1

To use custom layout file in my app I'm using this following code,

set :views, File.dirname(__FILE__) + "/../views"
set :public_folder, File.dirname(__FILE__) + "/../public"
get '/' do
if !Db.empty? then
haml :home, {:layout => :nosetup-layout}
elsif request.ip == "127.0.0.1" then

haml :setup, {:layout => :nosetup-layout}

else
haml :nosetup, {:layout => :nosetup-layout}
end
end 

there seems to be a problem with the layout option

I get the following error

undefined local variable or method `layout' for #<TabPlayer::Server:0x000000024509c8>

So, where did I went wrong?

pahnin
  • 5,367
  • 12
  • 40
  • 57

1 Answers1

1

Rename your layout to nosetup_layout (using an underscore).

Then just call:

haml :nosetup, {:layout => :nosetup_layout}
carpamon
  • 6,515
  • 3
  • 38
  • 51
  • It worked, thanks, but what is this stupid convention!! Its because of ` - ` or same name should be there for haml and layout? – pahnin Jun 25 '12 at 17:26
  • I can also have `:"nosetup-layout"` see http://stackoverflow.com/questions/4190297/how-to-make-a-layout-template-in-sinatra – pahnin Jun 25 '12 at 18:16
  • It is because you can't use - in the name of a ruby symbol. Open the ruby console and try to evaulate { :this => :wont-work }. – carpamon Jun 25 '12 at 20:42