Forum: Ruby on Rails Problem with link_to_function resulting rjs error, please he

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aed326335b876b6baf65016450c00cfa?d=identicon&s=25 Mister Yu (Guest)
on 2007-08-01 14:12
(Received via mailing list)
Hello all,

i am trying to add some ajax effect to the page and use the
link_to_funtion tag to toggle a "comment form" div.

but when i click on the link, firefox gives me error box saying:
RJS error
TypeError: Effect[effect_class] is not a constructor

after i click OK, it says:
$("comment_form").visualEffect("toggle_blind");
$("add_comment").update("Cancel");

here's the code for the div:

<!-- comment_form div-->
<%= link_to_function ("Add a comment", nil, :id =>"add_comment") do |
page|
 page[:comment_form].visual_effect  :toggle_blind
 page[:add_comment].replace_html "Cancel"
end
%>
<div id="comment_form" style="display: none;">
  <% form_tag :action => 'add_comment', :id =>@place do %>
      <%= render :partial => 'comment_form' %>
      <%= submit_tag "Submit" %>
  <% end %>
</div>
<!-- comment_form div-->

what is the problem and how do i fix it?

thanks in advance.
66d4f86a167826f5dd3bd32ff05b6cde?d=identicon&s=25 Steven Mead (bosh_bosh)
on 2007-08-07 13:25
I have exactly the same problem when using a code block to
link_to_function, the only solution I have uncovered is not to use the
code block form.  Unfortunately this is somewhat limited :(

I wish I could be more help...

We can only hope that this problem is fixed!
3da4ed7ea16825fead6120d70dc7da43?d=identicon&s=25 Jon Seidel (jseidel)
on 2007-08-14 16:41
(Received via mailing list)
I think there may be a bug in Rails... I wanted to use this as well
(it's documented in the Rails API docs as an example at
http://api.rubyonrails.com/classes/ActionView/Help...
as a link_to_function example).  I believe it has to do with the use
of the toggle_blind method on the $() prototype function -- maybe that
method is not being added properly?  I tested many different
combinations and did find one that worked:

  page.visual_effect :toggle_blind, 'details'  <== my div id; same as
your "comment_form

Notice that you can't use the element proxy of page[:comment_form] as
it winds up returning the $() form which fails.  Here are the
different variations that I tried:

  page[:details].visual_effect :toggle_blind
  page[:details].visual_effect('element', :toggle_blind)
  page[:details].visual_effect('details', :toggle_blind)
  page[:details].visual_effect :blind
  page[:details].toggle_blind

All of the above give that "not a constructor" error.

BUT... Note that a simple "toggle" (view/hide) DOES work:

  page[:details].toggle

HTH...jon
3da4ed7ea16825fead6120d70dc7da43?d=identicon&s=25 Jon Seidel (jseidel)
on 2007-08-14 16:51
(Received via mailing list)
Correction: some of the error statements give a "$
('details').toggleBlind is not a function" error...jon
This topic is locked and can not be replied to.