Value of a 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, c.id]} %>

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 ?

Thanks

On May 15, 11:02 am, “[email protected][email protected] 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:

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.

I am going to use collection_select as you advise.

This list is alreay in a form : _form.rhtml

2-Model <%= select 'clim', 'themodel_id', @themodels.collect {|c| [c.nom, c.id]} %>

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

Thank you.

On May 15, 12:05 pm, “[email protected][email protected] 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’))”}) %>

<%= link_to(‘edit’, {:action => “edit”, :id => “temp”}, {:id =>
“edit_link”}) %>


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

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

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