1

我有以下型号:

User
Athlete < User
Coach < User

在我的路线中,我有以下内容:

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

我想为每条sign_up路径创建一个路由(即:/sign_up/coach、/sign_up/athlete)...我应该创建两个不同的注册控制器还是有办法只用一个注册控制器来做到这一点?

4

2 回答 2

1

您可以使用单个注册控制器执行以下操作:

class UsersController < Devise::RegistrationsController

  private

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

end

您还需要做其他一些 tweeks。这是否值得,我想这取决于模型实际上有多相似。

希望能帮助到你!

于 2013-06-06T15:21:24.557 回答
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

谢谢。

于 2013-06-06T15:13:06.923 回答