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%> <%@questions.each do |question|%> <h1 class="question"> <%= link_to_function(question.description) do |page| page.visual_effect :toggle_appear, ''answer_<%=i%>'' end%> </h1> <p id="answer_<%=i%>"> <%=question.answer%> </p> <%i=i+1%> <%end%> Thank you for your help, -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 29 Apr 2008, at 11:20, san 1981 wrote:> > 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%> > <%@questions.each do |question|%> > <h1 class="question"> > <%= link_to_function(question.description) do |page| > page.visual_effect :toggle_appear, ''answer_<%=i%>'' > end%> > </h1>When you call page.visual_effect you''re not in erb-land, so you need "answer_#{i}" Fred> > > <p id="answer_<%=i%>"> > <%=question.answer%> > </p> > <%i=i+1%> > <%end%> > > Thank you for your help, > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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%> <%@questions.each do |question|%> <h1 class="question"> <%= link_to_function(question.description) do |page| page.visual_effect :toggle_appear, ''answer_#{i}'' end%> </h1> <p id="answer_#{i}"> <%=question.answer%> </p> <%i=i+1%> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, On Apr 29, 1:54 pm, san 1981 <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> <%i=0%> > <%@questions.each do |question|%> > <h1 class="question"> > <%= link_to_function(question.description) do |page| > page.visual_effect :toggle_appear, ''answer_#{i}'' > end%> > </h1> > > <p id="answer_#{i}"> > <%=question.answer%> > </p> > <%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. <%@questions.each_with_index do |question, i| %> <h1 class="question"> <%= link_to_function(question.description) do |page| page.visual_effect :toggle_appear, "answer_#{i}" end %> </h1> <p id="answer_<%=i%>"> <%=h question.answer%> </p> <% end %> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Apr 29, 2008 at 6:54 AM, san 1981 <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---