Forum: Ruby on Rails toggle the caption of a link

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Tarscher (Guest)
on 2008-11-13 18:57
(Received via mailing list)
hi all,

I'm trying to toggle the caption of a link between show archive and
hide archive? Everytime a user clicks the link the caption should

I tried but this simply doesn't work.

Someone can help me out?


  <div id="show_archive">
    <%= link_to_function "Show archive" do |page|
        if page['show_archive'].value == "Show archive"
          page['show_archive'].replace_html("Hide archive")
          page['show_archive'].replace_html("Show archive")
    end %>
Robert Z. (Guest)
on 2008-11-13 21:17
(Received via mailing list)

First off you should download and install Firebug for firefox to help
you debug any javascript errors you may be having.

The problem you are having is because you are calling a non-existent
method, value(), on the div element. There is also no RJS method
called value:

You should probably just use plain ol javascript for this one so you
can check the current innerHTML of the div.

ie.  if ($('show_archive').innerHTML == 'Show archive') { ... }

Or you could set some arbitrary attribute on the div and check it

<div id='show_archive' expanded='true' %></div>
if ($('show_archive').readAttribute('expanded') ==  'true') { ... }

Robert Z.
Zapient, LLC
Ruby on Rails Development and Consulting
Rick (Guest)
on 2008-11-14 10:45
(Received via mailing list)
You might take a look at this:

This topic is locked and can not be replied to.