# Problem with link\_to\_function resulting rjs error, please he

**URL:** <https://www.ruby-forum.com/t/problem-with-link-to-function-resulting-rjs-error-please-he/110957>\
**Category:** Rails\
**Created:** [August 1, 2007, 2:12pm UTC](https://www.ruby-forum.com/t/problem-with-link-to-function-resulting-rjs-error-please-he/110957 "2007-08-01T14:12:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mister\_Yu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/22d042/32.png) [@Mister\_Yu](https://www.ruby-forum.com/u/Mister_Yu)\
**Post date:** [August 1, 2007, 2:12pm UTC](https://www.ruby-forum.com/t/problem-with-link-to-function-resulting-rjs-error-please-he/110957/1 "2007-08-01T14:12:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mister\_Yu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/22d042/32.png) [@Mister\_Yu](https://www.ruby-forum.com/u/Mister_Yu)\
**Post date:** [August 7, 2007, 1:25pm UTC](https://www.ruby-forum.com/t/problem-with-link-to-function-resulting-rjs-error-please-he/110957/2 "2007-08-07T13:25:24Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Mister\_Yu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/22d042/32.png) [@Mister\_Yu](https://www.ruby-forum.com/u/Mister_Yu)\
**Post date:** [August 14, 2007, 4:41pm UTC](https://www.ruby-forum.com/t/problem-with-link-to-function-resulting-rjs-error-please-he/110957/3 "2007-08-14T16:41:23Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Mister\_Yu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/22d042/32.png) [@Mister\_Yu](https://www.ruby-forum.com/u/Mister_Yu)\
**Post date:** [August 14, 2007, 4:51pm UTC](https://www.ruby-forum.com/t/problem-with-link-to-function-resulting-rjs-error-please-he/110957/4 "2007-08-14T16:51:26Z")

</div>

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