Skip to content

Instantly share code, notes, and snippets.

@oliyoung
Created July 14, 2011 00:58
Show Gist options
  • Save oliyoung/1081662 to your computer and use it in GitHub Desktop.
Save oliyoung/1081662 to your computer and use it in GitHub Desktop.
if at_place
@reward = place.rewards.cellar_door.active.first
else
@reward = place.rewards.regular.active.first
end
@seangeo
Copy link

seangeo commented Jul 14, 2011

I would suggest that either Place or Reward needs a method to pick the right reward based on whatever conditions it likes.

Assuming there is in some sort of user class that defines in_place

def reward_for(user)
  if user.at_place
    self.rewards.cellar_door.active.first
  else
    self.rewards.regular.active.first
  end
end

This wraps up the ugly and you can call it like:

@reward = place.reward_for(user)

All depends on your context though. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment