2014-09-26 48 views
0

我想从我的rabl模板调用Rails辅助方法。我能够为它的一个对象via Stack Overflow调用Rails集合中的Rails帮助器

这是我的当前设置(和它的正常工作)

我有一个帮手

#app/helpers/application_helper.rb 
module ApplicationHelper 

    def full_url(image) 
    "#{request.protocol}#{request.host_with_port}#{image.picture_url}" if recipe.image 
    end 

end 


#app/images/show.rabl 
object @image 
attributes :id, :picture_url 
node(:picture_url) { full_url(@image) } 

现在我要为图像对象的列表做到这一点,但它不工作,我不能在rabl自述文件中找到它。

问题是,它传递@images名单,我不知道如何调用一个辅助方法的各个对象上

#app/images/index.rabl 
collection @images 
attributes :id, 
node(:picture_url) { full_url(@images) } 
+0

什么是'full_url'?它应该是'thumb_url'吗? – BroiSatse 2014-09-26 11:14:40

+0

@BroiSatse,对不起..我的坏,它应该是'full_url',我正在简化我的代码,并得到一个错字。我更新了我的问题。 – sameera207 2014-09-26 11:32:27

回答

3

你可以传递一个参数去您的节点块:

collection @images 
attributes :id, :picture_url 
node(:picture_url) {|image| full_url(image) } 
+0

非常感谢,它的工作原理 – sameera207 2014-09-27 02:53:48