【问题标题】:Formatting Date with Simple Form用简单的形式格式化日期
【发布时间】:2012-11-02 23:28:09
【问题描述】:

我在我的 Rails 应用程序中使用Simple Form gem。在我的注册表单中,我有一个出生日期字段。但是,这些字段按以下顺序显示:年/月/日。

获取字段顺序月 - 日 - 年的最佳方式是什么?

我的表单如下所示:

 <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
   <%= f.input :created_at %>          
   <%= f.button :submit, "Sign up" %>      
<% end %>

【问题讨论】:

    标签: ruby-on-rails-3 simple-form


    【解决方案1】:

    你在找这个吗?

    <%= f.input :birthday, :order => [:month, :day, :year] %>
    

    【讨论】:

      【解决方案2】:

      我不知道它是否适用于 simple_form,但我怀疑它会...将以下内容添加到 config/locals/en.yml(或类似):

      en:
        date:
          order:
            - :month
            - :day
            - :year
      

      【讨论】:

      • 如果您不知道该字段是否为日期,那就完美了,因此您不能明确传递:order 选项
      猜你喜欢
      • 2012-01-15
      • 2019-08-19
      • 1970-01-01
      • 1970-01-01
      • 2013-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多