0

我有这样的 index.rabl:

collection @exchangers, :root => "bank", :object_root => false

extends "exchanger_lists/show"

和这样的show.rabl:

object @exchanger
attributes :id, :name, :address, :location_id, :latitude, :longitude, :exchanger_type_id
node(:location_name) {|exchanger_list| exchanger_list.location.name }
node(:exchanger_type_name) {"normal" }
child currencies(@exchanger)  do
  attribute :value, :direction_of_exchange_id, :exchanger_list_id
end

我的控制器是这样的:

  def index
    @exchangers = ExchangerList.all
  end
  def show
    @exchanger = ExchangerList.find(params[:id])
  end

当我在浏览器中打开我的显示操作时,一切正常,向我的助手发送@exchanger 对象,一切正常。但!当我调用索引操作时,我得到:

Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

有数据一切正常...

当我使用索引 rabl 视图来帮助 @exchanger 对象时如何发送?

4

1 回答 1

0

呵呵)自己找,会分享:

我必须写的是:root_object

object @exchanger
attributes :id, :name, :address, :location_id, :latitude, :longitude, :exchanger_type_id
node(:location_name) {|exchanger_list| exchanger_list.location.name }
node(:exchanger_type_name) {"normal" }
child currencies(root_object)  do
  attribute :value, :direction_of_exchange_id, :exchanger_list_id
end
于 2013-04-24T15:16:51.243 回答