One of my views enables searching records using a text field. The rendered view contains only records that match the search. After the view has rendered, I want to add an option to perform an update on the displayed records. The problem is, I don't know how to figure out which records are shown, since the search form is different from the update form, and I can only submit one of them. Any ideas?
on 2009-02-19 14:31
on 2009-02-19 14:39
Let us assume you are displaying search results using @mysearchlist and iterate through them. <% @mysearchlist.each do |a| %> <%= link_to a.title, :action => "show", :id => a.id %> <%= link_to 'edit', :action => "edit", :id => a.id %> <% end %> There you go!.
on 2009-02-19 14:50
Thanks for the quick response. I'm not sure I follow. My view is rendered with partials, called from search function when the user submits the search: <%= render :partial => 'record', :collection => @search_results %> -- def search_records # get the search form results from params conds = # formulate the conditions @search_results = Records.find(:all, :conditions => conds) # render the view end Now, a separate form on the page is used to update the shown records. I can't see how this relates to your answer (then again, I'm new to all this).
on 2009-02-19 15:38
sa 125 wrote: > Now, a separate form on the page is used to update the shown records. I > can't see how this relates to your answer (then again, I'm new to all > this). If you have a separate form on the page for edits, how are you getting the "selected" record into that form for editing? I assume there a list view at the top which returns all those record meeting the search criteria, and below is the editable form. Do you edit one by one, or are you looking for something more like an edit in place within the listing? Haven't done this myself, so this is all speculation... For one by one, I assume you'll need some column in the list partial where the action (on click) executes a remote call with that record id and loads that records data into the form portion for editing (discard what was in the form portion, and reload that form part with the "current" records data). Or something like that?
on 2009-02-19 16:58
> Do you edit one by one, or are you looking for something more like an > edit in place within the listing? > It's more like finding the records to update using a filtering form, and then updating some or all the attributes in these records using another update form. More code and explanations in this post: http://railsforum.com/viewtopic.php?id=27309 Feel free to answer there, and I'll link it here. Thanks!