2013-04-24 43 views
0

發送對象我有這樣的index.rabl:Rails的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 

當我在瀏覽器中打開我的show動作時,一切正常,對我的幫助者來說是@exchanger對象,一切都好。但!當我打電話指數動作我得到:

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

數據一切正常......

當我使用索引Rabl的視圖幫手@exchanger對象如何發送?

回答

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