How to wrap every select of date_select with a div in Rails?

后端 未结 5 1806
抹茶落季
抹茶落季 2020-12-19 01:08

I\'m using Ruby on Rails 3 to create a form for the user, where he can save his birthdate. All the actions around the controller and model work just fine. But I\'m having tr

5条回答
  •  隐瞒了意图╮
    2020-12-19 01:18

    I had a similar problem but I wanted each select box to have its own class.

    Here's what I did (using ERB not HAML):

    <%= select_month(@person.birthday, field_name: "birthday(2i)", prefix: "person", prompt: true) %>
    <%= select_day(@person.birthday, field_name: "birthday(3i)", prefix: "person", prompt: true) %>
    <%= select_year(@person.birthday, field_name: "birthday(1i)", prefix: "person", start_year: Date.today.year, end_year: 1905, prompt: true) %>
    

    Then I was able to wrap each in a div with the proper class but you could also add classes directly to the select tags like this:

    <%= select_month(@person.birthday, {field_name: "birthday(2i)", prefix: "person", prompt: true}, class: "class_name") %>
    

提交回复
热议问题