Image url in JSON (RABL, Dragonfly, Ruby on Rails) -
i'm using rabl gem, user model has many posts
users/show.rabl
object @user attributes :id, :name kid :posts extends "posts/post" end
posts/_post.rabl
attributes :id, image: post.image.url
i want show post's image, have error: undefined local variable or method "post".
but in posts/_post.html.erb can utilize <%= post.image.url =%>
images loaded dragonfly gem.
how can image url in json format?
if child-attribute can append root node using glue.
like this:
@post attributes :id, :image_url glue @image attributes :url => :image_url end
or perhaps this:
@post attributes :id node :image_url |post| post.image.url end
ruby-on-rails-3.2 rabl dragonfly-gem
No comments:
Post a Comment