是否有可能在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
发布于 2016-04-20 21:51:13
你应该能做到的..。
attributes *Post.column_namesModel.column_names返回所有列的数组,前面的星号将其转换为逗号分隔的参数。
https://stackoverflow.com/questions/36755363
复制相似问题