Conditional Protoypte updates - Is there a simple answer?

I have a simple show/hide function for a div as follows :

<%= link_to_function "Show|Hide",
    visual_effect(:toggle_slide, :images, :duration => 1, :queue => 

‘end’) %>

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).

I’d like to do something like :

<%= link_to_function "Hide", update_page{|page|
page.visual_effect(:toggle_slide, :images, :duration => 1, :queue => 

if‘toggle_images’) == ‘Hide’‘toggle_images’).replace_html(:text => ‘Show’)
else‘toggle_images’).replace_html(:text => ‘Hide’)
{ :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
your RJS template name. Don’t define a method for this in your
and Rails will magically find your RJS template. All of your page.*
should go into the RJS template just fine.

Read about RJS stuff here:

And here’s a list to lots of stuff:

Hope that helps!

On 9/26/06, robl [email protected] wrote:

clicked again).

Posted via

Terry (TAD) Donaghe

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 …

You might want to take a look at the UJS plugin.

This seems like the kind of thing you want. It’s all ruby, with no
javascript anywhere. And can be DRY too if used well.

Have a Hide, and your RJS-ish code inside an


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs