Forum: Ruby on Rails How can I access currently selected records in the view?

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.
7db3b1680807d393d40260591b4ae5e0?d=identicon&s=25 sa 125 (sa125)
on 2009-02-19 14:31
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?
F04a22457fcbfee2afc77e77482abe08?d=identicon&s=25 Rails List (railslist)
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!.
7db3b1680807d393d40260591b4ae5e0?d=identicon&s=25 sa 125 (sa125)
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).
D188e591eac11021329b8821a5f954c7?d=identicon&s=25 Ar Chron (railsdog)
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?
7db3b1680807d393d40260591b4ae5e0?d=identicon&s=25 sa 125 (sa125)
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!
This topic is locked and can not be replied to.