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


Groups > comp.lang.ruby > #4666

Re: Ruby/Sinatra - Variable inside erb calls

From Eugen Ciur <ciur.eugen@gmail.com>
Newsgroups comp.lang.ruby
Subject Re: Ruby/Sinatra - Variable inside erb calls
Date 2011-05-17 06:34 -0500
Organization Service de news de lacave.net
Message-ID <7011113ad9646a11b7fef0900f1ee153@ruby-forum.com> (permalink)
References <69d0c8c5a3b8782605829508018eef60@ruby-forum.com>

Show all headers | View raw


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/.

Back to comp.lang.ruby | Previous | NextNext in thread | Find similar | Unroll thread


Thread

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

csiph-web