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

Closed
tolsen opened this Issue Mar 1, 2012 · 10 comments

Comments

Projects
None yet
8 participants
@tolsen

tolsen commented Mar 1, 2012

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.

@carhartl

This comment has been minimized.

Show comment
Hide comment

carhartl commented Mar 3, 2012

This seems related: rails/rails@19433ce

@carhartl

This comment has been minimized.

Show comment
Hide comment
@carhartl

carhartl Mar 3, 2012

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

carhartl commented Mar 3, 2012

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

@cmer

This comment has been minimized.

Show comment
Hide comment

cmer commented Mar 6, 2012

+1

@databyte

This comment has been minimized.

Show comment
Hide comment
@databyte

databyte Mar 22, 2012

Collaborator

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 = block.call
  self.formats = old_formats
  result
end
  • 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 👏 👏 👏 ... There is a fix in 3.2 stable (unreleased):
rails/rails#5440
commit with tests!

Collaborator

databyte commented Mar 22, 2012

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 = block.call
  self.formats = old_formats
  result
end
  • 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 👏 👏 👏 ... There is a fix in 3.2 stable (unreleased):
rails/rails#5440
commit with tests!

@nesquena

This comment has been minimized.

Show comment
Hide comment
Owner

nesquena commented Mar 23, 2012

@nesquena nesquena closed this Mar 23, 2012

@databyte

This comment has been minimized.

Show comment
Hide comment
@databyte

databyte Mar 27, 2012

Collaborator

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.

Collaborator

databyte commented Mar 27, 2012

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.

@mmarqueti

This comment has been minimized.

Show comment
Hide comment
@mmarqueti

mmarqueti May 16, 2012

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

Example:
Don't work
http://localhost:3000/api/projects.json

Error:

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

Works!
http://localhost:3000/api/projects/1.json

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

Example:
Don't work
http://localhost:3000/api/projects.json

Error:

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

Works!
http://localhost:3000/api/projects/1.json

@databyte

This comment has been minimized.

Show comment
Hide comment
@databyte

databyte May 16, 2012

Collaborator

What the code you're rending with?

Collaborator

databyte commented May 16, 2012

What the code you're rending with?

@dhirajbajaj

This comment has been minimized.

Show comment
Hide comment
@dhirajbajaj

dhirajbajaj Feb 25, 2013

I too having this issue:

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

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

I too having this issue:

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

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

@jshow

This comment has been minimized.

Show comment
Hide comment
@jshow

jshow Aug 19, 2013

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

jshow commented Aug 19, 2013

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