2013-05-15 49 views
1

我有以下型號:的Rails 3 devise_for和STI

User 
Athlete < User 
Coach < User 

在我的路線,我有以下幾點:

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks", :registrations => "registrations" } 

我想創造每個sign_up路徑的路線(即:/ sign_up/coach,/ sign_up/athlete)...我應該創建兩個不同的註冊控制器,還是有辦法用一個註冊控制器來做到這一點?

回答

0

,如果你對教練和運動員創造獨立的控制器這將是很好:

devise_for :coach, :controllers => { :registrations => "coach_registrations" } 
devise_for :athlete, :controllers => { :registrations => "athlete_registrations" } 

class CoachRegistrationsController < Devise::RegistrationsController 

end 

class AthleteRegistrationsController < Devise::RegistrationsController 

end 

感謝。

1

您可以使用一個單一的登記控制器做這樣的事情:

class UsersController < Devise::RegistrationsController 

    private 

    def resource_class 
     params[:type].present? ? params[:type].classify.constantize : super 
    end 

end 

有你需要做一些其他tweeks。無論這是否值得,我想這取決於模型實際上有多相似。

希望它能幫助!