我想從我的rabl
模板調用Rails幫助程序,但它不起作用。來自Rabl Rails的調用Rails幫手
我有一個圖像對象,我想通過它的通過我的api。那麼圖像路徑應該有完整的網址(例如:http://<my url>/uploads/myimage.jpg
)。主機部分我想通過Rails助手添加。
#my rabl file
object @image
attributes :id, :picture_url
我要的是一樣的東西(我試過,但不起作用)
#my rabl file
object @image
attributes :id, full_url(:picture_url)
#app/helpers/application_helper.rb
module ApplicationHelper
def full_url(path)
"#{request.host}#{path}" #something like this
end
end
但是當我這樣做,它完全從json
對象拖放的:picture_url
屬性
作品完美,非常感謝:雖然 – sameera207 2014-09-25 23:38:45
快問d,好像它不讀屬性的值,它需要的屬性作爲一個字符串,防爆如果的屬性值路徑說'my_image.gif',它使我回到'http:// localhost:3000/path'而不是'http:// localhost:3000/my_image.gif' ..任何想法? Im on rails 4.1.5 – sameera207 2014-09-26 00:03:53
@ sameera207看起來像我得到了節點的語法錯誤。我更新了我的答案,以獲得正確的語法。 – Eugene 2014-09-26 12:15:15