Note that there are some explanatory texts on larger screens.

plurals
  1. POruby "each do" and scriptaculous Effect.BlindDown/Up
    primarykey
    data
    text
    <p>I have a list of items with some details that I would like to reveal upon clicking a show/hide details link. after some experimenting, I've come across two issues.</p> <ol> <li><p>I'm having trouble making it so that the show/hide link only reveals the div of a specific item. right now, it is revealing all of the divs when clicking any of the show/hide links.</p></li> <li><p>Also, there has got to be a more elegant way to do this without doing a loop to generate a bunch of javascript. I looked into effect.multiple, but I'm not sure how to use it in this context.</p></li> </ol> <p>some insight or pointing in the general direction would be greatly appreciated! Thanks!</p> <p>here's the code for reference.</p> <pre><code> &lt;script type="text/javascript"&gt; function show_details() { &lt;% @posts.each do |b| %&gt; Effect.BlindDown('details_&lt;%= b.id %&gt;', {duration:0.3}); $('hide_details_link_&lt;%= b.id %&gt;').style.display = 'inline'; $('show_details_link_&lt;%= b.id %&gt;').style.display = 'none'; &lt;% end %&gt; } function hide_details() { &lt;% @posts.each do |b| %&gt; Effect.BlindUp('details_&lt;%= b.id %&gt;', {duration:0.3}); $('hide_details_link_&lt;%= b.id %&gt;').style.display = 'none'; $('show_details_link_&lt;%= b.id %&gt;').style.display = 'inline'; &lt;% end %&gt; } &lt;/script&gt; &lt;ul id="posts"&gt; &lt;% @posts.each do |b| %&gt; &lt;li&gt; &lt;div id="show_details_link_&lt;%= b.id %&gt;" style="display:inline;"&gt; &lt;%= link_to_function "show details", 'show_details()' %&gt; &lt;/div&gt; &lt;div id="hide_details_link_&lt;%= b.id %&gt;" style="display:none;"&gt; &lt;%= link_to_function "hide details", 'hide_details()' %&gt; &lt;/div&gt; &lt;div id="details_&lt;%= b.id %&gt;" style="display:none;"&gt; &lt;p&gt; &lt;%= b.comments %&gt;&lt;/p&gt; &lt;/div&gt; &lt;/li&gt; &lt;li&gt;&lt;%= link_to b.title, {:action =&gt; 'show', :id =&gt; b.id} -%&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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