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

Not rendering rabl when using Rails 2.3.x #55

Closed
gammons opened this issue Jul 1, 2011 · 2 comments
Closed

Not rendering rabl when using Rails 2.3.x #55

gammons opened this issue Jul 1, 2011 · 2 comments

Comments

@gammons
Copy link

gammons commented Jul 1, 2011

Hi,

I'm unsure if this is an application-specific problem, or what, but with my app I'm trying to use rabl and running into a snag.

So i have the following controller:

class PeopleController < ApplicationController
  def show
    @person = Person.find(params[:id])  
    respond_to do |format|
      format.html
      format.json
    end
  end
end

My show.json.rabl file looks like this:

object @person
attribute :id

My app/views/layouts/application.rhtml file looks like this:

<html>
  <body>
    <%= yield :main if @content_for_main -%>
  </body>
</html>

Now, when I attempt to get /people/1.json, I do not see the json. I see html!

GET /people/1.json

<html>
  <body>
          </body>
</html>

The rails log looks like this:

Processing PeopleController#show to json (for 127.0.0.1 at 2011-07-01 11:03:00) [GET]
  Parameters: {"id"=>"1"}
  Person Columns (44.9ms)   SHOW FIELDS FROM `people`
  Person Load (0.7ms)   SELECT * FROM `people` WHERE (`people`.`id` = 1) 
Rendering template within layouts/application
Rendering people/show
  Lead Columns (14.4ms)   SHOW FIELDS FROM `people`
Completed in 173ms (View: 30, DB: 77) | 200 OK [http://localhost/people/1.json]

so it looks to me like rails is attempting to show json, but ends up rendering html. I'm confused.

If I explicitly tell the controller to not render a layout, then it shows the json no problem:

class PeopleController < ApplicationController
  def show
    @person = Person.find(params[:id])  
    respond_to do |format|
      format.html
      format.json { render :layout => false }
    end
  end
end

That works. Unfortunately I do not know rails views that well, otherwise I'd have submitted a patch with my issue. But can you guys think why my app is doing this?

Thanks in advance!

@nesquena
Copy link
Owner

nesquena commented Jul 1, 2011

Can you try changing your layout files name to application.html.erb ? Always best to include mimetypes. Should work the same and I think stop conflicting with RABL?

@gammons gammons closed this as completed Jul 1, 2011
@gammons
Copy link
Author

gammons commented Jul 1, 2011

Thanks for the quick response. That fixed it. Thank you!

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

2 participants