dry - Anyone have a DRYer solution to these Nested If Statements? -


the purpose of method mark user's attendance @ event. can read following: if there event going on today, if user exists, if status either subscribed or confirmed, , if existing user has not been checked-in, add user event's user's array.

any suggestions more elegant solution?

def mark_attendance(user)   if current_event(current_merchant)     if user       if user.status == 'subscribed' || user.status == 'confirmed'         if current_event(current_merchant).users.where(id: user.id) == []           current_event(current_merchant).users << user         end       end     end   end 

i write this:

def mark_attendance(user)    event = current_event(current_merchant)   attending = ['subscribed', 'confirmed']    event.users << user if (event && user) &&       attending.include?(user.status) &&       event.users.where(id: user.id).any?  end 

not shorted, clearer imo.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -