次のようなカスタム ルートがあります。
match 'firsttime' => 'registrations#new', :via => :get, \
:defaults => {:promotion_path => :firsttime}
上記のルートの目標は、 http://www.mysite.com/firsttimeのような URLを登録コントローラーの「新規」メソッドにマップできるようにすることです。その登録のプロモーションは「初回」です。昇進。
私のモデルの 1 つで、この URL を試して生成するためのショートカット メソッドがあります。
class Registration < ActiveRecord::Base
include ActionView::Helpers
include ActionDispatch::Routing
include Rails.application.routes.url_helpers
belongs_to :promotion
def get_share_link()
promotion_path = promotion.url_path
url_to_share = url_for :controller => 'registrations', :action => 'new', :promotion_path => promotion_path
end
end
メソッド get_share_links() を呼び出すと、次のエラーで失敗します。
{:controller="registrations", :action="new", :promotion_path="firsttime"} に一致するルートはありません
私は何を間違っていますか、またはこれに正しい方法を使用していますか?