Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

tolsen opened this issue Mar 1, 2012 · 10 comments

Comments

@tolsen
Copy link

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
Copy link

carhartl commented Mar 3, 2012

This seems related: rails/rails@19433ce

@carhartl
Copy link

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
Copy link

cmer commented Mar 6, 2012

+1

@databyte
Copy link
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!

@nesquena
Copy link
Owner

Also, I added your comments to https://github.com/nesquena/rabl/wiki/RABL-and-Rails-3.2 thanks @carhartl

@databyte
Copy link
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.

@mmarqueti
Copy link

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
Copy link
Collaborator

What the code you're rending with?

@dhirajbajaj
Copy link

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
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants