# Drop downs for new and edit

**URL:** <https://www.ruby-forum.com/t/drop-downs-for-new-and-edit/159325>\
**Category:** Rails\
**Created:** [February 3, 2009, 1:42pm UTC](https://www.ruby-forum.com/t/drop-downs-for-new-and-edit/159325 "2009-02-03T13:42:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![qaswm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/5f8ce5/32.png) [@qaswm](https://www.ruby-forum.com/u/qaswm)\
**Post date:** [February 3, 2009, 1:42pm UTC](https://www.ruby-forum.com/t/drop-downs-for-new-and-edit/159325/1 "2009-02-03T13:42:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![qaswm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/5f8ce5/32.png) [@qaswm](https://www.ruby-forum.com/u/qaswm)\
**Post date:** [February 3, 2009, 1:49pm UTC](https://www.ruby-forum.com/t/drop-downs-for-new-and-edit/159325/2 "2009-02-03T13:49:11Z")

</div>

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

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

You could use select\_year

Fred

---

<div class="post-metadata">

**Author:** ![qaswm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/5f8ce5/32.png) [@qaswm](https://www.ruby-forum.com/u/qaswm)\
**Post date:** [February 3, 2009, 1:55pm UTC](https://www.ruby-forum.com/t/drop-downs-for-new-and-edit/159325/3 "2009-02-03T13:55:08Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![qaswm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/5f8ce5/32.png) [@qaswm](https://www.ruby-forum.com/u/qaswm)\
**Post date:** [February 3, 2009, 1:57pm UTC](https://www.ruby-forum.com/t/drop-downs-for-new-and-edit/159325/4 "2009-02-03T13:57:25Z")

</div>

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  
([ActionView::Helpers::DateHelper](http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#M001677)  
)

Fred

---

<div class="post-metadata">

**Author:** ![qaswm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/5f8ce5/32.png) [@qaswm](https://www.ruby-forum.com/u/qaswm)\
**Post date:** [February 3, 2009, 2:25pm UTC](https://www.ruby-forum.com/t/drop-downs-for-new-and-edit/159325/5 "2009-02-03T14:25:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![qaswm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/5f8ce5/32.png) [@qaswm](https://www.ruby-forum.com/u/qaswm)\
**Post date:** [February 3, 2009, 2:44pm UTC](https://www.ruby-forum.com/t/drop-downs-for-new-and-edit/159325/6 "2009-02-03T14:44:29Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![qaswm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/5f8ce5/32.png) [@qaswm](https://www.ruby-forum.com/u/qaswm)\
**Post date:** [February 3, 2009, 3:48pm UTC](https://www.ruby-forum.com/t/drop-downs-for-new-and-edit/159325/7 "2009-02-03T15:48:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![qaswm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/5f8ce5/32.png) [@qaswm](https://www.ruby-forum.com/u/qaswm)\
**Post date:** [February 3, 2009, 2:03pm UTC](https://www.ruby-forum.com/t/drop-downs-for-new-and-edit/159325/8 "2009-02-03T14:03:38Z")

</div>

> You could start by reading the api docs  
> ([ActionView::Helpers::DateHelper](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?
