What is wrong in “mapping” URLs to Rails actions with this form?

房东的猫 提交于 2019-12-12 04:58:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!