Sinatra and Chartkick Example

◇◆丶佛笑我妖孽 提交于 2019-12-05 18:19:37

This is the section of the docs you need to finish this example. If you don't want to make the views separate files, then either use inline templates, e.g.

get '/' do
  erb :index
end

__END__

@@ layout
<html><body>
  <%= yield %>
</html></body>

@@ index
<%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>
<%= pie_chart({"Football" => 10, "Basketball" => 5}) %>

or named templates:

template :layout do
  <<LAYOUT
<html><body>
  <%= yield %>
</html></body>
LAYOUT
end

template :index do
  <<INDEX
    <%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>
    <%= pie_chart({"Football" => 10, "Basketball" => 5}) %>
INDEX
end

get '/' do
  erb :index
end

I've used heredocs for convenience here, just be careful of the formatting.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!