[英]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.