JSON API Output

20 views
Skip to first unread message

Stacy Mullins

unread,
Mar 27, 2015, 4:42:12 PM3/27/15
to roar...@googlegroups.com
Hello,


  I am new to using the ROAR gem and am trying to get different output based on actions in my rails controller. For example:
  

  The singular output for a show action should be 
 
{"book_types": {"book_type_id": 1, "book_type": "hard_cover", "genre": "comedy"}}


The plural output for an index action should be 


{"book_types": [{"book_type_id": 1, "book_type": "hard_cover", "genre": "comedy"},


                        {
                        "book_type_id": 1, "book_type": "hard_cover", "genre": "comedy"}]
                          }
 What can I do to get the desired output?

Thanks


Josh Cohen

unread,
Mar 27, 2015, 7:16:11 PM3/27/15
to roar...@googlegroups.com
You may want to use two different representers. 
One to rep a single item
One to rep a collection
(The collection one can nest the single)

Then in your controller action you invoke the corresponding representer. 

Sent from my iPhone
--
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/d/optout.
Reply all
Reply to author
Forward
0 new messages