Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #4666 > unrolled thread

Re: Ruby/Sinatra - Variable inside erb calls

Started byEugen Ciur <ciur.eugen@gmail.com>
First post2011-05-17 06:34 -0500
Last post2011-05-17 14:16 -0500
Articles 2 — 2 participants

Back to article view | Back to comp.lang.ruby

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Ruby/Sinatra - Variable inside erb calls Eugen Ciur <ciur.eugen@gmail.com> - 2011-05-17 06:34 -0500
    Re: Ruby/Sinatra - Variable inside erb calls 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-17 14:16 -0500

#4666 — Re: Ruby/Sinatra - Variable inside erb calls

FromEugen Ciur <ciur.eugen@gmail.com>
Date2011-05-17 06:34 -0500
SubjectRe: Ruby/Sinatra - Variable inside erb calls
Message-ID<7011113ad9646a11b7fef0900f1ee153@ruby-forum.com>
You are on the right track:

:~> $ irb
ruby-1.9.2-p0 > :"hello"+'world'
NoMethodError: undefined method `+' for :hello:Symbol
        from (irb):1
        from /home/eugenc/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in
`<main>'
ruby-1.9.2-p0 > x = "hello"+'world'
 => "helloworld"
ruby-1.9.2-p0 > :x
 => :x
ruby-1.9.2-p0 >


In your case ruby converted :'templates/' to symbol, then tried to
concatenate string to it, this is because ':' has higher priority then
'+' operator. Solution is

 template_name  = 'templates/'+style+'/layout'
 erb template_name

(drop ':' operator, it is not necessary).


----
http://blog.eugen.co

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [next] | [standalone]


#4687

From7stud -- <bbxx789_05ss@yahoo.com>
Date2011-05-17 14:16 -0500
Message-ID<796f35470268b3a40b164d45fc480fce@ruby-forum.com>
In reply to#4666
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"

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.ruby


csiph-web