So I have a simple form for entering "brand" and "model" through a single submit button, as below:
<%= simple_form_for @brand, :html => { :class => 'form-horizontal' } do |m| %>
<fieldset>
<legend><%= controller.action_name.capitalize %> /Brand</legend>
<%= m.input :name %>
<%= m.simple_fields_for :models, Model.new do |p| %>
<%= p.input :name %>
<% end %>
<div class="form-actions">
<%= m.submit nil, :class => 'btn btn-primary' %>
<%= link_to 'Cancel', brands_path, :class => 'btn' %>
</div>
</fieldset>
<% end %>
I have name:string in my schema for both brand and model.. and validates_presence_of :name in both models.. The form DOES work for creating the brand and model simultaneously but my error "can't be blank" only shows up for the brand field.
Thanks for any help with this issue.
<%= m.simple_fields_for :models, @model do |p| %>Abram 2012-04-04 09:40
Realized what I was doing wrong. Needed to ALSO put @model = Model.new inside of the controller and put <%= m.simple_fields_for :models, @model do |p| %>