passing parameters to a representer roar-rails

502 views
Skip to first unread message

Josh Cohen

unread,
Jun 12, 2013, 8:21:16 PM6/12/13
to roar...@googlegroups.com

In the docs,

https://github.com/apotonick/roar-rails/#passing-options

 

If I do this in the controller:

 

respond_with @people, represent_with => PeopleRepresenter, :page_numberz => 5

 

(I've tried it both as a single hash with :represent_with, as well as individual params as above)

 

And this in the representer:

 

property :page_numberz

 

I get method not found.

 

How is this supposed to be done?

 

Im trying to implement pagination.  In my controller I have magic to parse the query string for page and per_page then I do the appropriate queries to get the right records.  Then in my HAL output, I include collection metadata for pagination.  I was expecting to pass things like total_pages from the controller to the representer by using paramaters

 

Eg:

{

  "total_pages": 1,

  "page": 1,

  "total_records": 1,

  "_embedded": {

    "people": [

      {

        "first_name": "Ayla",

        "last_name": "Erdman",

        "middle_name": "Graham",

 

Josh Cohen

jos...@gmail.com | @joshco

 

Nick Sutterer

unread,
Jun 12, 2013, 8:22:51 PM6/12/13
to roar...@googlegroups.com
Looks like a bug. Have you tried it without :represent_with ?


--
You received this message because you are subscribed to the Google Groups "Roar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to roar-talk+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Josh Cohen

unread,
Jun 12, 2013, 8:27:21 PM6/12/13
to roar...@googlegroups.com

No, I'm not sure how to do that.

In my controller, I have:

 

      def index

 

        @people=get_pages(Person)

        respond_with @people, :represent_with => PeopleRepresenter, :page_numberz => 5

 

      end

 

Since I have to call get_pages (which looks at params[] to figure out what query to run), I didn’t see how to do that with something like:

 

class SingersController < ApplicationController

  represents :json, :entity => MusicianRepresenter, :collection => MusicianCollectionRepresenter

 

Can you give me the code line to replace my respond_with to test?

Nick Sutterer

unread,
Jun 12, 2013, 8:54:23 PM6/12/13
to roar...@googlegroups.com
If `people` is a collection, do

  represents :json,  :collection => PeopleRepresenter


Nick Sutterer

unread,
Jun 12, 2013, 9:13:41 PM6/12/13
to roar...@googlegroups.com

Josh Cohen

unread,
Jun 12, 2013, 9:36:47 PM6/12/13
to roar...@googlegroups.com

Where would this line go?

When I replaced the respond_with line (in my index action), I got unknown method represents

Nick Sutterer

unread,
Jun 12, 2013, 9:44:23 PM6/12/13
to roar...@googlegroups.com
It's a class method, check the roar-rails README: https://github.com/apotonick/roar-rails/#represents-configuration
Reply all
Reply to author
Forward
0 new messages