开发者

What is the syntax to add a style to a date_select?

开发者 https://www.devze.com 2023-01-23 06:35 出处:网络
I can\'t seem to figure this out. I have this : = date_select(\"card_signup\", \"dob\", :end_year => DateTime.now.year - 100, :discard_day => true, :discard_month => true)

I can't seem to figure this out.

I have this :

= date_select("card_signup", "dob", :end_year => DateTime.now.year - 100, :discard_day => true, :discard_month => true)

And I want to include this {:style => "width: 121px;"}

开发者_JAVA技巧But every way I try it fails. Anyone know the syntax?


The date_select method accepts four arguments, the last two of which (options and html_options) are Ruby hashes. Therefore you need to use braces to group the options corresponding to the third method argument so that the method can determine which passed options belong to which parameter.

Try this:

date_select("card_signup", "dob", { :end_year => DateTime.now.year - 100,
  :discard_day => true, :discard_month => true },
  :style => "width: 121px;")


Given the docs at rubyonrails, it appears the syntax would be something like:

date_select("card_signup", "dob", { :end_year => DateTime.now.year - 100, :discard_day => true, :discard_month => true}, {:style => "width: 121px;"})

Since rails turns trailing arguments into hash for you, you can leave off the final braces:

date_select("card_signup", "dob", { :end_year => DateTime.now.year - 100, :discard_day => true, :discard_month => true}, :style => "width: 121px;")

0

精彩评论

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