ruby on rails - How do I make a form_for select helper display dates in descending order? -


I am new to both Ruby and Rail and I have trouble getting a select drop down for the current year and then to show I am using form_ to create form / field

I can work in ascending order with the following:

  & lt;% = builder.label: modelyear, "Model Year"%> & Lt;% = Builder Selection: modelyear, (time.Jon.news.yours- 30) .. (time.zon.news.your + 0)% & gt;  

This does not work:

  <% = builder.label: modelyear, "model year"%> & Lt;% = Builder Selection: modelyear, (time.Jon.new.year) .. (time.Jon.N. 30 - 30)% & gt; & Lt;% = builder.label: modelyear, "Model Year"% & gt; & Lt;% = Builder Selection: modelyear, (time.Jon.news.your + 0) .. (time.Jon.N. 30 - 30)% & gt;  

Edit: Complete code as the request (with the original attempt on the selector)

   

user.rb

  class user & lt; ActiveRecord :: Base has has_many: products, dependent: deleted accepts_nested_attributes_for: products ,: allow_destroy = & gt; True before_save {email.downcase! } Validates: first_name, presence: true valid: last_name, presence: true valid: email, presence: correct confirmation: address1, presence: correct confirmation: address 2, length: {max: 30} valid: city, presence: true valid : State  Maximum: 20} Valid: Zipcode, Length: {Max: 20} Valid: Country, Attendance: Right End  

product.rb < / P>

  class product & lt; ActiveRecord :: Base is_to: User Confirms: Serial, Attendance: Correct Confirmation: modelyear, Length: {Max: 4} End  

This should work

  & lt;% = builder.select: modelyear, ((Time.zone.now.year - 30) .. (Time.John .now.year + 0)). To_a.reverse% & gt;  

Here I am converting the range object to an array , which is also accepted as parameter You can use the convenient array method.


Comments