Ruby/Sinatra - Variable inside erb calls

S

Scott Elwood

Hi there,

I have a question regarding variables inside of erb arguments. This is
what I would like to achieve:




require 'sinatra'

get '/' do
style = 'default'
erb :'templates/'+style+'/layout'
end




Running that will give you errors, saying there can't be a plus sign for
the concatenation.

Is there a way to work around this?
 
7

7stud --

Eugen Ciur wrote in post #999234:
(drop ':' operator, it is not necessary).

According to the Sinatra docs, it must be a symbol.

So I would just use string interpolation:

erb :"templates/#{style}/layout"
 
S

Scott Elwood

Thank you both for the help, it works perfectly and I now understand why
it wasn't working before :D

<3 this forum
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top