Reputation: 448
I understand that controller is process and calculate data and pass to view.
But what is the usage of java script in ruby on rails project?
I'm trying to follow this link to deal with my google map app but really have no idea where to put those script and how to make it function.It's like Im holding the key but dont know the way to the door.
Upvotes: 1
Views: 128
Reputation: 9173
But what is the usage of java script in ruby on rails project?
Javascript in rails does the same thing what javascript does in general i.e to manipulate the DOM (change HTML contents)
have no idea where to put those script and how to make it function
You need to put your javascript in assets/javascript folder. If you look at your layout file(assuming application.html.erb), you'll see you have
<%= javascript_include_tag "application" %>
Which basically loads all your javascript from app/assets/javascript/application.js so you can either write your js inside that file or you can make a new js file( will recommend you to make a new one) and require that file inside application.js by
//= require file_name
or if you have //= require_tree .
in your application.js then it'll automatically require all files from app/assets/javascript. For more details you should check Rails Asset Pipeline
Upvotes: 0
Reputation: 7366
Have you added this gem in your gem file ? https://github.com/apneadiving/Google-Maps-for-Rails.
If yes then you can add html in your view file. and js in specific controller related js file. (assets/javascript/mycontroller.js) or in application.js file . All other changes clearly mentioned on gem read me.
Upvotes: 1
Reputation: 3323
First of the controller has nothing to do with the JavaScript. JavaScript is used to get interactivity into a static website. For example you want to show a something inside a div-tag if you click on a button. JavaScript is your way to go. This is the usage of JavaScript in your rails project.
In your rails application you have a folder app/assets/javascript. Inside this folder you create a new file called "googlemaps.js.coffee" and insert the code from the google maps side into it. Your application.js file takes care that all your other JavaScript files are included in your application.
Upvotes: 1