RailsCasts Pro episodes are now free!

Learn more or hide this

loran's Profile

GitHub User: loranbriggs

Site: codesquire.com

Comments by loran

Avatar

What am I missing? I cannot have a hour and min field convert to a duration model field.

ruby
  attr_accessible :date, :hour_dur, :min_dur
  attr_accessor :hour_dur, :min_dur
  has_many :shifts
  has_many :seats
  belongs_to :user
  
  before_save :update_duration

  validates_presence_of :date
  validates_presence_of :duration

  def update_duration
    duration = hour_dur*60 + min_dur
  end
  
  def hour_dur
    duration / 60 if duration.present?
  end
  
  def min_dur
    duration % 60 if duration.present?
  end
end
Avatar

delicious....... yes I believe that is the correct adjetive for this episode.

Avatar

Luis's suggestion has many options including removing the slider. Check out all the examples and most likely one of them will fit your needs

Avatar

I have since separated the two since it was causing even more problems when I was plotting the events on the calendar. I know its not the best solution to separate the date and time as two data fields but I got it working rather painless.

Still would love to hear any better ideas

Avatar

so I have a datetime field in my modle and I have seperated them by:

ruby
%p
    = f.label :event_date
    = f.date_select :event_date
    %br
  %p
    = f.label :event_time
    = f.time_select :event_date, :minute_step => 15, :ignore_date => true, :ampm => true
    %br

and this works fine. I have then change the date select to a f.text_field and applied whats discussed in the video. and I produce this error:

1 error(s) on assignment of multiparameter attributes

{"utf8"=>"✓",
 "authenticity_token"=>"YHlnywsS5yAA2gCp4iU+RQNGEC1i+VzMz2FQab8r+a0=",
 "event"=>{"event_name"=>"",
 "event_date"=>"2012-12-21",
 "event_date(4i)"=>"14",
 "event_date(5i)"=>"00",
 "participants"=>"5"},
 "commit"=>"Create Event"}

If I comment out the f.time_select line like so:

ruby
%p
    = f.label :event_date
    = f.text_field :event_date
    %br
  %p
    = f.label :event_time
    /= f.time_select :event_date, :minute_step => 15, :ignore_date => true, :ampm => true
    %br

everything works fine except that the time is saved as 00:00:00 of course. Any one have any clue on how to get this working right?