占位符在select_date rails 3中

时间:2012-12-29 14:51:42

标签: ruby-on-rails ruby-on-rails-3 forms placeholder

我通常可以使用

之类的东西在表单中放置占位符
:placeholder => "something" or {:placehoder => "something"}

我对如何在select_date中放置月份和年份的占位符感到有点困惑。我正在使用这个

<%= select_date(date = Date.current, :order => [:month, :year]) %>

我想在一个月和一年中有一个占位符

任何人都知道如何实现这一目标

由于

2 个答案:

答案 0 :(得分:6)

选择占位符?哈文没听说过这样的事。也许你想要:

 <%=  select_date(date = Date.current, :order => [:month, :year], :prompt => { :month => 'Select month', :year => 'Select year' }  %>

Here is the answer启发了我,所以你可能想要归功于philipth。我只是根据你的情况调整了它。如果您还需要更多信息,可以查看documentation。你可以在那里找到这样的例子:

# Generates a date select with custom prompts.
date_select("article", "written_on", :prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year' })

答案 1 :(得分:0)

您应该使用prompt: true来使用I18n翻译

date_select :user, :date_of_birth, prompt: true

翻译键是

fr:
  datetime:
    prompts:
      day: Jour
      hour: Heure
      minute: Minute
      month: Mois
      second: Seconde
      year: Année