ruby-on-rails – Ruby on Rails中的嵌套路由
发布时间:2020-12-17 04:16:15 所属栏目:百科 来源:网络整理
导读:我的模型类是: class Category ActiveRecord::Base acts_as_nested_set has_many :children,:foreign_key = "parent_id",:class_name = 'Category' belongs_to :parent,:class_name = 'Category' def to_param slug endend 是否有可能像这样的递归路线: /
我的模型类是:
class Category < ActiveRecord::Base acts_as_nested_set has_many :children,:foreign_key => "parent_id",:class_name => 'Category' belongs_to :parent,:class_name => 'Category' def to_param slug end end 是否有可能像这样的递归路线: 感谢您的任何帮助 :) 解决方法
您可以使用常规路线和
Route Globbing进行此操作,例如,
map.connect 'categories/*slugs',:controller => 'categories',:action => 'show_deeply_nested_category' 然后在你的控制器中 def show_deeply_nested_category do_something = params[:slugs] # contains an array of the path segments end 但是,请注意,不建议使用多达一级的nested resource routing. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |