0

我正在尝试在邮件视图中使用 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

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

"{没有路由匹配 {:controller=>"scribe_requests", :action=>"accept", :id=>"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 rescue in generate' /home/syed/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.2.5/lib /action_dispatch/routing/route_set.rb:520 :在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:在“渲染中的块”中

4

1 回答 1

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" 

谢谢您的帮助。

于 2012-07-25T16:49:12.777 回答