簡體   English   中英

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返回所有列的數組,前面的星號將其轉換為逗號分隔的參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM