I’m trying to build a simple nested form, checking a lot of resources online, but can’t find what is it that I’m missing!
I have the following:
class Configuration < ActiveRecord::Base
has_many :configoptions
accepts_nested_attributes_for :configoptions
end
class Configoption < ActiveRecord::Base
belongs_to :configuration
has_many :items
end
Now, I’m trying to make a simple form when you select a configuration so it would show the
configoptions belonging to it, but nothing works!
This is the view without any html
<%= form_for :config do |f| %>
<%= f.text_field(:name)%>
<% f.fields_for @options do |option|%>
<% end %>
<% end %>
In the controller I have:
def show
@config = Configuration.find(params[:id])
@options = @config.configoptions
end
But i end up getting the error:
undefined method `model_name' for Array:Class
Does anyone have advice for me? Thanks a lot!
FYI, Ryan Bates (RailsCasts) has created a gem to handle much of this. I’m using it now and it works great!
See https://github.com/reu/simple_nested_form for the details.