I'm using Rails to create a schedule of a shop's opening and closing hours. Simplified versions of the models I've set up is:
class Account < ActiveRecord::Base has_many :opening_hours, :dependent => :destroy end class OpeningHour < ActiveRecord::Base belongs_to :account # table schema # create_table "opening_hours", :force => true do |t| # t.integer "account_id" # t.string "day_of_week" # t.string "begins" # t.string "ends" # end end So an account might have one opening_hour for Monday (:day_of_week => "Monday", :opens =>"9am", :closes => "5pm"), two for Tuesday ([:day_of_week => "Tuesday", :opens => "9am", :closes => "12pm"], [:day_of_week => "Tuesday", :opens => "1pm", :closes => "5pm"]), etc. As I begin work on the HTML form for this schedule, I realize I'm not sure of the best way to allow the user to add multiple objects within one form when each object already has an attribute defined (the day_of_week attr). The form I'm working on should look like this: Monday Opening Hours [begins text_input] - [ends text_input] Tuesday Opening Hours [begins text_input] - [ends text_input] [begins text_input] - [ends text_input] ... Does anyone know of a standard way to handle this sort of requirement? I'm familiar with this method[1] to add multiple child objects in a single form, but in Ryan's example, the tasks lack any pre-determined attribute values. [1]: http://railscasts.com/episodes/73-complex-forms-part-1 Thanks very much for your help, Jacob Patton --~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---