Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit due to lack of rep:</strong> </p> <p>This will work in rails 3.1, not sure about 3.0 or below.. </p> <p>Also, davidb's answer would, if I understand it correctly, load <em>all</em> of the images regardless of whether the user wants to view them or not - this solution would only load them if the user clicks on the link to view them.. </p> <p>..............................................................................</p> <h1>controller</h1> <pre><code> def all_car_photos ... respond_to do |format| format.js end end </code></pre> <h1>view</h1> <pre><code> &lt;div id="column-left"&gt; &lt;%= render :partial =&gt; "car_gallery" %&gt; &lt;/div&gt; &lt;div id="column-right"&gt; &lt;%= render :partial =&gt; "vehicle_info" %&gt; &lt;/div&gt; &lt;%= link_to "Show All Photos", path_to_controller_action(@car), { :method =&gt; :get, :remote =&gt; true} %&gt; </code></pre> <h1>all_car_photos.js.erb</h1> <pre><code> $('#column-right').html("&lt;%= escape_javascript(render "car_gallery_all") %&gt;"); </code></pre> <p>Ok so, the view contains the link_to method which points to the all_car_photos controller action. The key thing here is that the link_to contains :remote => true - this submits the request using the baked in Rails AJAX functionality. </p> <p>The controller action does what it needs to do, but responds with the .js view - all_car_photos.js.erb - This contains a line of jQuery which will replace the content of the 'column-right' div with the 'car_gallery_all' partial.. </p> <p>It's late, but that setup should work..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload