Erb with Sinatra in ruby

Posted by JP on Stack Overflow See other posts from Stack Overflow or by JP
Published on 2010-04-02T17:56:20Z Indexed on 2010/04/02 18:53 UTC
Read the original article Hit count: 591

Filed under:
|
|

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| %>
  <%="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!

© Stack Overflow or respective owner

Related posts about sinatra

Related posts about ruby