[英]Rails 4 routes with simple_form and shallow nested resources
resources :accounts, shallow: true do
resources :textnotes
end
Gives me 给我
account_textnotes GET /accounts/:account_id/textnotes(.:format) textnotes#index
POST /accounts/:account_id/textnotes(.:format) textnotes#create
new_account_textnote GET /accounts/:account_id/textnotes/new(.:format) textnotes#new
edit_textnote GET /textnotes/:id/edit(.:format) textnotes#edit
textnote GET /textnotes/:id(.:format) textnotes#show
PATCH /textnotes/:id(.:format) textnotes#update
PUT /textnotes/:id(.:format) textnotes#update
When I try to create a new note 当我尝试创建新笔记时
http://0.0.0.0:3000/accounts/4/textnotes/new
<%= simple_form_for(@textnote) do |f| %>
I get the following error: 我收到以下错误:
NameError in Textnotes#new
Showing /Users/xyz/rails_projects/crm/app/views/textnotes/_form.html.erb where line #1 raised:
undefined method `textnotes_path' for #<#<Class:0x007f8204f37360>:0x007f8204be4fa0>
Do you need to add a url
parameter to simple_form_for
specifying accounts_textnotes_path
? 您是否需要在simple_form_for
添加一个url
参数以指定accounts_textnotes_path
?
With the shallow nesting setup you're posting to the index path of the parent resource (which I believe your routes output above shows). 使用浅层嵌套设置时,您将发布到父资源的索引路径(我相信上面的路由输出显示了该路径)。
If that doesn't work you could always try specifying a string path or an action. 如果这样不起作用,您可以随时尝试指定字符串路径或操作。
(As always, http://edgeguides.rubyonrails.org/form_helpers.html and http://guides.rubyonrails.org/routing.html may help.) (一如既往, http://edgeguides.rubyonrails.org/form_helpers.html和http://guides.rubyonrails.org/routing.html可能会有所帮助。)
You were close. 你近了 You have to specify the parent account like this: 您必须像这样指定上级帐户:
<%= simple_form_for([@account, @textnote]) do |f| %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.