我有两个动作,其中渲染最终应该使用相同的 rabl 模板输出 json,但目前,它们都有一个具有自己名称的模板
dashboard.json.rabl 和 batch_create.json.rabl
它们完全相同,如何在 batch_create 模板中指定使用仪表板的模板?
谢谢!
编辑#包括控制器的两个动作及其 rabl 视图
line_items_controller.rb
def dashboard
@line_items ||= LineItem.limit(1000).all.to_a
pids = [1,2,3,4,5]
@projects = Project.only(:id, :name).where(:_id.in => pids).to_a
@users = User.only(:first, :last, :role, :company_id).all.to_a
@companies= Company.where(:_id.in => @users.map(&:company_id)).to_a
@specs = Spec.where(:specable_id.in => pids).to_a
spec_ids= @specs.map { |e| e.id }
@contact_infos = ContactInfo.where(:infoable_id.in => spec_ids).to_a end
gon.rabl
respond_to do |format|
format.html
format.json
end
end
def batch_create
@line_items = LineItem.where(:_id.in => params[:line_item_ids]).to_a
# else same as #dashboard
end
app/views/line_items/dashboard.json.rabl 与 app/views/line_items/batch_create.json.rabl 相同
object false
child @projects => :projects do
attributes :id, :name
end
child @companies => :companies do
attributes :id, :name
end
child @users => :users do
attributes :id, :full, :company_id
end
child @specs => :specs do
attributes :id, :style, :due_at_note
end
child @contact_infos => :contact_infos do
attributes :info, :infoable_id
end
child @line_items do
attributes :id, :title, :dashboard_length, :dashboard_created_at, :original_file_url, :project_id
end