Problem with link_to_function resulting rjs error, please he


#1

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:

<%= 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
%>

<% form_tag :action => 'add_comment', :id =>@place do %> <%= render :partial => 'comment_form' %> <%= submit_tag "Submit" %> <% end %>

what is the problem and how do i fix it?

thanks in advance.


#2

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 :frowning:

I wish I could be more help…

We can only hope that this problem is fixed!


#3

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/Helpers/JavaScriptHelper.html
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


#4

Correction: some of the error statements give a “$
(‘details’).toggleBlind is not a function” error…jon