ruby-on-rails – 插入一个css类以在Rails date_select上选择

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 插入一个css类以在Rails date_select上选择前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用date_select方法生成3个html选择,日,月和年.
但我需要每个选择都有一类CSS.

我没有在文档中找到如何将参数传递给帮助器,我尝试了几种方法,没有.

Rails查看:

  1. <%= f.date_select :birthday,:order => [:day,:month,:year],:start_year => 1910,:end_year => 2012,:html => {:class => ['day','month','year']} %>

HTML输出

  1. <select id="poll_user_birthday_3i" name="poll_user[birthday(3i)]">
  2. <select id="poll_user_birthday_2i" name="poll_user[birthday(2i)]">
  3. <select id="poll_user_birthday_1i" name="poll_user[birthday(1i)]">

像我这样的HTML输出

  1. <select id="poll_user_birthday_3i" name="poll_user[birthday(3i)]" class="day">
  2. <select id="poll_user_birthday_2i" name="poll_user[birthday(2i)]" class="month">
  3. <select id="poll_user_birthday_1i" name="poll_user[birthday(1i)]" class="year">

谢谢!

解决方法

他们解决这个问题的方式是用css

视图

  1. <span class="datetime"> <%= f.date_select :birthdate,:end_year => 2012 %></span>

CSS

  1. .datetime select:nth-child(1){
  2. width: 130px;
  3. text-indent: 15px;
  4. }
  5.  
  6. .datetime select:nth-child(2) {
  7. width: 200px;
  8. text-indent: 5px;
  9. }
  10.  
  11. .datetime select:nth-child(3) {
  12. width: 110px;
  13. text-indent: 15px;
  14. }

猜你在找的Ruby相关文章