没有路由匹配Rails 4.2.6

时间:2016-07-15 04:44:51

标签: ruby-on-rails

我在运行应用程序时遇到此错误:

  

没有路线匹配[PUT]“/ accounts / 1 / payment”

这是我的表单语法;

<%= semantic_form_for(@account, :url => payment_path, :html => { :method => :put }) do |f| %>
......
<% end %>

routes.rb中:

get "/accounts/:id/payment" => "accounts#payment", :as => "payment"

控制器方法:

def billing
  @account = Account.find(params[:id])
  if request.put?
    // some code here
  end
end

4 个答案:

答案 0 :(得分:1)

替换

get "/accounts/:id/payment" => "accounts#payment", :as => "payment"

match "/accounts/:id/payment", to: "accounts#payment", :as => "payment", via: [:get, :put]

如果有效,请告诉我。

修改

如果您的控制器操作为billing,则可能需要执行

match "/accounts/:id/payment", to: "accounts#billing", :as => "payment", via: [:get, :put]

答案 1 :(得分:0)

您的表单正在尝试查找路由匹配方法,而您的路由有get方法。 使用put in routes而不是get

put "/accounts/:id/payment" => "accounts#payment", :as => "payment"

答案 2 :(得分:0)

在您的表单中,您告诉此表单被视为PUT请求,但您的路由表明它是GET请求。您应该在routes.rb和表单定义中使用相同的请求类型。

答案 3 :(得分:0)

试试这个

put "/accounts/:id/payment" => "accounts#billing", :as => "payment"