# Override helper (observe\_field) and put JS at the bottom

**URL:** <https://www.ruby-forum.com/t/override-helper-observe-field-and-put-js-at-the-bottom/155913>\
**Category:** Rails\
**Created:** [December 18, 2008, 5:33am UTC](https://www.ruby-forum.com/t/override-helper-observe-field-and-put-js-at-the-bottom/155913 "2008-12-18T05:33:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![artchrst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@artchrst](https://www.ruby-forum.com/u/artchrst)\
**Post date:** [December 18, 2008, 5:33am UTC](https://www.ruby-forum.com/t/override-helper-observe-field-and-put-js-at-the-bottom/155913/1 "2008-12-18T05:33:28Z")

</div>

Is it possible to override a helper function and put its javascripts at  
the bottom (using yield)?

I tried the follows in helper:  
``

# override observe field to put js at the bottom

def observe\_field(field\_id, options = {})  
if @layout\_options  
content\_for :after\_js do  
super(field\_id, options )  
end  
else  
super  
end  
end

In view

`
<%=yield :after_js%>
`

But it seems not working.

---

<div class="post-metadata">

**Author:** ![artchrst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@artchrst](https://www.ruby-forum.com/u/artchrst)\
**Post date:** [December 18, 2008, 5:43am UTC](https://www.ruby-forum.com/t/override-helper-observe-field-and-put-js-at-the-bottom/155913/2 "2008-12-18T05:43:29Z")

</div>

Arthur C. wrote:

> Is it possible to override a helper function and put its javascripts at  
> the bottom (using yield)?
> 
> I tried the follows in helper:  
> ``
> 
> # override observe field to put js at the bottom
> 
> def observe\_field(field\_id, options = {})  
> if @layout\_options  
> content\_for :after\_js do  
> super(field\_id, options )  
> end  
> else  
> super  
> end  
> end
> 
> In view
> 
> `
> <%=yield :after_js%>
> `
> 
> But it seems not working.

Oops, I found the problem. I should not return anything when I put  
things into content\_for, so

`
  def observe_field(field_id, options = {})
    #super
    #return
    if @layout_options
      content_for :after_js_ready do
        super(field_id, options )
      end
      return "" # ******don't return immediate results****
    else
      super
    end
  end
`

Cool! I am getting A in yslow now 😃
