for example,
i got a list of Target in my controller
@targets = @user.targets.all
then i want to render @targets as json result for client ajax call.
in Target class define, i have some column i don’t want to render.
i know when render single @target, we can use
:only
or
:except
but, how to deal with the list?
i tried
@targets.each do |target| xxxx end
to merge the json result, failed.
Override
as_jsonin yourTargetclass and specify which columns you don’t want to be rendered.More details here.