ruby-on-rails – 带Rails的动态路由3
我有一个任务,开发一个rails应用程序跟随模型的路由.
我需要有PageController和Page模型.页面URL必须是/ contacts,/ shipping,/ some_page. 另外我需要有CatalogController和Category模型.分类网址必须像笔记本电脑/智能手机/ android. 而且它将是ProductsController和产品型号,产品的URL必须是线/笔记本电脑/ toshiba_sattelite_l605,/ smartphones / android / htc_magic 我明白这个问题可以通过使用URL来解决 > / page / shipping 但客户不希望在URL中看到“/ page”或“/ catalog”的插入. 请告诉我解决这个问题的方向. 解决方法
你必须写一个“全部”规则:
在routes.rb上 get '*my_precioussss' => 'sauron#one_action_to_rule_them_all' 你的宝贵的控制器: class SauronController < ApplicationController def one_action_to_rule_them_all @element = find_by_slug(params[:my_precioussss]) render @element.kind # product,category,etc end end 然后你为每个“kind”元素写一个视图:product.html.erb,category.html.erb等. 确保写下你的find_by_slug实现. 您可以将one_action_to_rule_them_all更改为pikachu_i_choose_you和SauronController到PokemonController,这样也可以. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |