Created
April 8, 2012 04:55
-
-
Save brandoncordell/2334795 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
— | |
= 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