“映射”有什么问题?使用此表单的 Rails 操作的 URL?
在“app/views/users/reset.html.erb”文件中,我有以下代码:
<%= form_tag( send_reset_users_path, :method => :post ) do %>
<%= text_field_tag :email %>
<%= submit_tag("Send") %>
<% end %>
在“app/controllers/*users_controller.rb*”中,我有以下代码:
def reset
respond_to do |format|
format.html # reset.html.erb
end
end
def send_reset
...
end
在“config/”中>routes.rb' 我有这样的代码:
resources :users do
collection do
get 'reset'
get 'send_reset'
end
end
当我提交表单时,我收到错误:“没有路由匹配“/users/send_reset””(浏览器 URL 变为“.../users/send_reset”)。 出了什么问题? 如何将 URL“映射”到 Rails 操作?
PS:我认为问题出在“config/routes.rb”中......
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"...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题就在这里
:method =>; :post
和get 'send_reset'
,在我看来,当您的控制器期望 GET 方法时,您正在尝试 POST 参数the problem is here
:method => :post
andget 'send_reset'
, in my opinion you are trying to POST parameters when your conntroller expect GET method您的routes.rb将
send_reset
路由声明为只能通过get使用。您必须编写post 'send_reset'
:You routes.rb declares the
send_reset
route as only available via get. You have to writepost 'send_reset'
: