RABL - 通配符包括所有属性

RABL - Wildcard include all attributes

是否可以在 RABL 模板中使用某种通配符来拉回模型的所有可访问属性,而不必指定每个属性?

作为示例,RABL 文档显示了如下内容,它带回了 :id, :title, :subject 属性。

# app/views/posts/index.rabl
collection @posts
attributes :id, :title, :subject
child(:user) { attributes :full_name }
node(:read) { |post| post.read_by?(@user) }

我想做一些类似的事情

# app/views/posts/index.rabl
collection @posts
attributes *
child(:user) { attributes :full_name }
node(:read) { |post| post.read_by?(@user) }

并让这个给 :id, :title, :subject, :author, :etc

你应该可以做到这一点...

attributes *Post.column_names

Model.column_names returns 所有列的数组,前面的星号将其转换为逗号分隔的参数。