Created
July 14, 2011 00:58
-
-
Save oliyoung/1081662 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if at_place | |
@reward = place.rewards.cellar_door.active.first | |
else | |
@reward = place.rewards.regular.active.first | |
end |
@reward = (at_place ?
place.rewards.cellar_door :
place.rewards.regular) .active.first
My preferred stylization is a bit … unusual. You get the basic idea, though.
If you really want to Take It Too Far™, then:
@reward = place.rewards.send(at_place ? :cellar_door : :regular).active.first
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
'rewards' is a relationship, 'cellar_door', 'regular' and 'active' are scopes on reward