比如有如下代码: @exams = Exam.all render json: @exams.to_json
请教如何删除所有记录中的某个无用的属性?
可以使用 gem activeserializer 抱歉,不会拼,希望没拼错
#1 楼 @flowerwrong 你指active_model_serializers?
user.as_json(only: [:id, :name]) # => { "id" => 1, "name" => "Konata Izumi" } user.as_json(except: [:id, :created_at, :age]) # => { "name" => "Konata Izumi", "awesome" => true }
#2 楼 @ericguo 对,就这个