【发布时间】:2015-03-01 03:44:33
【问题描述】:
我有这个嵌套资源:
resources :services do
resources :users do
put "assign" => "services#users#assign", as: :assign
end
end
我的表单包含这个:
<%= button_to 'submit', service_user_assign_url(service.id, abstractor.id), method: :put %>
这会生成以下网址,我觉得很好:
http://localhost:3000/services/1/users/2/assign
以下内容在我的服务控制器中:
def assign
@service = Service.find(params[:service_id])
@service.users << User.find(params[:user_id])
redirect_to dashboards_path
end
但是我得到了这个错误:
The action 'users' could not be found for ServicesController
我不确定这意味着什么 - 我在用户和服务之间有很多关系,我正在尝试将现有用户与服务相关联
【问题讨论】:
-
这可能是由于“services#users#assign”。我从来没有见过。您指的是“services#assign”吗?
标签: ruby-on-rails associations nested-resources