“没有路由匹配”错误但是rake路由找到它

时间:2011-01-23 23:50:25

标签: ruby-on-rails controller routes

好的,在这里得到一个非常奇怪的路由错误。

No route matches {:controller=>"subscriptions", :action=>"change"}

Extracted source (around line #22):

19:     <td><%= s.product.name %></td>
20:     <td><%= s.calc_time_to_next_arrival %></td>
21:     <td>
22:         <%= form_for(:subscription, s, :url => { :action => "change" }, :id => s) do %>
23:             <%= label_tag(:q, "Days to delay:") %>
24:             <%= text_field_tag(:query) %>
25:             <%= check_box_tag(:always) %>

然而,如果我运行rake路线,这就是我得到的

change_subscription GET    /subscriptions/:id/change(.:format {:controller=>"subscriptions", :action=>"change"} 

很确定这意味着它应该在那里。不知道发生了什么。

这是route.rb

中规定路线的地方
resources :subscriptions do
    member do
      get 'change'
    end
  end

这是订阅控制器

def change
    @subscription = Subscription.find(params[:id])
    @subscription.change(:query, :always)
    redirect_to :back
  end

1 个答案:

答案 0 :(得分:4)

那应该是post 'change',而不是get 'change'

呃,我当然是put 'change'

怎么样:

<%= form_for s, :url => change_subscription_path(s) do |f| %>