# Best way of moving some jQuery from a view helper

**URL:** <https://www.ruby-forum.com/t/best-way-of-moving-some-jquery-from-a-view-helper/174258>\
**Category:** Rails\
**Created:** [August 23, 2009, 8:40pm UTC](https://www.ruby-forum.com/t/best-way-of-moving-some-jquery-from-a-view-helper/174258 "2009-08-23T20:40:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [August 23, 2009, 8:40pm UTC](https://www.ruby-forum.com/t/best-way-of-moving-some-jquery-from-a-view-helper/174258/1 "2009-08-23T20:40:15Z")

</div>

I have a helper that uses some jQuery code that I would like to move out  
of the helper method.  
I am trying to move it to application.js but it will probably end up in  
a different file.  
I have two reasons for wanting to do this.

1. I want to keep all my jQuery code seperate to my HTML code
2. I want to change the append to an appendTo so I can add a highlight  
effect, appendTo which is proving awkward to achieve in the helper.

```auto
  def link_to_create_address(form_builder)
    link_to_function 'New address', {:id => 'new_address_link'} do
|page|
      form_builder.fields_for :addresses, Address.new, :child_index =>
'NEW_RECORD' do |faddress|
        html = render(:partial => 'address_container',
                                :locals => { :faddress => faddress,
                                :uid => 'NEW_RECORD',
                                :show_edit_form => true })
        page <<
"jQuery('#address_list').prepend('#{escape_javascript(html)}'.replace(/NEW_RECORD/g,
new Date().getTime())).effect('highlight', {}, 300)"
      end
    end
  end
```

So basically I want to move the line

```auto
  "jQuery('#address_list').prepend('#{escape_javascript(html)}'.replace(/NEW_RECORD/g,
new Date().getTime())).effect('highlight', {}, 300)"
```

into a more suitable location.
