0

I have a collection of model objects that I am trying to return JSON for. E.G

@regions.to_json(:only => [:id, :name ])

that works fine.

If I try to use :

@regions.to_json(:only => [:friendly_id, :name ]) 

then nothing is returned for the friendly_id. The model does have:

has_friendly_id :name, :use_slug => true

So I am wondering what I am missing - or if I am not allowed to use friendly_id's in to_json?

patrickdavey
  • 1,966
  • 2
  • 18
  • 25

1 Answers1

2

Try using

@regions.to_json(:only => [:id, :cached_slug])
Aj Gu
  • 1,509
  • 9
  • 12