I’d like to just display Hide, then when the link is clicked perform the
toggle_slide and then change the link text to ‘Show’ (and back when
clicked again).
‘end’)
if page.select(‘toggle_images’) == ‘Hide’
page.select(‘toggle_images’).replace_html(:text => ‘Show’)
else
page.select(‘toggle_images’).replace_html(:text => ‘Hide’)
end
},
{ :id => ‘toggle_images’} %>
However you can’t use Ruby within the block like this (as far as I can
tell). I could use an Ajax call to a partial to do the replace but this
seems overkill.
Does anybody have a solution for this example that doesn’t involve
custom JS or an Ajax call ?
I think this code is just screaming for an RJS template.
Change your link_to_function to a link_to_remote and name your action
after
your RJS template name. Don’t define a method for this in your
controller
and Rails will magically find your RJS template. All of your page.*
code
should go into the RJS template just fine.
But that means I need to do a remote call to a server to replace some
innerHTML for a DOM element for an already known value - not very
efficient really …