我有這樣的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 do
attribute :value, :direction_of_exchange_id, :exchanger_list_id
end
我位指示是這樣的:
def index
@exchangers = ExchangerList.all
end
def show
@exchanger = ExchangerList.find(params[:id])
@currency_list = CurrencyList.all
@currencies = []
@currency_list.each do |c|
@currencies << CurrencyValue.find(:all, :conditions => {:currency_list_id => c.id, :exchanger_list_id => @exchanger.id}, :order => :updated_at).last(2)
end
@currencies.flatten!
end
如果我打電話瀏覽器顯示方法,我看到孩子@currencies和它的數據,但如果我打電話索引我看到所有(我也看到節點),但孩子,我沒有e ....怎麼了?我做得不好?
你的意思是你看不到@currencies子節點?當您調用index並僅渲染顯示模板時,此實例變量將爲零。 – dan 2013-04-24 12:19:08
@dan是的,也許你是對的....但如何才能解決我的問題? – 2013-04-24 12:23:20
我不會理睬你,我發佈了一個答案,因爲評論中缺少空間。 – dan 2013-04-24 12:47:27