1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I just tried and it worked. Came here to answer my question but you already did. Good to know I can assign records values like this. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.