开发者

Rails datetime_select can't set default date if using prompts

I am having some trouble getting datetime_select to work in my form. I can get it to EITHER Set the default date OR allow prompts, but not both. What I really want is something like

      2011 June 18 hour minute

where the default values for the day, month and year popups are set, but the default values for the hour and minute are not. If I use this code:

     <%= f.datetime_select:start_time, 
        :default => Time.now, 
        :prompt => {:hour => "hour", :minute => "minute"} %>

I get the values

     2006 January 1 hour minute 

If I don't set the prompts, the default shows just fine.

    <%= f.datetime_select:start_time, :default => Time.now  %>

yields

    2011 June 18 23:53

I have also tried setting just the parts of the default that I want

    <%= f.datetime_select:start_tim开发者_开发技巧e, 
     :default =>{:year=>Time.now.year,:month=>Time.now.month,:day=>Time.now.day}, 
  :prompt => {:hour => "hour", :minute => "minute"} %>

and it does the same thing as just setting the whole default to Time.now.

Any thoughts? Is it really not supported to have prompts and a default?

Thanks for your help.


In my knowledge you should probably try something on the following lines :

<%= f.datetime_select :start_time, :default => Time.now.strftime('%Y %B %d %H %M') %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜