【发布时间】:2014-12-10 00:30:39
【问题描述】:
resources :accounts, shallow: true do
resources :textnotes
end
给我
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
当我尝试创建新笔记时
http://0.0.0.0:3000/accounts/4/textnotes/new
<%= simple_form_for(@textnote) do |f| %>
我收到以下错误:
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>
【问题讨论】:
-
我不知道 simple_form,但您似乎需要同时为该方法提供
@textnote和@account对象才能使其工作? -
您声明了
textnote_path而不是textnotes_path。这可能是问题吗?@textnote对象是什么?
标签: ruby-on-rails ruby-on-rails-4 simple-form nested-resources