0

I searched a lot but I can't seem to find a clear answer about how to execute javascript code via Sinatra, it symply renders the code as html for me. Here is what I tried so far :

require 'sinatra'
set :public_folder, 'public'
class Dashboard < Sinatra::Base
 get '/' do
 send_file File.join(settings.public_folder, 'javascripts/index.js') # renders code as html
 '<script type="text/javascript" src="index.js"></script>' # nothing
 '<script>alert("Hello, world !")</script>' # works correctly
 end
end
asked Apr 1, 2015 at 14:08
2
  • render js: '<script type="text/javacript" >alert("q");</script>' try pls Commented Apr 1, 2015 at 14:12
  • "wrong number of arguments (1 for 2..4)", also just '<script>alert("hello")</script>' is working, but I'm really trying to load a script from a file here Commented Apr 1, 2015 at 14:18

1 Answer 1

1

Figured it out, the path in src must be so :

<script type="text/javascript" src="javascripts/index.js"></script>
answered Apr 1, 2015 at 15:19
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.