如何在索引视图中显示许多嵌套对象之一
class Album < ActiveRecord::Base
has_many: photos
accepts_nested_attributes_for :photos,
:reject_if => proc { |a| a.all? { |k, v| v.blank?} }
has_one: cover
accepts_nested_attributes_for :cover
end
class Album Controller < ApplicationController
layout "mini"
def index
@albums = Album.find(:all,
:include => [:cover,]).reverse
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @albums }
end
end
这就是我的票价。我只想为每张专辑展示一个封面。
任何关于这方面的信息都会有很大的帮助!!