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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On May 15, 11:02 am, "hlei...-CnXOeebvsI53K8eIWKoEHQ@public.gmane.org" <hlei...-CnXOeebvsI53K8eIWKoEHQ@public.gmane.org> wrote:> 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 ? > > ThanksFirst, 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) { bla; } </script> 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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, c.id]} %> How would I do a form around that so poeple can edit what they have choosen ? Thank you. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On May 15, 12:05 pm, "hlei...-CnXOeebvsI53K8eIWKoEHQ@public.gmane.org" <hlei...-CnXOeebvsI53K8eIWKoEHQ@public.gmane.org> wrote:> 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, > c.id]} %> > > How would I do a form around that so poeple can edit what they have > choosen ? > > 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[$ (''clim_themodel_id'').selectedIndex].value; } </script> <%= 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 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---