Ruby on rails 如何:Rails使用完全相同的rabl模板响应json?

Ruby on rails 如何:Rails使用完全相同的rabl模板响应json?,ruby-on-rails,rabl,Ruby On Rails,Rabl,我有两个操作,其中呈现最终应该使用相同的rabl模板输出json,但目前,它们都有一个具有自己名称的模板 dashboard.json.rabl和batch_create.json.rabl 它们完全相同,如何在batch_create模板中指定使用仪表板的模板 谢谢大家! 编辑#包括控制器的两个动作及其rabl视图 行项目控制器.rb app/views/line\u items/dashboard.json.rabl与app/views/line\u items/batch\u create

我有两个操作,其中呈现最终应该使用相同的rabl模板输出json,但目前,它们都有一个具有自己名称的模板

dashboard.json.rabl和batch_create.json.rabl

它们完全相同,如何在batch_create模板中指定使用仪表板的模板

谢谢大家!

编辑#包括控制器的两个动作及其rabl视图

行项目控制器.rb app/views/line\u items/dashboard.json.rabl与app/views/line\u items/batch\u create.json.rabl相同
您是否尝试在批处理_create.json.rabl中使用此选项:

extends '<insert_object_name>/dashboard'
扩展“/dashboard”

Hi TC,我试过了,但是返回的对象被包装在一个数组中。因此,在我的dashboard.json.rabl中,它返回{“foo”:“bar”},如果我在批处理_create.json.rabl中执行扩展'line_items/dashboard',我将返回[{“foo”:“bar”}]。您知道如何排除将其视为对象数组的情况吗?谢谢,您可以用rabl视图和控制器操作更新问题吗?整个响应是否包含在[]中,还是仅包含行_items子项?最后一行的第三行应为“child@line_items=>:line_items do”,并且整个响应不包含在[]中
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
extends '<insert_object_name>/dashboard'