ichigolas
ichigolas

Reputation: 7725

Including methods on to_json call

I'm trying to render a json from an ActiveRecord::Base object, including paperclip's methods.

> i = Model.last
> i.to_json methods: :picture
=> # Successful output

Problem is, I need .picture.url(:tiny) and to_json methods: 'picture.url(:tiny)' doesn't work. Is there a way to make to_json work or I'll have to work this around other way?

Upvotes: 0

Views: 1134

Answers (1)

jvnill
jvnill

Reputation: 29599

in your picture model, create a method called picture_avatar

def tiny_avatar
  picture.url(:tiny)
end

then use that method to pass to to_json

i.to_json methods: :tiny_avatar

Upvotes: 2

Related Questions