You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 ?
The text was updated successfully, but these errors were encountered:
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.
For this example
With collection template index.json.rabl it's not necessary declare the collection
But in object template show.json.rabl the declaration it's necessary.
otherwise the { } it's empty
It's normal way ?
The text was updated successfully, but these errors were encountered: