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
Kernael
3,2904 gold badges25 silver badges43 bronze badges
-
render js: '<script type="text/javacript" >alert("q");</script>' try plsLegendary– Legendary2015年04月01日 14:12:02 +00:00Commented 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 hereKernael– Kernael2015年04月01日 14:18:01 +00:00Commented Apr 1, 2015 at 14:18
1 Answer 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
Kernael
3,2904 gold badges25 silver badges43 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Explore related questions
See similar questions with these tags.
default