Rails 3 date_select for year only

Posted by tvalent2 on Stack Overflow See other posts from Stack Overflow or by tvalent2
Published on 2011-11-21T16:39:58Z Indexed on 2011/11/21 17:50 UTC
Read the original article Hit count: 174

I have a form in my Rails 3 app where I want to create a select tag for just the year on a method :grad_year. I have everything working - and storing - properly using date_select and adding :discard_month and :discard_day. However when I render @profile.grad_year I get the month and day values. So I'm wondering how to store and render only the year for @profile.grad_year?

Here is the form:

<%= f.date_select :grad_year, {:start_year => Time.now.year, :end_year => Time.now.year - 95, :discard_day => true, :discard_month => true}, :selected => @profile.grad_year %>

In my migration:

t.date :grad_year

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby-on-rails-3