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

Using respond_with method ignores meta data #42

Closed
vlucas opened this issue Oct 27, 2011 · 3 comments
Closed

Using respond_with method ignores meta data #42

vlucas opened this issue Oct 27, 2011 · 3 comments
Assignees

Comments

@vlucas
Copy link

vlucas commented Oct 27, 2011

When using the respond_with rendering method, any data added with the :meta key is ignored:

respond_with(@events, :api_template => :public, :root => :results, :meta => api_collection_meta(@events))

Where the default respond_to block works as expected:

respond_to do |format|
  format.html # index.html.erb
  format.json { render_for_api :public, json: @events, :root => :results, :meta => api_collection_meta(@events) }
end
@ghost ghost assigned fabrik42 Nov 6, 2011
@fabrik42
Copy link
Owner

fabrik42 commented Nov 6, 2011

Hi,

sorry but I can not confirm this. We have specs that cover both kinds of controllers and I also tried to reproduce it manually, but everything seems to work fine.

This is the controller I tested:

class RespondWithUsersController < ApplicationController

  respond_to :json, :xml

  self.responder = ActsAsApi::Responder

  def index
    @users = User.where("").all
    meta_hash = { :page => 1, :total => 999 }
    respond_with @users, :api_template => :name_only, :root => :users, :meta => meta_hash    
  end

end

It produces:

{
    "page": 1,
    "total": 999,
    "users": [
        {
            "first_name": "Me"
        },
        {
            "first_name": "Me2"
        }
    ]
}

Can you provide a more specific example or even a rspec test, so I can reproduce the problem?

Best,

Chris :)

@fabrik42
Copy link
Owner

Is there anything left to say regarding this issue?
If not, I'm closing it for now...

@fduperier
Copy link

Hello,

I have exactly the same issue.
When trying to add meta using respond_with, nothing appears in the body response.
However, while using render_for_api, it works successfully...

Here is the code :
class ApiController < ApplicationController
self.responder = ActsAsApi::Responder
respond_to :json, :xml
end

class Api::V1::ProjectsController < ApiController
def update
if @project.update_attributes(params[:project])
meta = { :message => "L'histoire a bien ete mise a jour", :success => true }
respond_to do |format|
format.json { render_for_api :public, :json => @project, :meta => meta, :status => :created }
format.xml { render_for_api :public, :xml => @project, :meta => meta, :status => :created }
end
# respond_with(@project, :meta => meta, :api_template => :public, :status => :created)
end
end
end

Cheers

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

3 participants