NameError in using custom layout option in sinatra

2019-08-03 13:20发布

问题:

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?

回答1:

Rename your layout to nosetup_layout (using an underscore).

Then just call:

haml :nosetup, {:layout => :nosetup_layout}