Reputation: 1036
routes.rb:
resources :shops
shop_controller.rb:
def new
@shop=Shop.new
end
new.html.erb:
<%= form_for(@shop) do |f| %>
....
<% end %>
error: undefined method `shops_path' for:
<%= form_for(@shop) do |f| %>
The problem is that I already specify the shop resources in the routes file. Why still get such kind of error?
Any help will be appreciated, thanks
Upvotes: 0
Views: 188
Reputation: 3462
Make sure you have these lines in your rake routes
output:
shops GET /shops(.:format {:action=>"index", :controller=>"shops"}
POST /shops(.:format) {:action=>"create", :controller=>"shops"}
OR
shops POST /shops(.:format) {:action=>"create", :controller=>"shops"}
If they aren't present, look carefully at your routes.rb
for possible with_options
, scope
or any other scoping that can affect your resources :shops
in such a way that it doesn't generate default url helpers.
Upvotes: 1
Reputation: 6574
since u havent specified the method in the form tag, i guess it is going as a GET request. Try adding the method to ur form
<%= form_for(@shop), :method => :post do |f| %>
Upvotes: 0
Reputation: 11967
You should use ShopsController
not ShopController
due to Rails naming convention.
Upvotes: 1