Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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).

like image 663
Asherlc Avatar asked Jun 27 '26 10:06

Asherlc


1 Answers

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
like image 58
iblue Avatar answered Jun 29 '26 05:06

iblue



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!