Therefore, my app has my own registration controller, which adds a role assignment to a new registered user. >
Class Registration Controller & lt; Devise :: RegistrationsController def build_resource resource.role = Role.find_by_name ('registered') If resource.save if resource.active_for_authentication is it? Set_flash_message: Notice ,: if_navigational_format is signed? Sign_in (resource_name, processing) response_with resource ,: location = & gt; After_sign_up_path_for (resource) and set_flash_message: notice, "sign_up_but _ # {resource.inactive_message}" if is_navigational_format? Expire_session_data_after_sign_in! Reply with Resource: Location = & gt; (Resource) for after_inactive_sign_up_path_ end other clean_up_passwords resource end-end processing with resource response Is there any cleaner way to add functionality to this method?
I think I can handle him with a callback at the level of a model, but I can call it '
Revoked one callback only
class user & lt; ActiveRecord :: Before creating the Base: set_role Private def set_role if self.role.nil? Self.role = Role.find_by_name ('registered') and end and end Many cleaners make the customer fully controller.
Comments
Post a Comment