Rails 4 json return on API
- by El - Key
I'm creating an API on my application. I currently overrided the as_json method in my model in order to be able to get attached files as well as logo from Paperclip :
def as_json( options = {} )
super.merge(logo_small: self.logo.url(:small), logo_large: self.logo.url(:large), taxe: self.taxe, attachments: self.attachments)
end
Then within my controller, I'm doing :
def index
@products = current_user.products
respond_with @products
end
def show
respond_with @product
end
The problem is that on the index, I don't want get all the attachments. I only need it on the show method. So I tried it :
def index
@products = current_user.products
respond_with @products, except: [:attachments]
end
But unfortunately it's not working. How can I do to not send :attachments?
Thanks