我工作的Rails項目的那一刻,和我建立使用json_builder與拉亞API使用像這樣一個觀點:僅對特定的控制器操作引導clear_helpers?
layer "Layer name"
errorString "ok"
errorCode 0
hotspots @inspections do |inspection|
id inspection.slug
anchor do
geolocation do
lat inspection.lat
lon inspection.lng
end
end
text do
title inspection.name
description "#{inspection.rating} out of 5"
imageURL "http://my-url.com/assets/rating#{inspection.rating}.png"
end
end
然而,當我在瀏覽器中加載這個觀點,沒有出現我的JSON的title
部分。我已經設法縮小到我的layout_helper
文件(我一直使用漂亮的發電機),也被稱爲title
幫助方法。由於我不需要這個幫手,有沒有什麼辦法只爲這個特定的控制器動作運行clear_helpers
?或者有沒有更好的方法來做到這一點? (我是很新,Rails的,因爲你可能會說!)
沒有骰子不幸。我得到錯誤「助手必須是字符串,符號或模塊」。如果我忽略:除了它有效,但很明顯,助手加載了我想跳過的動作 – Pezholio
對,好的。我已經釘了它。只需將輔助方法重命名爲其他內容即可!有時最簡單的解決方案是最簡單的! :) – Pezholio
太棒了!更新我的答案,指出它爲什麼不起作用,但你應該添加並接受你自己的答案:) – robotmay