そのため、アプリに独自の登録コントローラーがあり、新しく登録されたユーザーにロールの割り当てを追加します
class RegistrationsController < Devise::RegistrationsController
def create
build_resource
resource.role = Role.find_by_name('registered')
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end
end
このメソッドに機能を追加するよりクリーンな方法はありますか? ロジックを私のメソッドから分離しておくために、devise のコードをメソッドにコピー/貼り付けする必要はありません。
コールバックを使用してモデルレベルで処理できると思いますが、ベストプラクティスがわかりません