Rails プロジェクトの API を開発していますが、この問題を解決する方法がわかりません。
doorkeeper
認証には gemを使用rabl
し、json レンダリングには gem を使用します。そして、ログインしたユーザー専用のフィールドをいくつか追加する必要があります。
例: の一部show.rabl
:
node :accessible, if: lambda { |m| current_user } do |model|
model.accessible(current_user)
end
そしてapi/application_controller.rb
:
def current_user
User.find(doorkeper_token.resource_owner_id) if doorkeper_token
end
私もこの方法を試しました(rabl
ファイル):
if current_user
node(:accessible) { |m| m.accessible(current_user) }
else
{no: "no"} # this line rendered!!
end
そして、rabl は私のメソッドについて何も知らず、if
ラムダで false を返します。どうすればこの問題を解決できますか? 私は提案の準備ができています。ありがとうございました!
私が使うrails-3.2.6 doorkeeper-0.4.2 rabl-0.6.13