Suraj Shukla
Suraj Shukla

Reputation: 187

Add js scripts in the application.html.erb

I am new to rails, I know that we add our css and js files in application.html.erb file.

But do we also add the js scripts in the same file?

For example this script below

   <script>
    $(function () {
      $("#slider").responsiveSlides({
        auto: true,
        speed: 500,
        namespace: "callbacks",
        pager: true,
      });
    });
  </script>

Upvotes: 2

Views: 6828

Answers (2)

user8259107
user8259107

Reputation:

You can add any scripts in application.html.erb, but i think will be better to require application.js in application.html.erb with javascript_include_tag:

<%= javascript_include_tag "application" %>

and include any scripts from javascript folder in application.js

//= require library_name

Upvotes: 2

puneet18
puneet18

Reputation: 4427

you can create a custom js file in /assets/javascripts folder and write all your js code and it will load in your page also.

Upvotes: 0

Related Questions