2014-09-26 4 views
0

rabl 템플릿에서 Rails 헬퍼 메소드를 호출하고 싶습니다. 한 개체에 대해 via Stack Overflow 수있었습니다.rabl 콜렉션 내에서 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 README에서 찾으십시오.

문제는 내가 각각의 객체에 대해 도우미 메서드를 호출하는 방법을 잘 모르겠어요, 그것은 @images 목록을 전달합니다

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

'full_url'이란 무엇입니까? 'thumb_url'이 될까요? – BroiSatse

+0

@BroiSatse, 미안 .. 내 잘못이야, 'full_url'로되어있다, 나는 내 코드를 단순화하고 오타가있어. 내 질문을 업데이트했습니다. – sameera207

답변

3

당신은 당신의 노드 블록에 PARAM을 전달할 수 있습니다

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

고마워요, 작동합니다 – sameera207