3
我在Rails項目中使用Active Model Serializers Rails中控制器選項,並有一個user
對象,需要從控制器傳遞到串行這樣的:默認的序列渲染
# Note the 'user:' option that will be accessible inside
# the serializer with @options[:user]
def show
render json: @some_object, user: current_user
end
def index
render json: SomeObject.all, user: current_user
end
這是不夠好我正在嘗試做什麼,但它不是非常乾燥,並導致render
陳述充滿了選項。當這些選項發生變化時,我需要返回並在所有操作中手動刪除/修改它們。
我的問題是:有沒有辦法在控制器級別設置render
調用的默認選項列表,而不是手動將選項手動放置在每個控制器操作中?
然後訪問這在0.10.x被_removed_(不推薦) – saywhatnow 2017-03-17 01:14:29