渲染时可以有条件except、only或include选项吗?因此,如下例所示:
render json: @post,
except: [:author]例外选项或类似选项有可能是有条件的吗?
理想情况下,这是一种有条件的方式,允许我处理许多不同的条件和情况。
就像这样:
render json: @post,
except: return_excluded_keysreturn_excluded_keys函数可能会返回需要排除的键。
我使用的是Rails 4.2.6和Active Model Serializer 0.9.3。
发布于 2016-08-02 10:06:08
也许:
render json: @post.as_json(except: [:author])发布于 2016-08-02 08:50:34
Conditional attributes in Active Model Serializers
https://github.com/rails-api/active_model_serializers/issues/825
我相信这些应该会给你指明正确的方向。您可以将条件传递给序列化程序,然后手动构造输出。
https://stackoverflow.com/questions/38710102
复制相似问题