“映射”有什么问题?使用此表单的 Rails 操作的 URL?

发布于 2024-10-08 20:51:16 字数 803 浏览 0 评论 0原文

在“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱花落人离去 2024-10-15 20:51:16

问题就在这里:method =>; :postget 'send_reset',在我看来,当您的控制器期望 GET 方法时,您正在尝试 POST 参数

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

优雅的叶子 2024-10-15 20:51:16

您的routes.rb将send_reset路由声明为只能通过get使用。您必须编写post 'send_reset'

resources :users do
  collection do
    get 'reset'
    post 'send_reset'
  end
end

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文