我试图让我的页面 Controller 的“显示”操作呈现 Liquid 模板而不是普通 View 。模板本身存储在数据库中。
这是我的表演 Action :
def show
@organization = Organization.find_by_subdomain(request.subdomain)
@template = Liquid::Template.parse(Template.find(@organization.current_template))
@page = @organization.pages.find(params[:id])
respond_to do |format|
format.html { render @template.render('page' => @page)}
format.json { render json: @page }
end
end
但是,它引发了这个异常:
uninitialized constant PagesController::Liquid
我是 RoR 新手,所以我假设发生的情况是它试图在 PagesController 类中找到 Liquid 类,而不是意识到它本身就是一个类。我正在遵循(有点稀疏)说明 here尽我所能。
我做错了什么?
最佳答案
您需要在 Gemfile 中包含液体:
gem "liquid"
然后运行bundle install
并重新启动Rails服务器。
关于ruby-on-rails - 在 Controller 中渲染液体模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11712654/