【问题标题】:Triggering GET method on form submit when POST method is specified指定 POST 方法时在表单提交上触发 GET 方法
【发布时间】:2015-08-28 05:10:40
【问题描述】:

我有一个 form_tag,我指定了一个 POST 方法,但每次我提交表单时,它都会尝试使用 GET 方法。这是我的表格:

 <%= form_tag (refund_path(subscription), :method => "post") do %>
                  <%= hidden_field_tag :subscription_id_refund, subscription.id %>
                  <%= submit_tag "Rembourser ce joueur", id: "export", class: "btn btn-warning"%>
                  <% end -%>

这是我的路线:

 post 'refunds/:subscription_id', to: "subscriptions#refund", as: "refund"

这是我的方法:

def refund
    @subscription = Subscription.find(params[:subscription_id_refund])
    if mangopay_refund
      @subscription.status == "refused"
      redirect_to
      flash[:notice] = "Vous avez bien procéder au remboursemend de #{@subscription.user.full_name}. Celui-ci ne participe plus au tournoi"
    else
      redirect_to
      flash[:warning] = "Le remboursement n'a pas pu etre effectué. Merci de réessayer plus tard"
    end
  end

你知道怎么解决吗?

【问题讨论】:

  • 你为什么用form_tag而不是form_for
  • 生成的 HTML 是什么样子的?
  • 除了一些语法之外,我看不到任何问题。删除form_tag 中的=。你能确保你提交的表格是正确的。您可能还想为收到的 GET 请求添加服务器日志。
  • 抱歉刚刚发现我错过了redirect_to

标签: ruby-on-rails ruby forms http-method


【解决方案1】:

表单的方法默认为POST。所以删除:method =&gt; "post"选项并尝试。

 <%= form_tag(refund_path(subscription)) do %>

参考:form_tag

【讨论】:

  • 抱歉刚刚发现我错过了redirect_to
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多