2016-04-20 98 views
1

是否可以在RABL模板中使用某种通配符来撤回模型的所有可访问属性,而不必指定每个属性?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

回答

1

你应该能够做到这一点...

attributes *Post.column_names 

Model.column_names回报所有列的数组,前面的星号将其转换为逗号sep受评论者。

+0

谢谢。当我读到你的答案时,我面对着自己(字面意思)。 – bigtunacan