Reputation: 537
I think what I am trying to do is simple in theory but I'm having a hard time putting it into words to search for a solution.
on my Contest form I have a collection select-
<div class="form-group">
<%= f.label :matchup_id, 'Select Matchset' %>
<%= f.collection_select(:matchset_id, Matchset.where("starttime > ?", Time.now), :id, :name, { :prompt => true } ) %>
For whichever matchset they choose here, I want to pass that Matchset's starttime to the field also called starttime on this Contest model.
Editing for clarification: I want to pass a second value from the Matchset model to the Contest model based on the user's selection in the collection select. So if the user selects matchset 1 in the collection select, I want to pass 1 as the matchset_id to Contest but I also want to take the starttime from matchset 1 and pass that as the starttime for the Contest record I'm creating as well. Any tips for a newbie?
Upvotes: 1
Views: 103
Reputation: 158
It might be easier to assign the starttime
value to a Contest
in the controller. In the action this view is calling, after you have assigned the selected matchset
to the contest
, you can access the starttime
by calling:
@contest.matchset.starttime
It will be a little different if the contest has_many matchsets
but it's the same idea.
Upvotes: 1