ruby-on-rails - 在 Controller 中渲染液体模板

标签 ruby-on-rails ruby-on-rails-3 template-engine templating liquid

我试图让我的页面 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/

相关文章:

ruby-on-rails - has_one关联的嵌套属性

java - 速度和 $foreach.count

c# - ASP.NET MVC 在运行时查看可扩展性

ruby-on-rails - AWS : S3 Bucket AWS You can't grant public access because Block public access settings are turned on for this account

mysql - 未知列 mysql where 子句 - 但我可以在我的应用程序中访问和设置它。是什么原因造成的?

ruby-on-rails - Heroku 推送错误

ruby-on-rails - 在 Rails 3 中处理 Multi-Tenancy 的最佳方式

ruby-on-rails - rails : Filter has_many relationship by another Foreign Key

jQuery tokeninput 跨多个字段搜索

go - 在Golang web应用开发中,是否可以将Go的模板与jade(pug)模板引擎一起使用?