0

私には2つのアクションがあり、そのうちのレンダリングは最終的に同じrablテンプレートを使用してjsonを出力する必要がありますが、現時点では、それぞれに独自の名前のテンプレートがあります

Dashboard.json.rablおよびbatch_create.json.rabl

それらはまったく同じですが、ダッシュボードのテンプレートを使用するために、batch_createテンプレートでどのように指定できますか?

ありがとうございました!

編集#コントローラーの2つのアクションとそれらの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
4

1 に答える 1

0

batch_create.json.rablでこれを使用してみましたか?

extends '<insert_object_name>/dashboard'
于 2012-07-14T01:22:52.550 に答える