Good practice to include javascript functions in view?

Hello,

I was just wondering if it was good pratice to have a load of javascript
functions in a view file, or whether these javascript functions should
be put in a javascript file and loaded in.

Thanks for your time.

On Thu, Mar 01, 2007 at 03:39:22PM +0100, James S. wrote:

I was just wondering if it was good pratice to have a load of javascript
functions in a view file, or whether these javascript functions should
be put in a javascript file and loaded in.

Static assets should be served as static assets. It makes sense to have
a
script tag (e.g. javascript_tag) in your views, and maybe an occasional
and
very small script tag with inline code that uses functions/objects in
your
static JS files. If you find yourself writing more than three or so
lines
of JS in a view, you should probably pull it out into a static JS file.

Thanks for your time.
–Greg

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