Drop downs for new and edit


#1

I have a drop down in my forms.

Year Manufactured The value needs to be from 1970 – current year

In the new form i am using the following code

-- Select -- <%= options_from_collection_for_select((1970..Time.now.year).collect {|p| [ p, p ] }, "first", "last") %>

I want to be able to show the items in reverse order. Where the most
recent year shows first.

Also in the edit form i want similar code but with the selected item to
be the one that is present in the database. How can i achieve this?


#2

On 3 Feb 2009, at 12:42, Qaiser Wali wrote:

{|p| [ p, p ] }, “first”, “last”) %>

You could use select_year

Fred


#3

On 3 Feb 2009, at 12:42, Qaiser Wali wrote:

You could use select_year

Fred

I am sorry I do not know ruby as much so will need more help than this.


#4

On 3 Feb 2009, at 12:55, Qaiser Wali wrote:

On 3 Feb 2009, at 12:42, Qaiser Wali wrote:

You could use select_year

Fred

I am sorry I do not know ruby as much so will need more help than
this.

You could start by reading the api docs
(http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#M001677
)

Fred


#5

On 3 Feb 2009, at 13:03, Qaiser Wali wrote:

I still need to have a custom value like – Select – added in there.

And also for edit time, how do i make it that it shows the value
from db
already selected?
Both of those are covered by the examples in the api docs I linked to.

Fred


#6

Both of those are covered by the examples in the api docs I linked to.

Fred

Thanks for the help so far, but using this i am running into more issues
that before, I am not getting the field name as i want it using
:field_name to specify the vehicle[year_made] gives me
date[vehicle[year_imported]] and also the prompt does not show.

So guiding me to the API is not helping me solving my problem. Any other
solutions.


#7

On 3 Feb 2009, at 13:44, Qaiser Wali wrote:

date[vehicle[year_imported]] and also the prompt does not show.

you need to play with the the :prefix option to change date to
something else.

Fred


#8

You could start by reading the api docs
(http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#M001677
)

Fred

Thanks for this, now two more questions remain.

I still need to have a custom value like – Select – added in there.

And also for edit time, how do i make it that it shows the value from db
already selected?