我为模型“Customer”实现了单个表继承。 “人”和“公司”是“客户”。所以我添加了两条新路由来将所有请求转发到CustomersController
:
resources :customers # added by generator
resources :people, :controller => 'customers' <== NEW
resources :companies, :controller => 'customers' <== NEW
我想做的是
type
”添加到资源的操作“new
”:customers
我的目标是能够致电
new_customer_path(:type => 'Person')
和
new_person_path
之前我尝试过以下操作,但它停止了其他操作(如show)
resources :people, :controller => 'customers' do
get 'new', :on => :member, :type => 'Person'
end
那里的任何人都可以告诉我我的错误吗?
答案 0 :(得分:2)
尝试将参数添加到资源参数
resources :people, :controller => 'customers', :type => "Person"
resources :companies, :controller => 'customers', :type => "Company"
答案 1 :(得分:0)
至于new_person_path,你可以这样做:
map.new_person "new_person", :controller => "customers", :action => "new", :type => "person"
请记住:
new_customer_path(:type => "person")
会在网址中传递“?type = person”,以便访问者能够更改它。