This was really useful. Thanks for leaving info on how you did it.
On Wednesday, May 13, 2009 1:43:10 AM UTC-5, Jacob Patton wrote:

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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/WfMWSnETLBUJ.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 25, '12 at 3:27a
activeNov 25, '12 at 3:27a
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Elioncho: 1 post

People

Translate

site design / logo © 2022 Grokbase