3

I'm trying to get a json view that uses rabl to have custom attributes sent by the request, so for example if a model has

:id, :first_name, :last_name

I wanna be able to just call the values I want like say id and first_name only, so what I dont know is how to convert something like a string to the attributes that rabble has to return.

Thanks

merlin371
  • 504
  • 1
  • 4
  • 11

1 Answers1

0

First of all create variable in controller set by request. For example

@attributes_choose_by_user = params[:attrs]

them just pass that variable as parameter to attributes in an viewer

# app/views/posts/index.rabl
collection @posts
attributes @attributes_choose_by_user

request should look like this

GET /posts?attrs[]=id&attrs[]=first_name&attrs[]=last_name
Maksim Morozov
  • 53
  • 4
  • 13