Use javascript in rails 3.2 without coffeescript

I am using Rails 3.2, it is configured for coffeescript. I know that Coffeescript is a terrific language and not so difficult to learn, but I'm just starting to hug Javascript and jQuery. So my question is this: is there an easy way to install rails 3.2 to use Javascript instead? At the moment, my jQuery is in tags <script></script>in my view (timeline / index.html.erb). I would like to move it to a .js file. I tried changing the name of my timeline.js.coffee only to timeline.js and put jQuery there, but I get Uncaught SyntaxError: Unexpected token ILLEGAL.

What should I do besides the obvious answer "learn coffeescript"?

+5
source share
4 answers

I was on the right track. To switch to javascript in rails 3.2, you only need to remove the extension .coffee. However, you also need to make sure that you use //for comments instead#

//# Place all the behaviors and hooks related to the matching controller here.
//# All this logic will automatically be available in application.js.
//# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
+6
source

The manifest of files and directives
http://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives

add js files to app / assets / javascripts, then add files to application.js


your js file

alert("here");

application.js

//= require_tree .
or
//= require your_js_file_name

then it will be selected from the code below in your app/views/layouts/application.html.erb

<%= javascript_include_tag "application" %>
0
source
$ rails -v
Rails 3.2.11

?
http://bit.ly/VHEnBX

git clone it
cd js_test
bundle
rails s -d
open http://localhost:3000

# stop the detached server 
kill -9 `cat tmp/pids/server.pid`

here .

js. .coffee . http://bit.ly/UPe2mp

0

gem 'coffee-rails' Gemfile

0

All Articles