How to pass an instance variable to a erb template in a Sinatra route?

96 Views Asked by At

How do I pass an instance variable to an erb template in a Sinatra route. The below doesn't work.

   get '/' do
    
       @beercompany = "Coors"
       erb :mytemplate
    end 

mytemplate.erb

<h1> Hello from <% @beercompany %></h1>

output doesn't show beercompany's name

Hello from 
1

There are 1 best solutions below

0
darkinSyde On BEST ANSWER

You need to put = to display the variable:

<h1> Hello from <%= @beercompany %></h1>