【问题标题】:"No route matches" error but rake routes finds it“没有路线匹配”错误,但 rake 路线找到它
【发布时间】:2011-06-14 05:25:33
【问题描述】:

好的,这里出现了一个非常奇怪的路由错误。

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"} 

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

这是在 routes.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

【问题讨论】:

    标签: ruby-on-rails controller routes


    【解决方案1】:

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

    呃,我的意思是put 'change',当然。

    怎么样:

    &lt;%= form_for s, :url =&gt; change_subscription_path(s) do |f| %&gt;

    【讨论】:

    • 已经试过了。再次尝试,并重新启动服务器以获得良好的效果。 rake 路由的输出已正确更新,但仍然出现此错误。 (同样,尝试“放”只是为了咯咯笑)
    猜你喜欢
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-11
    • 1970-01-01
    相关资源
    最近更新 更多