when retreiving a date from a DATETIME field in a database, is there a way to set the date to the value of the DB in the view? It seems to always default to the current date... if I have a field called birthdate in the users table and i do @user = User.find(@params[:id]) in my view i have a <%= date_select ''birthdate'',''user'' %> but dont know how to set a value for date_select that isnt the current date. Any ideas ? thanks adam
On 1/6/06, Adam Denenberg <straightflush@gmail.com> wrote:> when retreiving a date from a DATETIME field in a database, is there a > way to set the date to the value of the DB in the view? It seems to > always default to the current date... > > if I have a field called birthdate in the users table and i do > > @user = User.find(@params[:id]) > > in my view i have a <%= date_select ''birthdate'',''user'' %> > > but dont know how to set a value for date_select that isnt the current date. >You''ve got the parameters reversed; the ActiveRecord instance comes first: http://api.rubyonrails.com/classes/ActionView/Helpers/DateHelper.html#M000381 Also, if you need the TIME part of the DATETIME column, you may want datetime_select instead.
sorry your right,i typed it wrong in the email, its correct in my view. However i still dont know how to populate the ''default'' values of the month/day/year. it always defaults to the current date. How do i set the birthdate(1i) pieces of the object so that the form has the values from the DB and not the current date? thanks adam On 1/7/06, Wilson Bilkovich <wilsonb@gmail.com> wrote:> On 1/6/06, Adam Denenberg <straightflush@gmail.com> wrote: > > when retreiving a date from a DATETIME field in a database, is there a > > way to set the date to the value of the DB in the view? It seems to > > always default to the current date... > > > > if I have a field called birthdate in the users table and i do > > > > @user = User.find(@params[:id]) > > > > in my view i have a <%= date_select ''birthdate'',''user'' %> > > > > but dont know how to set a value for date_select that isnt the current date. > > > You''ve got the parameters reversed; the ActiveRecord instance comes first: > http://api.rubyonrails.com/classes/ActionView/Helpers/DateHelper.html#M000381 > > Also, if you need the TIME part of the DATETIME column, you may want > datetime_select instead. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
date_select should be handling that for you, assuming: 1. You call it <%= date_select ''user'', ''birthdate'' %> 2. @user is an instance variable that has been set. 3. @user.respond_to?(:birthdate) 4. @user.birthdate returns a Date. Make sure all four of those things are true, and you should be OK. On 1/7/06, Adam Denenberg <straightflush@gmail.com> wrote:> sorry your right,i typed it wrong in the email, its correct in my > view. However i still dont know how to populate the ''default'' values > of the month/day/year. it always defaults to the current date. How > do i set the birthdate(1i) pieces of the object so that the form has > the values from the DB and not the current date? > > thanks > adam > > > On 1/7/06, Wilson Bilkovich <wilsonb@gmail.com> wrote: > > On 1/6/06, Adam Denenberg <straightflush@gmail.com> wrote: > > > when retreiving a date from a DATETIME field in a database, is there a > > > way to set the date to the value of the DB in the view? It seems to > > > always default to the current date... > > > > > > if I have a field called birthdate in the users table and i do > > > > > > @user = User.find(@params[:id]) > > > > > > in my view i have a <%= date_select ''birthdate'',''user'' %> > > > > > > but dont know how to set a value for date_select that isnt the current date. > > > > > You''ve got the parameters reversed; the ActiveRecord instance comes first: > > http://api.rubyonrails.com/classes/ActionView/Helpers/DateHelper.html#M000381 > > > > Also, if you need the TIME part of the DATETIME column, you may want > > datetime_select instead. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Adam: On Jan 6, 2006, at 8:36 PM, Adam Denenberg wrote:> > but dont know how to set a value for date_select that isnt the > current date.[untested] date_select "birthday", "user", :start_year => user.birthday.year, :start_month => user.birthday.mon, :start_day => user.birthday.day Cheers, Hasan Diwan <hasan.diwan@gmail.com> -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 186 bytes Desc: This is a digitally signed message part Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060111/8e402b34/PGP.bin
Possibly Parallel Threads
- date_select broken
- Overriding date_select in local project to use custom value rather than blank for starting option...
- Rails 2.1 and ddatetime_select
- In datetime_select, :order does not work, but it works for date_select Why
- specifying m/d/y order in datetime_select