Skip to content

Instantly share code, notes, and snippets.

@brandoncordell
Created April 8, 2012 04:55
Show Gist options
  • Save brandoncordell/2334795 to your computer and use it in GitHub Desktop.
Save brandoncordell/2334795 to your computer and use it in GitHub Desktop.
# admin/dealers_controller.rb
class Admin::DealersController < Admin::BaseController
def new
@dealer = Dealer.new
7.times do |i|
@dealer.hours.build(day: i)
end
end
# dealer.rb
#
# Schema looks like
# id, dealer_id, day (int mapped to day of week. sun - 0 to sat - 6), open (time column), close (time column),
# created_at, updated_at
class Dealer < ActiveRecord::Base
has_many :hours
accepts_nested_attributes_for :hours
end
# dealers/new.html.haml
= form_for [:admin, @dealer], html: { class: 'form-horizontal' } do |f|
...
...
%fieldset
%legend Hours of Operation
= f.fields_for :hours do |h|
.control-group
= h.label :monday, class: 'control-label'
.controls
.input-append
= h.text_field :open, class: 'span1'
%span.add-on am
&mdash;
= h.text_field :close, class: 'span1'
%span.add-on pm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment