Created
March 3, 2013 00:36
-
-
Save jason/5073930 to your computer and use it in GitHub Desktop.
VoteTypes.name holds whether the vote is an aye, nay, or abstain. @ resolution has Resolution.find(params[:id}). Votes has the vote_type_id, the member_id (who it is that's voting) and the resolution_id
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
td = @vote_types[@resolution.votes.where(:member_id => n).first.vote_type_id - 1].name |
Oh and don't forget to load the resolution, votes, members, and vote_types up front when you query in the controller. If you don't, your view might trigger an extra SQL query every time you try to access vote.member
or vote.vote_name
.
@resolution = Resolution.include(:votes => [:member, :vote_type]).find(params[:id])
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Honestly it seems like VoteType should be a constant inside Vote instead of its own class with a mapping to name, but without doing that, here's roughly what it should look like:
I've never used slim, but here's the ERB equivalent: