callback - Rails public profile creation and determining whether profile is public or not -


in app user has ability create profile, there series of required fields need filled out before user's profile "public".

i working on after_update callback runs series of checks see if required fields filled out.

here method:

# user model after_update :check_public_status  def check_public_status     if self.name.blank? || self.state.blank? || self.city.blank? ||          self.high_school.blank? || self.recruit_year.blank? || self.birthday.blank? ||          self.stat(:height).blank? || self.stat(:weight).blank?       self.update_attribute :public, false       self.update_attribute :removed_from_listing, true     else       self.update_attribute :public, true       self.update_attribute :removed_from_listing, false     end   end 

is there better way of doing without having nasty if/else statement?

how this:

user model

after_update :update_public_status!  def update_public_status!   required_fields_present =      [       name, state, city,        high_school, recruit_year,       birthday, stat(:height), stat(:weight)     ].all?   if required_fields_present     make_public!   else     make_private!   end end  def make_public!   update_attribute :public, true   update_attribute :removed_from_listing, false end  def make_private!   update_attribute :public, false   update_attribute :removed_from_listing, true end 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -