I have a faq where the answers are blinded down when the question is clicked. What I want to do is have a link that either blinds up or down all the answer-elements on the page. When the link is clicked, it should switch between the text "Show all" / "Hide all" and the link_to_remote should also change. I figure I´ve made a mess out of it as it is. Can I somehow make all this in action or something also?
How should I do this?
# in my controller: def display_all render(:update) do |page| page.select('div.answer').each do |answer| answer.visual_effect(:blind_down, :duration => 0.25, :fps => 100) end
page.replace_html :toggle_all, link_to_remote("Hide all", {:url => {:action => :hide_all}}, :id => "toggle_all") end end
def hide_all render(:update) do |page| page.select('div.answer').each do |answer| answer.visual_effect(:blind_up, :duration => 0.25, :fps => 100) end
page.replace_html :toggle_all, link_to_remote("Show all", {:url => {:action => :display_all}}, :id => "toggle_all") end end
## in my template:
<%= link_to_remote("Show all", {:url => {:action => :display_all}}, :id => "toggle_all")%>