我有Sinatra
个应用,正在使用Padrino
。当我使用content_for
帮助器在布局中呈现内容时,它将其作为字符串而不是html返回。
app.rb
class CateringApp < Sinatra::Application
register Padrino::Helpers
end
layout.erb
<div id="page-wrapper">
<%= flash[:notice] %>
<%= content_for?(:main_table) ? yield_content(:main_table) : yield %>
</div>
category.erb
<% content_for :main_table do %>
<div id="name" class="row">
"IM ALIVE"
</div>
<% end %>
我在浏览器上获得的结果是文字字符串
<div id="name" class="row">
"IM ALIVE"
</div>
app.rb
require 'dotenv'
Dotenv.load
require 'sinatra'
require 'sinatra/activerecord'
require 'sinatra/reloader'
require 'sinatra/flash'
require 'sinatra/assetpack'
require 'padrino-helpers'
class CateringApp < Sinatra::Application
enable :protect_from_csrf
use Rack::Session::Cookie, :secret => ENV['SESSION_SECRET']
register Padrino::Helpers
register Sinatra::AssetPack
end
# require all config files
Dir["./config/*.rb"].each {|file| require file }
require './auth'
Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
activemodel (4.1.6)
activesupport (= 4.1.6)
builder (~> 3.1)
activerecord (4.1.6)
activemodel (= 4.1.6)
activesupport (= 4.1.6)
arel (~> 5.0.0)
activesupport (4.1.6)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
backports (3.6.0)
builder (3.2.2)
carrierwave (0.10.0)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
json (>= 1.7)
mime-types (>= 1.16)
dotenv (0.11.1)
dotenv-deployment (~> 0.0.2)
dotenv-deployment (0.0.2)
excon (0.39.6)
fog (1.23.0)
fog-brightbox
fog-core (~> 1.23)
fog-json
fog-softlayer
ipaddress (~> 0.5)
nokogiri (~> 1.5, >= 1.5.11)
fog-brightbox (0.5.1)
fog-core (~> 1.22)
fog-json
inflecto
fog-core (1.24.0)
builder
excon (~> 0.38)
formatador (~> 0.2)
mime-types
net-scp (~> 1.1)
net-ssh (>= 2.1.3)
fog-json (1.0.0)
multi_json (~> 1.0)
fog-softlayer (0.3.19)
fog-core
fog-json
formatador (0.2.5)
i18n (0.6.11)
inflecto (0.0.2)
ipaddress (0.8.0)
jsmin (1.0.1)
json (1.8.1)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.25.1)
mini_portile (0.6.0)
minitest (5.4.1)
multi_json (1.10.1)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (2.9.1)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
padrino-helpers (0.12.3)
i18n (~> 0.6, >= 0.6.7)
padrino-support (= 0.12.3)
tilt (~> 1.4.1)
padrino-support (0.12.3)
activesupport (>= 3.1)
pg (0.17.1)
polyglot (0.3.5)
pony (1.11)
mail (>= 2.0)
rack (1.5.2)
rack-protection (1.5.3)
rack
rack-test (0.6.2)
rack (>= 1.0)
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
sinatra-activerecord (2.0.2)
activerecord (>= 3.2)
sinatra (~> 1.0)
sinatra-assetpack (0.3.3)
jsmin
rack-test
sinatra
tilt (>= 1.3.0, < 2.0)
sinatra-contrib (1.4.2)
backports (>= 2.0)
multi_json
rack-protection
rack-test
sinatra (~> 1.4.0)
tilt (~> 1.3)
sinatra-flash (0.3.0)
sinatra (>= 1.0.0)
sinatra-reloader (1.0)
sinatra-contrib
thread_safe (0.3.4)
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (1.2.2)
thread_safe (~> 0.1)
PLATFORMS
ruby
DEPENDENCIES
activerecord
carrierwave
dotenv
fog
padrino-helpers
pg
pony
sinatra
sinatra-activerecord
sinatra-assetpack
sinatra-flash
sinatra-reloader
答案 0 :(得分:2)
在您的Gemfile中加入gem 'erubis'
。
Padrino ::渲染只有在相应的宝石(erubis,haml或slim)被包含在捆绑中并且在需要'padrino-helpers'时可见时才能被激活。