我正在尝试 Rabl,但是,我似乎收到了一个几乎空的 json 块。
require_dependency "api/application_controller"
module Api
class RentablePropertiesController < ApplicationController
respond_to :json
def index
@r = Core::RentableProperty.all
# render :text => @r.to_json --> note: this renders the json correctly
render "api/rentable_properties/index" #note: rabl here does not
end
end
end
index.json.rabl
collection @r
输出
[{"rentable_property":{}}]
注意:使用简单的@r.to_json,它可以正确呈现:
[{"id":1,"description":"description","property_type_id":1,"created_at":"2013-08-22T19:04:35.000Z","updated_at":"2013-08-22T19:04:35.000Z","title":"Some Title","rooms":null,"amount":2000.0,"tenure":null}]
知道为什么 rabl 不起作用吗?