Trip
Trip

Reputation: 27114

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

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;"}

But every way I try it fails. Anyone know the syntax?

Upvotes: 1

Views: 1445

Answers (2)

Jeff Paquette
Jeff Paquette

Reputation: 7127

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;")

Upvotes: 2

John Topley
John Topley

Reputation: 115322

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;")

Upvotes: 5

Related Questions