1

In my ruby on rails application I have controlled called AnimalsController. At this controller I have a method "edit" and a corresponded edit.html.erb view in my animals folder. When I also manually added some static javascript file into the page which are located at public/assets/js/ folder. When I render the view, instead of rails is trying to load these javascripts file in the relative path instead of mydomail.com/assets/js/ folder.

Url: /animals/:id/edit

I have script file myscript.js inside assets/js/

When I send request to htt://0.0.0.0:3000/animals/:id/edit

Rails search for http://0.0.0.0:3000/animals/:id/edit/assets/js/myscript.js

I want it to seach the script at http://0.0.0.0:3000/animals/js/myscript.js

This is code is in my edit.html.erb

<script src="assets/js/myscript.js"></script>

Not: I intentionally don't use <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

Any suggestions ?

Thanks.

0

2 Answers 2

1

It should be

<script src="/assets/js/myscript.js"></script>

Without the starting '/' it assumes the asset path is rooted on the page path. With the starting '/' it assumes the asset path is rooted at the domain.

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

Comments

1

If you use the rails helper, it will handle this for you.

 <%= javascript_include_tag 'myscript' %>

Just don't forget to add this file to the assets initializer config/initializers/assets.rb.

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.