Rails 3 respond_with, route constraints and resources

Posted by Intelekshual on Stack Overflow See other posts from Stack Overflow or by Intelekshual
Published on 2011-03-11T04:53:36Z Indexed on 2011/03/11 8:10 UTC
Read the original article Hit count: 171

I'm building a versioned API, so I have the following nested controllers:

  • ApiController < ApplicationController
  • Api::V1Controller < ApiController
  • Api::V1::EventsController < Api::V1Controller

The API is accessed via a subdomain. I have the following routes:

  constraints(:subdomain => "api") do
    scope :module => 'api' do
      namespace :v1 do
        resources :events
      end
    end
  end

This produces the type of URL I want (/v1/events).

The problem I'm facing is when using responds_with in Api::V1::EventsController. Just doing something as simple as the below fails with the error too few arguments:

def index
    @events = Event.all
    respond_with(@events)
end

I know respond_width is meant to be used with resources, but I'm not sure how the events resource should be accessed from the constrained, scoped, and namespaced route. I can output other things (such as current_user), just not an array of events. Help?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby-on-rails-3