路线.rb:
resources :shops
shop_controller.rb:
def new
@shop=Shop.new
end
新的.html.erb:
<%= form_for(@shop) do |f| %>
....
<% end %>
错误:未定义的方法“shops_path”:
<%= form_for(@shop) do |f| %>
问题是我已经在路线文件中指定了商店资源。为什么还会出现这样的错误?
任何帮助将不胜感激,谢谢
路线.rb:
resources :shops
shop_controller.rb:
def new
@shop=Shop.new
end
新的.html.erb:
<%= form_for(@shop) do |f| %>
....
<% end %>
错误:未定义的方法“shops_path”:
<%= form_for(@shop) do |f| %>
问题是我已经在路线文件中指定了商店资源。为什么还会出现这样的错误?
任何帮助将不胜感激,谢谢
确保你的rake routes输出中有这些行:
shops GET /shops(.:format {:action=>"index", :controller=>"shops"}
POST /shops(.:format) {:action=>"create", :controller=>"shops"}
或者
shops POST /shops(.:format) {:action=>"create", :controller=>"shops"}
如果它们不存在,请仔细查看您routes.rb的可能with_options,或任何其他可能以不生成默认 url 帮助程序的方式scope影响您的范围。resources :shops
由于 Rails 命名约定,您ShopsController不应该使用。ShopController
由于您没有在表单标签中指定方法,我猜它是作为 GET 请求进行的。尝试将方法添加到您的表单
<%= form_for(@shop), :method => :post do |f| %>