我有一个Sinatra应用程序。一切都很好,但是当我添加这段代码时:
!= yield_content :css
直接转到主视图(模板)或"shared/_head"
!!!5
%html{lang: :en}
!= haml :"shared/_head"
!= yield_content :css
%body{'data-spy' => "scroll", 'data-target' => ".subnav", 'data-offset '=> "50"}
!= haml :"shared/_header"
.container-fluid
!= haml :"shared/_flash"
!= yield
%hr
!= haml :"shared/_footer"
错误抛出:
undefined method `yield_content' for #<App:0x00000004267ce0>
为什么?
答案 0 :(得分:3)
根据https://github.com/sinatra/sinatra-contrib#modular-style,您只需安装gem,然后将content_for扩展名包含在您的应用程序文件中。如下所示:
require 'sinatra'
require 'sinatra/content_for'
class App < Sinatra::Base
helpers Sinatra::ContentFor
get '/' do
erb :index
end
end
刚检查过,它对我有用