Skip to content

Instantly share code, notes, and snippets.

@maxschulze
Created January 23, 2013 12:19
Show Gist options
  • Save maxschulze/4604964 to your computer and use it in GitHub Desktop.
Save maxschulze/4604964 to your computer and use it in GitHub Desktop.
class JuryReview
# some mongo fields here, not called round_number nor rapper_slug
# Now let's have a getter and setter, these are the names for the form fields as well, e.g.
# f.select :rapper - This should render a select with <option value="ID OF THE RAPPER OR SLUG">WHATEVER</option>
# f.input :round_number
attr_accessor :round_number, :rapper
# Implement the setter first
def round_number=(n)
self.round = Round.where(number: n).first
end
# Since you have replaced the embbeded_in (!!!) you can query the rapper directly without the round
# This is important because you can't guarantee that the round is saved before the rapper is being set
def rapper=(id_or_slug)
self.rapper = Rapper.where(slug: id_or_slug).first
end
....
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment