问题
In 'app/views/users/reset.html.erb' file I have this code:
<%= form_tag( send_reset_users_path, :method => :post ) do %>
<%= text_field_tag :email %>
<%= submit_tag("Send") %>
<% end %>
In 'app/controllers/*users_controller.rb*' I have this code:
def reset
respond_to do |format|
format.html # reset.html.erb
end
end
def send_reset
...
end
In 'config/routes.rb' I have this code:
resources :users do
collection do
get 'reset'
get 'send_reset'
end
end
When I submit the form I get the error: "No route matches "/users/send_reset"" (browser URL becomes '.../users/send_reset'). What is wrong? How can I "map" URLs to Rails actions?
P.S.: I think the problem is in "config/routes.rb"...
回答1:
the problem is here :method => :post
and get 'send_reset'
, in my opinion you are trying to POST parameters when your conntroller expect GET method
回答2:
You routes.rb declares the send_reset
route as only available via get. You have to write post 'send_reset'
:
resources :users do
collection do
get 'reset'
post 'send_reset'
end
end
来源:https://stackoverflow.com/questions/4479404/what-is-wrong-in-mapping-urls-to-rails-actions-with-this-form