我建立一个版本的API,所以我有以下嵌套控制器:的Rails 3 respond_with,路由约束和资源
ApiController < ApplicationController
Api::V1Controller < ApiController
Api::V1::EventsController < Api::V1Controller
的API通过子域访问。我有以下路线:
constraints(:subdomain => "api") do
scope :module => 'api' do
namespace :v1 do
resources :events
end
end
end
这产生了我想要的URL类型(/ v1/events)。
我面临的问题是在Api::V1::EventsController
中使用responds_with
时。只是这样做的以下简单的东西失败,错误too few arguments
:
def index
@events = Event.all
respond_with(@events)
end
我知道respond_with
是为了与资源使用,但我不知道怎么的事件资源应该从约束,范围的访问和名称空间路由。我可以输出其他东西(如current_user),而不是一系列事件。帮帮我?
更新:
这里是什么工作:
# a single resource
def index
@event = Event.all.first
respond_with @event
end
# an array of a completely different resource
def index
@user = User.all
respond_with @user
end
因此,也许它是与事件模型,专门收集与阵列。我会继续调查。
同样的事情对我来说,和我使用mongoid了。 – 2011-07-04 01:54:06