Hi,

I have a rails project, where there are three divs on a page - search,
results, images. When I enter a search query in the search div, a
link_to_remote updates the results div with the results. Each result
is in turn a link_to_remote that calls render :partial on the images
div to show images for that result.

When i first get some results, the results show up fine. When I click
on a result the first time, the images show up, and its good. When I
click on another result link, the images show up, but the results pane
gets wiped out. Can anybody help?

Thanks!

The relevant code is below (only relevant parts are shown) - the
partials for results and images are not shown, as they are trivial:

#home.html.erb

<%= javascript_include_tag :defaults%>
<div id='query-div'>
<%= text_field_tag :phrase%>
<%=link_to_remote "Go",
        :url => {:action => 'show_results'},
        :with => "$('phrase').serialize()"
        %>
</div>

<table>
        <tr>
                <td style='width: 50%; border: 2px solid black;'>
                        <div id='results-div'/>
                </td>
                <td style='width: 50%; border: 2px solid black;'>
                        <div id='images-div'/>
                </td>
        </tr>
</table>

# home_controller.rb

def show_results

  phrase = params[:phrase]
  @query = Query.new
  @query.phrase = phrase
  @query.load_results!
  @result_names = @query.results.map{|r| r.name}
  render :update do |page|
    page.replace_html 'results-div', :partial => 'results'
  end
end

def show_images

        result_name = params[:result_name]

        phrase = params[:phrase]

        @result = Result.find_by_name(result_name)

        @result.load_images!
        @images = @result.images
        render :update do |page|
          page.replace_html 'images-div', :partial => 'images'
        end
end

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to