开发者

Rails devise user function

开发者 https://www.devze.com 2023-04-09 01:49 出处:网络
How do I execute a particular function after a user has signed up. (I wanted to add to one of my a开发者_StackOverflow社区ssociations, I already have it coded in a non-devise rails but now I need it h

How do I execute a particular function after a user has signed up. (I wanted to add to one of my a开发者_StackOverflow社区ssociations, I already have it coded in a non-devise rails but now I need it here)


Device has provided helper action 'after_sign_in_path_for' you can override it within your application controller.

def after_sign_in_path_for(resource_or_scope)
.... #write your customize code or call any method
end


For sign up it would look like:

def after_sign_up_path_for(resource_or_scope)
  if resource_or_scope.is_a? User  # and perhaps other conditions
    #... do something, go somewhere
  else
    super
  end
end

Ofc. Assuming that your Devise user model is called User.


You can use the after_create callback in your User model.

The following guide has tons of examples: http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号