Hi Railers, I''m trying to get a couple of dates from a form in order to work out a price for something - this is before I go saving stuff to the database, so is the first stage of building up this record. I can get the dates back in certain ways (more on that in a sec), but can''t seem to just get the dates back so I can start using them. Here''s my form: <!--[form:getquote]--> <p><label for="booking_booking_start">Booking start</label><br/> <%= datetime_select ''booking'', ''booking_start'', :discard_minute => true %>:00</p> <p><label for="booking_booking_end">Booking end</label><br/> <%= datetime_select ''booking'', ''booking_end'', :discard_minute => true %>:00</p> <!--[eoform:getquote]--> If I do a debug() on params[:booking] I get: --- !ruby/hash:HashWithIndifferentAccess booking_end(3i): "3" booking_end(4i): "18" booking_start(1i): "2005" booking_start(2i): "9" booking_start(3i): "3" booking_start(4i): "18" booking_end(1i): "2005" booking_end(2i): "9" But I can''t seem to just get my date values booking_start or booking_end, and have tried all the following in desperation: params[:booking][:booking_start] params[:booking][''booking_start''] params[''booking''][''booking_start''] What am I missing in order to get those dates back from the form and start using them? (This is a couple of steps before I will save them to the database, so I''m only half using ActiveRecord here.) Incidentally, I''ve already asked on IRC and a couple of people seemed quite stumped by this one, so thanks for your help anyone that can solve this seemingly simple problem! Cheers, ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/
On 9/3/05, Dave Silvester <dave-AJqNGCqIqVQ7cdpDWioORw@public.gmane.org> wrote:> > Hi Railers, > > I''m trying to get a couple of dates from a form in order to work out a > price > for something - this is before I go saving stuff to the database, so is > the > first stage of building up this record. I can get the dates back in > certain > ways (more on that in a sec), but can''t seem to just get the dates back so > I > can start using them. > > Here''s my form: > > <!--[form:getquote]--> > <p><label for="booking_booking_start">Booking start</label><br/> > <%= datetime_select ''booking'', ''booking_start'', :discard_minute => true > %>:00</p> > > <p><label for="booking_booking_end">Booking end</label><br/> > <%= datetime_select ''booking'', ''booking_end'', :discard_minute => true > %>:00</p> > <!--[eoform:getquote]--> > > If I do a debug() on params[:booking] I get: > > --- !ruby/hash:HashWithIndifferentAccess > booking_end(3i): "3" > booking_end(4i): "18" > booking_start(1i): "2005" > booking_start(2i): "9" > booking_start(3i): "3" > booking_start(4i): "18" > booking_end(1i): "2005" > booking_end(2i): "9" > > But I can''t seem to just get my date values booking_start or booking_end, > and > have tried all the following in desperation: > > params[:booking][:booking_start] > params[:booking][''booking_start''] > params[''booking''][''booking_start''] > > What am I missing in order to get those dates back from the form and start > using them? (This is a couple of steps before I will save them to the > database, so I''m only half using ActiveRecord here.) >I was a little puzzled at this behavior also, and assumed I was probably missing something. My solution was to just create a new datetime object out of the elements in the params date hash. Chris _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
snacktime wrote:> I was a little puzzled at this behavior also, and assumed I was probably > missing something. My solution was to just create a new datetime object out > of the elements in the params date hash.I''ve also just this minute arrived at the same solution! booking_start = Time.mktime(booking["booking_start(1i)"], booking["booking_start(2i)"], booking["booking_start(3i)"], booking["booking_start(4i)"]) Thanks for your help though! :-D As an aside, a funny thing I seem to be noticing with Rails (or maybe it''s Ruby) - the difficult stuff is easy, and the stuff that should be easy sometimes takes me hours! Are we in some strange alternate universe here? ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/
snacktime wrote:> I was a little puzzled at this behavior also, and assumed I was probably > missing something. My solution was to just create a new datetime objectout> of the elements in the params date hash.I had this same problem (sent an email to this list with no response). I was able to get the date without having to access each element individually. Can''t really remember how. (another, unrelated problem I was having was when the date was out of range). I''ll post the code on Tues. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails