Rails 4 json return on API

Posted by El - Key on Stack Overflow See other posts from Stack Overflow or by El - Key
Published on 2013-10-29T21:51:05Z Indexed on 2013/10/29 21:53 UTC
Read the original article Hit count: 205

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about JSON