ruby - Rails - Jbuilder and use of partials? -
ruby - Rails - Jbuilder and use of partials? -
i have template takes array of objects, , each object needs render partial template. result comes empty objects. thought what's wrong in code??
controller
def index render text: render_to_string(template: 'users.json.jbuilder', locals: {:@uses : users} end
users.json.jbuilder
json.array! @users |user| json.partial! 'user.json.jbuilder', { user: user} end
user.json.jbuilder
jbuilder.encode |json| json.id user.id json.username user.user_name end
result
[{},{},{},{},{},{},{},{},{},{},{},{},{},{}]
user.json.jbuilder
means jbuilder.encode |json|
summoned.
so, user.json.jbuilder
file become functional follows:
json.id user.id json.username user.user_name
that's it... end of story :)
ruby-on-rails ruby jbuilder
Comments
Post a Comment