Automatically load javascript function after page load

I am new to Rails and still don't understand the resource container ...

I want a

views/product/product.js 

starts automatically after

views/product/index.html.erb 

was displayed for DRY reasons.

Is there a place in the asset pipeline that calls the model.js file after loading any or partial model.erb file?

I know how to do it manually, and dumped

app/assets/javascripts/product.js

but then I have to call the doSomethingAfterPageload () method in a new, show. delete etc. Even better if it works for partial ones.

+3
source share
3 answers

- ( ), js, (application.js), , , . , ( ), js script , .

, yield :javascript , javascript content_for :javascript do.

JavaScript javascript Rails 3?

js . : http://viget.com/inspire/extending-paul-irishs-comprehensive-dom-ready-execution

+2

IMO, js , .

0

Taken from here: Asset Pipeline - Rails guide

If you add app/assets/javascripts/<controller>.js, it will be available for this particular controller.

So, if you add in app/assets/javascripts/product.js:

$(document).ready ->
  alert "page has loaded!"

It will be executed in all representations of this controller, for example, indexor edit.

Hope this helps :)

0
source

All Articles