简体   繁体   中英

“No route matches” error but rake routes finds it

Alright, getting a pretty bizarre routing error here.

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) %>

And yet if I run rake routes this is what I get

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

Pretty sure that means it should be there. Not sure what is going on.

Here is where the route is stated in routes.rb

resources :subscriptions do
    member do
      get 'change'
    end
  end

Here's the controller though for subscriptions

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

That should be post 'change' , instead of get 'change'

Er, I meant put 'change' , of course.

How about:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM