Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails rabl - returning ALL attributes, not just named ones

Rabl allows you to grab the attributes by naming them in your view, for instance:

object @user
attributes :name, :email

I have a model whose attributes are will not be known, but I'd like to display everything returned from the controller in my instance variable using rabl.

Is there a shortcut like:

attributes :all

etc.

Thanks

like image 825
Squadrons Avatar asked Dec 06 '12 20:12

Squadrons


2 Answers

You should be able to use .column_names:

attributes *User.column_names
like image 200
PinnyM Avatar answered Sep 29 '22 01:09

PinnyM


If you want to get rid of some columns, like "created_at" and "updated_at":

attributes *User.column_names - ["created_at", "updated_at"]
like image 22
Hörður Ingi Avatar answered Sep 29 '22 00:09

Hörður Ingi