Inline RJS in controller

Inline RJS and Controller

Hi guys,

I really like the idea about inline RJS.
I have about 20 rjs files for this 1 controller.
They are small. Just updating and hiding some div’s.
So to move this into my controller would clean up a lot.
It makes sense because you see in the controller what you do.


  1. Any penalties for doing this?
  • size of controller increases
  • performance issues
  • moving view actions into controller

Thanks in advance and happy coding.



You can keep the inline RJS in the controller clean by creating RJS
helper methods, which allow you to aggregate common functionality
together in one method call.

For example:

def create
@product = Product.create(params[:product])
render :update do |page|
page.insert_html :bottom, ‘products’, :partial => ‘product’
page.visual_effect :highlight, “product-#{}”

You could move this to a helper method in the helper module for the

def insert_product(product)
page.insert_html :bottom, ‘products’, :partial => ‘product’, :object
=> product
page.visual_effect :highlight, “product-#{}”

And you end up with:

def create
product = Product.create(params[:product])
render(:update){|page| page.insert_product(product)}

Refactoring out all common functionality like this should allow you
have many small, one-line, inline RJS calls.

I don’t see why you’d run into any performance problems, but I’d be
weary of your helper and inline RJS code getting too complex. You can
always move the code back to its own RJS template if your controller
code starts getting too bloated.

On 4/1/06, John [email protected] wrote:

Posted via

Rails mailing list
[email protected]

Cody F.

Hi Cody,

I see what you mean.
I was also thinking about avoiding duplicate code.
And you showed me how.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs