【发布时间】:2012-09-20 01:17:37
【问题描述】:
我需要将 json 嵌入到 html 中,并在 #322 RailsCasts 中说明了使用 RABL 的方法...
app/views/places/show.html.erb
<div id="place" data-place="<%= render(template: "places/show.json.rabl") %>" >
这是我的 rabl 模板
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
它工作正常,但我想在其他视图中呈现 rabl 模板:
app/views/places/finder.html.erb
<%= @places.each do |place| %>
<div id="place-<%= place.id %>" data-place="<%= render(template: "places/show.json.rabl") %>" >
<% end %>
它显示下一条消息错误
nil:NilClass 的未定义方法 `type_place'
Extracted source (around line #1):
1: object @place
2: attributes :id, :name, :desc, :address
3:
4: node(:type) { |place| place.type_place.name }
从消息中我认为错误是我没有将对象位置传递给模板...我尝试了很多但没有得到这个。
提前谢谢,对不起我的英语
【问题讨论】:
标签: ruby-on-rails json rabl