Forum: Ruby on Rails Value of a list

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
D0061d4a3d28febfaf27528c38407cc1?d=identicon&s=25 (Guest)
on 2007-05-15 11:03
(Received via mailing list)
Hi all,

I am a newbie. Those are little technical questions that will look
simple to me after a little while. But for the moment I am stuck.

I have a select list which I use to list the a marees table
<%= select 'clim', 'maree_id', @marees.collect {|c| [c.nom,]} %>

I would like to create a link edit which would link to the edit page
of the selected row of the list.

would you be so kind and give me an hint ?

8a00145d61d84b58c4688cdc50bac48f?d=identicon&s=25 Wiebe Cazemier (halfgaar)
on 2007-05-15 11:46
(Received via mailing list)
On May 15, 11:02 am, "" <> wrote:
> would you be so kind and give me an hint ?
> Thanks

First, I'd use the method collection_select, because then you don't
have to hassle with the collect call yourself.

As for your problem, you're going to have to use javascript for that.
You'll have to change the edit link whenever the dropdown changes. As
an HTML option, pass

:onchange => "update_link('id_of_link')"

and put a script in your view like:

<script type="text/javascript">
  function updateLink(link) {

You'll have to find the nodes in link in which the relevant info is.
I'm not too experienced with javascript, so I can't help you there
without trying it first.

It's easier to just make a form, in which you select what you want to
edit, and then press the edit button.
D0061d4a3d28febfaf27528c38407cc1?d=identicon&s=25 (Guest)
on 2007-05-15 12:05
(Received via mailing list)
I am going to use collection_select as you advise.

This list is alreay in a form : _form.rhtml

<p><label for="clim_themodel_id">2-Model</label>
<%= select 'clim', 'themodel_id', @themodels.collect {|c| [c.nom,]} %>

How would I do a form around that so poeple can edit what they have
choosen ?

Thank you.
8a00145d61d84b58c4688cdc50bac48f?d=identicon&s=25 Wiebe Cazemier (halfgaar)
on 2007-05-15 12:34
(Received via mailing list)
On May 15, 12:05 pm, "" <> wrote:
> Thank you.

First, as an exercise in Javascript, I decided to program it:

<%= collection_select("clim", "themodel_id", @themodels, "id", "nom",
{}, {:onchange => "updateLink($('edit_link'))"}) %>

<script type="text/javascript">
  function updateLink(link) {
    link.href = 'edit/' + $('clim_themodel_id').options[$

<%= link_to('edit', {:action => "edit", :id => "temp"}, {:id =>
"edit_link"}) %>

<script type="text/javascript">updateLink( $("edit_link") );</script>

But, if you still want to use it, it up to you :)

About the form, that's just a regular form as I'm sure you've made

<%= form_tag({:action => "edit"}) %>

<%= collection_select("clim", "themodel_id", @themodels, "id", "nom")

<%= submit_tag("edit") %>
<%= end_form_tag %>

Then in the edit action, params["clim"]["themodel_id"] is your id,
which you can then use in whatever way you like.

BTW, in both situations, it may be cleaner not to use "select", but
"select_tag", because you're only using the id to redirect you to
somewhere else. "Select" takes in an object and method name, to be
used for automatic attribute and retrieval for creating or editing
values, but you don't do that here.
This topic is locked and can not be replied to.