0

I have created a new ruby on rails project using the command : rails new [project_name].

Further, I want to create javascript files, so I can control my view elements. For this, I've created a new js file and placed it in the app->assets->javascripts->apple_pay.js

Currently the appe_pay.js implementation is just for testing :

console.log("test")

Also, my application.js, used like a manifest file, looks like this :

//= require_tree .

When I run the project using rails server command, I'm expecting to see the message displayed on the console, but it's not, any ideea ?

2
  • Anything in your JS console in browser? Commented Sep 11, 2019 at 11:29
  • nothing, I think I am missing something, or just I dont understand how things are working using rails, I am a beginner. Commented Sep 11, 2019 at 11:32

2 Answers 2

3

find: config/initializers/assets.rb Then: Rails.application.config.assets.precompile += %w[your_file.js]

noticing that as it's out of application.js you need to include it inside your views using:

javascript_include_tag :your_file

Save & Restart your server :)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot, your answer helped me to find the solution in my case: I had to add : <%= javascript_include_tag 'application' %> in my .erb file, because in the application.js i was requiring the whole tree.
Great to know that, I wrote the javascript_include_tag based on HAML not html.erb sorry for that but I'm happy that your issue was solved.
-2

If you are not install "jquery-rails" then first install the gem and require file also add in application.js

//= require file_name

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.