Forum: Ruby on Rails Drop downs for new and edit

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1a8ba6cf5e232c16ecefa1618e9fb4ed?d=identicon&s=25 Qas WM (qaswm)
on 2009-02-03 13:42
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 name="vehicle[year_made]" id="vehicle_year_made">
<option value="0" selected="selected">-- Select --</option>
<%= options_from_collection_for_select((1970..Time.now.year).collect
{|p| [ p, p ] }, "first", "last") %>
</select>

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?
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-02-03 13:49
(Received via mailing list)
On 3 Feb 2009, at 12:42, Qaiser Wali wrote:

> {|p| [ p, p ] }, "first", "last") %>
> </select>
>

You could use select_year

Fred
1a8ba6cf5e232c16ecefa1618e9fb4ed?d=identicon&s=25 Qas WM (qaswm)
on 2009-02-03 13:55
> 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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-02-03 13:57
(Received via mailing list)
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/Help...
  )

Fred
1a8ba6cf5e232c16ecefa1618e9fb4ed?d=identicon&s=25 Qas WM (qaswm)
on 2009-02-03 14:03
>
> You could start by reading the api docs
> (http://api.rubyonrails.org/classes/ActionView/Help...
>   )
>
> 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?
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-02-03 14:25
(Received via mailing list)
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
1a8ba6cf5e232c16ecefa1618e9fb4ed?d=identicon&s=25 Qas WM (qaswm)
on 2009-02-03 14:44
> 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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-02-03 15:48
(Received via mailing list)
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
This topic is locked and can not be replied to.