I'm following the #322 RailsCasts and in the last part he comments a way to embebed json into html
<div id="articles" data-articles="<%= render(template: "articles/index.json.rabl") %>" >
In my project I have a rabl template: app/views/places/show.json.rabl
object @place
attributes :id, :name, :desc, :address
node(:type) { |place| place.type_place.name }
child :photos do
attributes :id, :desc
node(:url) { |photo| photo.image.url(:square) }
end
If I render /places/21.json it shows:
{"id":21,"name":"foo","desc":"bar","address":"some address","type":"baz",
"photos":[{"id":26,"desc":"foofoo","url":"/uploads/photo/image/26/square_conmemorativo-1920x1080.jpg"}]}
well it's working but if I try to embebed json data into html I'm doing this:
<article id="show_place" data-place="<%= render(template: "places/#{@place.id}.json.rabl") %>" >
error log
Missing template places/21.json with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :rabl]}. Searched in: * "/home/ed/projects/rails_projects/final_u/app/views"
What Am I doing wrong?
UPDATE
I just found the solution
<article id="show_place" data-place="<%= render(template: "places/show.json.rabl") %>" >
And it works but I don't know why.. and here I have another question
There is a way to pass a single object to the render(template: "") ??
Thanks in advance.... and sorry for my English