我在运行应用程序时遇到此错误:
没有路线匹配[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
答案 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"