Asherlc
Asherlc

Reputation: 1161

"Template is missing" when rendering Liquid template

I'm trying to render a liquid template that is stored in the database.

Here is my 'show' action in the controller:

  def show
    @organization = Organization.find_by_subdomain(request.subdomain)
    @template = Liquid::Template.parse(Template.find(@organization.current_template).body)
    @page = @organization.pages.find(params[:id])

    respond_to do |format|
      format.html { render @template.render('page' => @page), :template => false}
      format.json { render json: @page }
    end
  end

However, when I visit the page, I get a "Template is Missing" exception with the following error (note that "testing testing" is the body attribute of the page object, which is currently the only thing being rendered in the template):

Missing template /testing testing with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :haml]}.
Searched in: * "/Users/ashercohen/Documents/Rails/Vocalem-Rails/app/views" 
* "/Users/ashercohen/.rvm/gems/ruby-1.9.3-p194/gems/twitter-bootstrap-rails-2.1.1/app/views"
* "/Users/ashercohen/.rvm/gems/ruby-1.9.3-p194/gems/devise-2.1.2/app/views"

Why is it trying to find another template, when I've specifically pass the :template => false argument? Is there something I'm missing here? I'm trying to bypass using any template files, as it seems like they shouldn't be needed here (though am not strongly opposed if I am wrong).

Upvotes: 3

Views: 751

Answers (1)

iblue
iblue

Reputation: 30424

Because render almost always takes a filename, while @template.render('page' => @page) contains the plain html. You should invoke render like this:

render :text => @template.render('page' => @page), :content_type => :html

Upvotes: 4

Related Questions