trailblazer / roar-rails

Use Roar's representers in Rails.
http://roar.apotomo.de
MIT License
235 stars 65 forks source link

Documentation missing for rails index method (collections) #124

Closed sbwoodside closed 7 years ago

sbwoodside commented 8 years ago

I'm new to Roar and I'm unable to find any explicit documentation on how to implement the index method. Based on looking through the other issues, this is what I have now:

class FormsController < ApplicationController
  include Roar::Rails::ControllerAdditions

  def index
    form_params = index_params
    forms = Form.all.limit(form_params[:limit])
    respond_with(forms)
  end

module FormRepresenter
  include Roar::JSON

  property :id
  property :name
  collection :form_results
  collection :form_labels
end

module FormsRepresenter
  include Representable::JSON::Collection

  items extend: FormRepresenter, class: Form
end

This seems to be working. Is it the correct / approved way to implement the index method?

myabc commented 7 years ago

@sbwoodside this looks like a good approach to me.

N.B. once is roar-rails 1.1 is out (see #131), we'll begin deprecating usage of module representers. You might want to switch to using decorators (inheriting from Roar::Decorator). More info here: http://trailblazer.to/gems/representable/3.0/api.html#representer-modules