3

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>
4
  • did you add and check? what is the issue? Commented Jul 5, 2017 at 11:17
  • didn't add and check... Commented Jul 5, 2017 at 11:19
  • why you need to add them , you just need to add them in there respective js file Commented Jul 5, 2017 at 11:20
  • @SurajShukla Can you please tell me how did you call that function in erb file? Commented Apr 27, 2022 at 12:45

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.