I have a form that allows user to register for a tournament. In the process of building the registration form I hae dynamic nested fields with so far field_type of basic. When I load the participants new form I am trying to load all the fields from the Fields table with field_type of basic. It will find them and if I just try <%= @basic.name %> from the new form it will give the name of the last field in the database with that field_type, but if I try:
<% @basic.each do |b| %>
<%= b.name %>
<% end
I get the error undefined method `each' for #<Field.
Here is the new action from the participants_controller:
def new
@participant = @event.participants.new
@user = User.find(current_user.id)
@children = @user.children
@basic = Field.find_by(event_id: @event.id, field_type: 'basic')
end
Fields belong to events but do I have to connect them to participants to make this work?
Thanks
question from:https://stackoverflow.com/questions/65911730/rails-undefined-method-each-for-field