내 Item 모델에서 메서드의 값을 출력하려고합니다 (current_user는 application_controller에 정의되어 있습니다).rabl에서 메소드 값을 출력하는 방법은 무엇입니까?
object @item
attributes :id, :name
code :is_liked do |this_item|
if current_user
this_item.is_liked current_user
else
false
end
end
내 모델 : 나는 현재 내 rabl 템플릿으로이
class Item < ActiveRecord::Base
...
def is_liked user
if user
if user.liked_item_ids.include?(self.id)
return true
else
return false
end
end
end
....
end
그러나 그것은 작동하지 않습니다. 나는 이것을 출력하는 적절한 방법이 무엇인지 확신하지 못한다. 이 아이디어가 올바르게 작동하는 방법을 알고 싶습니까?
이Failure/Error: Unable to find matching line from backtrace
ActionView::Template::Error:
stack level too deep
들으, 나는 시도하지만 점점 오전 오류로 질문을 업데이트했습니다. current_user가 내 rabl 템플릿에서 액세스 할 수 있는지 확실하지 않아 현재 테스트 중입니다. – timpone
current_user를 사용할 수 있어야합니다. 그냥'attributes'리스트에서'is_liked'를 제거하고'is_liked' 메쏘드를 확인하십시오. – apneadiving
thx; 네, 속성에서 is_liked와 함께 시도해 봤지만 여러분의 의견에 동의합니다. 질문을 업데이트 할 것입니다. 나는 current_user를 application_controller와 helper_method로 가지고 있기보다는 helper 클래스로 옮겨 보려고합니다. thx – timpone