Reputation: 3467
In my app users can register information about a tournament. If the user is a paying customer, she can fill in additional info, otherwise the fields for the additional info are unavailable (visible but disabled).
I laid this out as two objects: Tournament
and TournamentExtras
where the former has_one :tournament_extras
and the latter belongs_to :tournament
. Tournament
also accepts_nested_attributes_for :tournament_extras
.
I would like this to show up as a single form. The fields in the two objects are related, meaning you can add a start date (to Tournament
) but only paying customers can add an end date (to TournamentExtras
) but since the two fields are logically realted, they should show up after eachother in the form.
How do I do this?
I tried opening the form_for
and fields_for
loops withing eachother (before adding any fields) hoping that I could add any field whereever I like. That didn't work; apparently you can't reference the form object within the fields loop(?).
Upvotes: 0
Views: 126
Reputation: 4103
form_form and fields_for should work with each other.
Somewhat of a skeleton for this is:
form_for(@tournament) do |f|
f.fields_for(@tournament.tournament_extra) do |g|
end
end
Upvotes: 1