# Bug: Calling visual\_effect within helper

**URL:** <https://www.ruby-forum.com/t/bug-calling-visual-effect-within-helper/120511>\
**Category:** Rails\
**Created:** [November 17, 2007, 6:58pm UTC](https://www.ruby-forum.com/t/bug-calling-visual-effect-within-helper/120511 "2007-11-17T18:58:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cujigar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/2acd7d/32.png) [@cujigar](https://www.ruby-forum.com/u/cujigar)\
**Post date:** [November 17, 2007, 6:58pm UTC](https://www.ruby-forum.com/t/bug-calling-visual-effect-within-helper/120511/1 "2007-11-17T18:58:09Z")

</div>

This post is slightly long, please bear up with me. The problem is  
little twisted.

I am quoting from the docs:-  
[http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html)

> > > > > > > > > >

Helper methods can be used in conjunction with JavaScriptGenerator. When  
a helper method is called inside an update block on the page object,  
that method will also have access to a page object.

Example:

module ApplicationHelper  
def update\_time  
page.replace\_html ‘time’, Time.now.to\_s(:db)  
page.visual\_effect :highlight, ‘time’  
end  
end

# Controller action

def poll  
render(:update) { |page| page.update\_time }  
end

> > > > > > > > > >

Below is my helper code:-

> > > > > > > > > >

module ContextsHelper  
def sort\_contexts  
page.sortable(‘context\_list’,  
:complete =\>visual\_effect(:highlight, ‘context\_list’),  
:url =\> { :action =\> “sort” },  
:handle=\>“drag\_handle”)  
end  
end

> > > > > > > > > >

Following is how I reuse it in my view:

\<%= update\_page\_tag() do |p| p.sort\_contexts end %\>

and in my controller as

def some\_action  
render :update do |page|  
…  
page.sort\_contexts  
end  
end

The problem is that the output of “sort\_contexts” helper is

new Effect.Highlight(“context\_list”,{});  
Sortable.create(“context\_list”, {handle:‘drag\_handle’,  
onUpdate:function(){new Ajax.Request(‘/contexts/sort’,  
{asynchronous:true, evalScripts:true, onComplete:function(request){new  
Effect.Highlight(“context\_list”,{});},  
parameters:Sortable.serialize(“context\_list”)})}});

See there is the extra Effect.Highlight as the first line. This is  
completely uncalled for.

Please help me solve this issue.
