2016-04-20 93 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