开发者

Erb with Sinatra in ruby

So I have a webserver I've built using sinatra, the meat of which goes like this:

set :variable,"value"
get '/' do
  erb :index
end

And, of course, the template in views/index.erb which looks something like this:

<html>
<!-- etc -->
  <ul>
  <% my_array.each do |thing| %>
  <开发者_Go百科%="Something: #{thing}, variable from sinatra: #{settings.variable}"%>
  <% end %>
  </ul>
</html>

If you try running code like this you'll notice that you can't access sinatra's settings variable from inside erb templates. Any ideas how I can achieve this while keeping its simplicity?

Thanks in advance!


I was using an old version of Sinatra - updated to version 1.0 and it works fine :)

Thanks everyone!


I had a similar issue and the resolution was to make sure all the set :x, "y" stuff happened in the class declaration (of my subclass of Sinatra::Base) outside of the initialize method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜