0

I'm currently trying to get an example of the Chartkick gem to work in Ruby with Sinatra but I'm running into an issue. The example loads on my localhost but only shows "Loading..." and when I dug deeper I found this error in the console saying: "The resource from “http://localhost:4567/chartkick.js” was blocked due to MIME type mismatch (X-Content-Type-Options: nosniff)." Here is the example I'm trying to use:

require 'sinatra'
require 'chartkick'

get '/' do
  erb :index
end

__END__

@@ layout
<html>
<head>
  <script>
  var Chartkick = {"language": "es"};
  </script>
  <script src="http://www.google.com/jsapi"></script>
  <script src="chartkick.js"></script>
</head>
<body>
  <%= yield %>
</body>
</html>

@@ index
<%= timeline [
  ["Washington", "1789-04-29", "1797-03-03"],
  ["Adams", "1797-03-03", "1801-03-03"],
  ["Jefferson", "1801-03-03", "1809-03-03"]
] %>]

I have tried setting the content type to various MIME combinations but it doesn't seem to work. I feel like I'm missing something that could be in the configuration for Sinatra or a small line of code for my browser to refuse loading that resource.

Advert
  • 3
  • 1
  • 3
  • Where is your chartkick file stored? Is it in your public folder. By searching, I found that error mostly attributes to path mismatch. Here is another reference on how to use chartkick with Sinatra - https://stackoverflow.com/q/23238671/2096740 – arjun Feb 02 '18 at 19:26
  • I think @arjun is correct, [this answer to a similar question](https://stackoverflow.com/a/41319855/335847) seems to suggest your js file is not found in the public directory. Also, you should really list script files using an absolute path, ``. Note the leading slash. – ian Feb 11 '18 at 19:36

0 Answers0