开发者

Rails: friendly_id and to_json

开发者 https://www.devze.com 2023-03-07 04:05 出处:网络
I have a collection of model objects that I am trying to return JSON for.E.G @regions.to_json(:only => [:id, :name ])

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?


Try using

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

精彩评论

暂无评论...
验证码 换一张
取 消