Skip to content

Instantly share code, notes, and snippets.

@erichurst erichurst/User.rb
Created Feb 2, 2012

Embed
What would you like to do?
Custom callback notification with Rails 3
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
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
You can’t perform that action at this time.