I am creating a rails 3 backend that consists of RESTful json controllers. E.g. the controllers look something like this:
respond_to :json
def index
...
respond_with resources
end
...
This is consumed by jQuery on the client. Everything is working great.
My next step is to control the JSON so that some properties are not serialized depending on the context. E.g. the owner of the resource gets more properties sent down than someone who only has read access.
I am currently tending towards Draper and using separate decorators for each model based on the user's role.
My problem is that this is generating a lot of boilerplate. I am also currently using cancan for role based authorization.
Can anyone suggest a better method for accomplishing this?