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

Empty { } for single object render to show #39

Closed
joel opened this issue Jun 9, 2011 · 3 comments
Closed

Empty { } for single object render to show #39

joel opened this issue Jun 9, 2011 · 3 comments
Labels

Comments

@joel
Copy link

joel commented Jun 9, 2011

For this example

class PostsController < ApplicationController
  def index
    @posts = Post.all
    respond_to do |format|
      format.json
    end
  end
  def show
    @post = Post.find(params[:id])
    respond_to do |format|
      format.json
    end
  end
end

With collection template index.json.rabl it's not necessary declare the collection

attributes :id, :title, :content

But in object template show.json.rabl the declaration it's necessary.

object @post
attributes :id, :title, :content

otherwise the { } it's empty

It's normal way ?

@nesquena
Copy link
Owner

nesquena commented Jun 9, 2011

Yes, you are right. The 'default' object detection is really basic, we could introspect the action and guess more at what the object would be.

Right now it only looks for an instance variable with the same name as the controller i.e 'posts'. I typically explicitly declare the object for clarity but I would be open to adding smarter defaults.

@fbernier
Copy link

+1. I might look into it eventually.

@nesquena
Copy link
Owner

Closing for now, use explicit collection declarations for the time being.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants