0

I am new in Rails 3.2. I do not know how I can use javascript with Rails 3.2. There are assets file in it and in assets file there is a file is called javascript. However, in this file, document names are controller_name.js.coffee. Thus, I need to help. How can I manage my javascript+jQuery code?

Thanks.

Trevor Burnham
  • 76,828
  • 33
  • 160
  • 196
eayurt
  • 1,169
  • 1
  • 19
  • 42

1 Answers1

2

In an out-of-the-box Rails 3.1+ app, the application.js.coffee file brings in all the other .js and .js.coffee files with the

# require_tree .

Sprockets directive. In development mode, this serves all of your JS files separately. In production, it concatenates them.

If you want to use JavaScript instead of CoffeeScript, simply replace the .js.coffee extensions with .js. (Don't forget to replace the #-style comments with //-style ones.)

I hope that gives you enough information to get started. For more information, consult the official guide: http://guides.rubyonrails.org/asset_pipeline.html

Trevor Burnham
  • 76,828
  • 33
  • 160
  • 196
  • so, can i use JS like Rails 3.0 usage because i don not want to struggle with assets pipeline. – eayurt Apr 24 '12 at 06:12
  • 2
    You could, but you wouldn't want to. The asset pipeline makes it extremely easy to do things like minification that previously required either manual effort or additional plugins. You can change the default extension from `.js.coffee` to `.js` by removing the CoffeeScript gem; see http://stackoverflow.com/a/6113524/66226 – Trevor Burnham Apr 24 '12 at 15:38