即使在rails 3.2中定义,也没有路由匹配

时间:2012-07-25 14:29:28

标签: ruby-on-rails routes

我正在尝试在邮件程序视图中使用url_for来定义路由:

<%= url_for(
    :controller => 'scribe_requests', 
    :action => 'accept', 
    :id => @match.acceptance_token, 
    :only_path => false) %>

我在routes.rb中定义了路线:

resources :scribe_requests do
  member do
    match 'accept' => 'scribe_requests#accept', :as => :accept
  end
end

我的控制员:

class ScribeRequestsController < ApplicationController
  respond_to :html

  def accept
    ..
  end
  ..
end

我不确定这里出了什么问题?我的延迟工作失败了,例外是

  

“{No route matches {:controller =&gt;”scribe_requests“,:action =&gt;”accept“,   :ID =&gt; “中nv4Nl8wWXLX2zFDm3s3t7w”}   /home/syed/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.2.5/lib/action_dispatch/routing/route_set.rb:532:in   raise_routing_error' /home/syed/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.2.5/lib/action_dispatch/routing/route_set.rb:528:in 救援'生成'   /home/syed/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.2.5/lib/action_dispatch/routing/route_set.rb:520:in   generate' /home/syed/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.2.5/lib/action_dispatch/routing/route_set.rb:561:in 生成”   /home/syed/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.2.5/lib/action_dispatch/routing/route_set.rb:586:in   url_for' /home/syed/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.2.5/lib/action_dispatch/routing/url_for.rb:148:in url_for”   /home/syed/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.2.5/lib/action_view/helpers/url_helper.rb:107:in url_for' /home/syed/work/projects/mapunity/retina-india/app/views/notifier/scribe_service_needed_email.html.erb:47:in _ app_views_notifier_scribe_service_needed_email_html_erb___981003510_106966530'   /home/syed/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.2.5/lib/action_view/template.rb:145:in   `block in render'

1 个答案:

答案 0 :(得分:0)

必须在路由定义中添加:via选项才有效。奇怪的是,我没有任何影响。可能是一些缓存问题。所以在改变之后,我的路线定义变成了,

resources :scribe_requests do
  member do
    match 'accept' => 'scribe_requests#accept', :via => :get, :as => :accept
  end
end

试运行:

ruby-1.9.2-p0 > app.url_for :controller => 'scribe_requests', :action => 'accept', :id => 'test'
 => "http://www.example.com/scribe_requests/test/accept" 

感谢您的帮助。