グレープエンティティを使用してモデルメソッドに引数を渡すにはどうすればよいですか?
アイテムを提示するときに current_user がアイテムを気に入るかどうかを確認したいので、モデルuser_likes?
メソッドを作成しました。
class Item
include Mongoid::Document
#some attributes here...
has_and_belongs_to_many :likers
def user_likes?(user)
likers.include?(user)
end
end
しかし、現在のユーザーをグレープエンティティモデルに送信する方法がわかりません:
module FancyApp
module Entities
class Item < Grape::Entity
expose :name #easy
expose :user_likes # <= How can I send an argument to this guy ?
end
end
end
ブドウのAPIで:
get :id do
item = Item.find(.....)
present item, with: FancyApp::Entities::Item # I should probably send current_user here, but how ?
end
current_user はおそらくこの最後のコードから送信されるべきだと思いますが、その方法がわかりません:(
何かご意見は ?ありがとう !