我有两个渲染最终应该使用相同的rabl模板输出json的动作,但此刻,它们每个都有一个带有自己名字的模板
dashboard.json.rabl和batch_create.json.rabl
它们完全相同,我如何在batch_create模板中指定使用仪表板的模板?
谢谢!
编辑#including控制器的两个动作和他们的rabl视图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
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
答案 0 :(得分:0)
您是否尝试过在batch_create.json.rabl中使用它:
extends '<insert_object_name>/dashboard'