I'm using simple form with my rails 4 app.
I have 3 models in the app. One called Project, one for Scope and one for Data (the model is called datum but the view is called data).
There is a has and belongs to many association between Project and Scope. Data belongs to Scope.
I ask users to outline the scope of the project in general (by asking high level questions in the scope form) and then depending on the answers to the true/false questions in the scope form, I render partials which are forms created in the Data view.
In my scope form I have a question:
<%= f.input :data, :as => :boolean, :label => false, :inline_label => true %>
Those partials from the data view are rendered in the new project view. I have written this line to try to show the data form if the answer to the question about data (asked in the scope form) is true.
In my new project view I have:
<% if @project.scopes.data == true %>
<%= render "data/form" %>
<% end %>
In my schema I have a join table form projects_scopes. I also have a foreign key for scope_id in my data model.
However, I get this error:
`enter code here`undefined method `data' for #<ActiveRecord::Associations::CollectionProxy []>
Does anyone know what I've done wrong?
Thank you
You need to do a nested form. Basically, you end up doing another simple form inside of your simple form for the nested object, then allow your primary object to accept the nested attributes for the nested object. Here is a reference that goes into detail on implementation. I believe you can find it on youtube as well.
http://railscasts.com/episodes/196-nested-model-form-revised?view=comments
Also depending on how complex your form gets, you may look at doing a form object.