Visual_effect

Hello,

I try to make a visual effect “toggle” on a list generated automatically
from a controller, I’ve tried this but that doesn’t work? the id
"answer_<%=i%> isn’t recognized I think?

<%i=0%>
<[email protected] do |question|%>

<%= link_to_function(question.description) do |page| page.visual_effect :toggle_appear, 'answer_<%=i%>' end%>

<%=question.answer%>

<%i=i+1%> <%end%>

Thank you for your help,

On 29 Apr 2008, at 11:20, san 1981 wrote:

<%= link_to_function(question.description) do |page| page.visual_effect :toggle_appear, 'answer_<%=i%>' end%>

When you call page.visual_effect you’re not in erb-land, so you need
“answer_#{i}”

Fred

thank you Fred,

I’ve changed so this in my code but that works only for the first title;
if I click on another title, it’s always the description of the first
title that disappears/appears? I would like to make a
appearition/disappearition of the description linked to the title
concerned.

<%i=0%>
<[email protected] do |question|%>

<%= link_to_function(question.description) do |page| page.visual_effect :toggle_appear, 'answer_#{i}' end%>

<%=question.answer%>

<%i=i+1%>

Hi,

On Apr 29, 1:54 pm, san 1981 [email protected] wrote:

<%i=i+1%>

You’ve nearly got it, but you’re confusing ERB scope and ruby scope.
Also strings surrounded with single quotes in ruby don’t get
interpolated, you need double quotes.

Finally you don’t need your index variable i when you could use
each_with_index instead.

<[email protected]_with_index do |question, i| %>


<%= link_to_function(question.description) do |page|
page.visual_effect :toggle_appear, “answer_#{i}”
end %>

<p id="answer_<%=i%>">
  <%=h question.answer%>
</p>

<% end %>

On Tue, Apr 29, 2008 at 6:54 AM, san 1981
[email protected] wrote:

thank you Fred,

I’ve changed so this in my code but that works only for the first title;
if I click on another title, it’s always the description of the first
title that disappears/appears? I would like to make a
appearition/disappearition of the description linked to the title
concerned.

check the source to make sure it looks as you’d expect it to.

This could arguably be simplified even further with the
content_tag_for and dom_id methods. Something like this (untested):

<% @questions.each do |question| %>
<% content_tag_for :h1, question do
link_to_function(question.description) do |page|
page.visual_effect :toggle_appear, dom_id(question, “answer”)
end
end %>

 <% content_tag_for :p,  question, "answer" do %>
   <%=h question.answer%>
 <% end %>

<% end %>

Search the Rails API docs for dom_id and content_tag_for.