rails 3 how to find_or_create_by method, how to set additional attributes on the new object -
rails 3 how to find_or_create_by method, how to set additional attributes on the new object -
this happening in approval model. approval has attribute :email. saying self.email calling object of approval class email attribute.enter code here
def associate_correct_user new_user = user.find_or_create_by_email self.email |u| u.invite! end if creating user here need pass 2 other attributes (first_name , last_name). attributes need pulled model email, self.email been validated against.
this makes sense in head:
def associate_correct_user new_user = user.find_or_create_by_email self.email |u| user = email.find_by_email(self.email) u.first_name = user.first_name u.last_name = user.last_name u.invite! end this creates user, not set first_name , last_name attributes new user...
show me lines of log/development.log when user created. may first_name , last_name protected attributes. here have illustration of find_or_create_by http://api.rubyonrails.org/classes/activerecord/base.html#label-dynamic+attribute-based+finders uses different syntax.
user.find_or_create_by_name('bob', :age => 40) { |u| u.admin = true } ruby-on-rails ruby-on-rails-3
Comments
Post a Comment