W
W
waweca2015-08-19 17:20:46
Ruby on Rails
waweca, 2015-08-19 17:20:46

What is the correct way to use ActiveModel::Serializer in a "nested" array in RoR?

With this rendering format json Serializer works.

respond_to do |format|
      format.html
      format.json { render json: @company }
    end

Thus, he ignores
respond_to do |format|
      format.html
      format.json { render json: { company: @company, meta: { current_page: @company.current_page } } }
    end

The meta contains information about Kaminari.
Does ActiveModel::Serializer work in such an array, if so, how to style it correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jeiwan, 2015-08-19
@waweca

Something like this:

render json: { company: CompanySerializer.new(@company, root: false).serializable_hash, meta: { current_page: @company.current_page } }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question