Chuck Vose wrote:> I''m having difficulty figuring out the ruby neccessary to do this
so I
> thought I would try the list. I''m hoping to get a date_select to
only
> display certain days (specifically only fridays) but rails doesn''t
> seem to have the flexibility so I''ve been going at it in ruby to
no
> avail.
>
> I''ve looked on google but couldn''t find it (because it
isn''t there or
> I don''t know exactly what to search for). I''m not
concerned about
> having the full railsy date select but it would be nice if it''s
> possible.
>
> This is the code so far:
>
> ...
>
> Cheers,
> Chuck Vose
This will get the next friday, including today if it is a friday:
def get_next_weekday(weekday)
date = Date.today
until date.wday == weekday
date += 1
end
date
end
Then you can do:
def select_friday(in_model, in_attr)
friday = get_next_weekday(5)
@dates = []
friday.step(20, -7){|day| @dates << day}
friday.step(20, 7){|day| @dates << day}
@dates.sort!
select in_model, in_attr, @dates
end
And to display them, you should be able to use the standard (non date
specific) select tag:
<%= select ''model'', ''date_field'',
@dates.collect {|date| [date.to_s(:short), date.to_s(:db)] } %>
The value of each friday on the list is "2006-07-21", ready to be sent
to the DB, but the user sees "Jul 21, 2006" or whatever format is
assigned to the :short symbol.
--
Posted via http://www.ruby-forum.com/.