[Rails] RoR date_select() default date

Norman Timmler lists at inlet-media.de
Wed Mar 1 09:09:25 GMT 2006


Am Dienstag, den 28.02.2006, 23:20 +0100 schrieb mehdi:
> Hi,
> I'm trying to use the date_select() function of ruby on rails, but I 
> want my form  easier to use and I want to put an explicit default date. 
> I don't kow how to do that. I can't find any information about default 
> on the web, and no example either.
> 
> Let me know if there is a tips that I don't know...

>From the Rails API Documentation:

"date_select(object, method, options = {}) 

Returns a set of select tags (one for year, month, and day) pre-selected
for accessing a specified date-based attribute (identified by method) on
an object assigned to the template (identified by object)."

I give you an example:

# Controller:
def new
  @invoice = Invoice.new(:date_of_issue => Date.today)
end

# View:
<%= date_select 'invoice', 'date_of_issue' %>

The date_select helper will display the date of today as default. Change
the date in the controller, and the default date in the view will
likewise.

-- 
Norman Timmler

http://blog.inlet-media.de



More information about the Rails mailing list