I want to be able to create one menu object that has fields_for :brunch, :lunch, and :dinner. The menu object has_many brunches, lunches, and dinners, but each time I "edit", only one brunch, one lunch, and one dinner object are added. I'm using carrierwave to upload brunch_menus, lunch_menus, and dinner_menus (attributes of brunches, lunches, and dinners respectively) as pdfs to amazon s3 and viewing them as iframes. When I try to save a menu object, the menu object gets created and saved, but its brunch, lunch and dinner don't get created when I edit it. When i run Brunch.all i get []
Thanks! Sarah Menu Controller: before_filter :authenticate_admin!, :except => [:show] def edit @menu = Menu.find(params[:id]) @menu.dinners.build @menu.lunches.build @menu.brunches.build end Menu Model: class Menu < ActiveRecord::Base has_many :brunches, :dependent => :destroy has_many :lunches, :dependent => :destroy has_many :dinners, :dependent => :destroy accepts_nested_attributes_for :lunches, :dinners, :brunches end Brunch, lunch, dinner models: class Lunch < ActiveRecord::Base attr_accessible :menu_id, :lunch_menu belongs_to :menu mount_uploader :lunch_menu, ImageUploader end Menu Form: <%= form_for @menu, :html => {:multipart => true} do |f| %> <% if @menu.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@menu.errors.count, "error") %> prohibited this menu from being saved:</h2> <ul> <% @menu.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <%= f.fields_for :brunches do |a|%> <div class="field"> <%= a.label :brunch_menu %><br /> <%= a.file_field :brunch_menu %> </div> <% end %> <%= f.fields_for :lunches do |a|%> <div class="field"> <%= a.label :lunch_menu %><br /> <%= a.file_field :lunch_menu %> </div> <% end %> <%= f.fields_for :dinners do |a|%> <div class="field"> <%= a.label :dinner_menu %><br /> <%= a.file_field :dinner_menu %> </div> <% end %> <div class="actions"> <%= f.submit %> </div> <% end %> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/EBYsb9O1HnYJ. For more options, visit https://groups.google.com/groups/opt_out.