Created
February 2, 2012 17:40
-
-
Save erichurst/1724799 to your computer and use it in GitHub Desktop.
Custom callback notification with Rails 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
... | |
def self.new_sitter(user, params) | |
if user.parent? | |
transaction do | |
sitter = create! do |u| | |
u.sub_type = 'sitter' | |
u.first_name = params[:first_name] | |
u.last_name = params[:last_name] | |
u.email = params[:email] | |
end | |
notify_observers :new_sitter_created | |
sitter | |
end | |
else | |
logger.info "User: #{user.id}, #{user.to_s}, with sub_type 'sitter' attempted to create a User with sub_type 'sitter'." | |
nil | |
end | |
end | |
... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserObserver < ActiveRecord::Observer | |
def new_sitter_created(user) | |
#do something | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment