Skip to content
This repository

rabl may be interfering with finding html templates (Rails 3.2.2) #180

tolsen opened this Issue March 01, 2012 · 10 comments

8 participants

Tim Olsen Nathan Esquenazi Klaus Hartl Carl Mercier David Sommers Marcelo Marqueti Dhiraj Bajaj Jodi Showers
Tim Olsen

Rails 3.2.2 appears to have made things worse. While trying to render an html page, Rails seems to be insisting on trying to find a json template:

Template is missing

Missing template quarks/index with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder, :coffee, :haml, :rabl]}. Searched in: * "/Users/tim/git/surround-release2/app/views" * "/Users/tim/.rvm/gems/ruby-1.9.3-p0/gems/devise-2.0.4/app/views" 

The controller action has a respond_to block with format.html and format.json defined.

The problem goes away if I remove rabl so I suspect some weird rabl interaction with regard to registering. Also, this problem did not happen in Rails 3.2.1.

Klaus Hartl

This seems related: rails/rails@19433ce

Klaus Hartl

In my case I found out that when using render template using rabl within another (html) layout, like for instance:

<%= render(template: 'users/current_user', formats: [:json], handlers: [:rabl]).html_safe %>

any following call to render insists on json, so I had to make the format explicit again there:

<%= render(partial: 'foo/bar', formats: [:html]) %> 

Maybe this is just the way it works in Rails now...

Carl Mercier
cmer commented March 05, 2012


David Sommers

I had a bitch of a time finding all the other renderings in my massive list of partials (client-side heavy, lots of template partials).

So I added this to my helpers:

def with_format(format, &block)
  old_formats = formats
  self.formats = [format]
  result =
  self.formats = old_formats
  • partially compiled from reading this and this.

Then I had a file like show.html.erb render this:

<%= render partial: "foo/bar", formats: :js, locals: { baz: baz } %>

Which then switches formats to JSON which bombs without the helper:

var test = <%= with_format(:json) { render(template: 'v1/recipes/show', formats: :json).html_safe } %>;

So the formats goes from :html to :json, renders out the RABL, and then back to :html

The formats: :json halts deprecation warnings.

GOOD NEWS :clap::clap::clap: ... There is a fix in 3.2 stable (unreleased):
commit with tests!

Nathan Esquenazi
Nathan Esquenazi nesquena closed this March 22, 2012
David Sommers

FYI, Rails 3.2.3 does include the fix and you won't get template not found errors anymore even if the output format is different.

Marcelo Marqueti

I still see this issue with rails 3.2.3 and ruby 1.9.3, but only with index page

Don't work


MissingTemplate (Missing template api/projects/index, application/index with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder, :coffee, :rabl]}


David Sommers

What the code you're rending with?

Dhiraj Bajaj

I too having this issue:

respond_to do |format|
  format.html do
    render :template => "main/index"
  format.json do
    render :status => 200 , :json => {:success => true, :explore =>  'some-data' }

When i hit explore.json
It gives me...

Template is missing

Missing template main/index with {:handlers=>[:erb, :builder, :coffee, :rabl, :haml], :formats=>[:json], :locale=>[:en, :en]}. Searched in: * "D:/app/app/views" * "C:/Ruby/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views" * "C:/Ruby/lib/ruby/gems/1.9.1/bundler/gems/rails_admin_tag_list-ca103dbca58e/app/views" * "C:/Ruby/lib/ruby/gems/1.9.1/bundler/gems/rails_admin-3684bd706770/app/views" * "C:/Ruby/lib/ruby/gems/1.9.1/gems/kaminari-0.14.1/app/views"

RABL is interfering in default handlers

Jodi Showers

I'm seeing this issue with rabl-0.8.5, rails 3.2.13 and ruby 1.9.3p194

must force format to :json, default format not working with :index method (other's are good)

GET /companies - template not found
GET /companies.json - template found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.