1

I'm trying to load an image in the javascript on a rails app,

The javascript works in the application, just the tab image does not load and believe its probably a image path issue, The image is in the images folder.

$(function(){
         $('.divslide').SlideOut({
             Handle: '.handle',  
             pathToTabImage: 'images/menu.png', 
             ...

I have tried changing the paths with no luck, Any help would be great, thanks.

1
  • It would be very nice of you to accept the best answer, cause it's quite messy to look through all of them. Commented Mar 22, 2018 at 11:00

4 Answers 4

3

Firstly make sure that you have .erb extanstion on your .js file, like

main.js -> main.js.erb

And now you can use the asset_path() helper:

$(function(){
     $('.divslide').SlideOut({
        Handle: '.handle',  
        pathToTabImage: '<%= asset_path("images/menu.png") %>', 
        ...

Where the image must be in app/assets/images folder.

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

Comments

0

Changed path and got it working

$(function(){
     $('.divslide').SlideOut({
         Handle: '.handle',  
         pathToTabImage: 'images/menu.png', 
         ...

to

$(function(){
     $('.divslide').SlideOut({
         Handle: '.handle',  
         pathToTabImage: 'assets/menu.png', 
         ...

Comments

0

I think if it is in the images folder than it should be

pathToTabImage: 'assets/images/menu.png',  

Comments

0

The correct path should be /assets/menu.png

1 Comment

Thank you, Same thing popped into my head after asking and it worked.

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.