【发布时间】:2016-04-08 15:08:37
【问题描述】:
我正在使用 Ionic 框架,但问题是关于 AngularJS。我已经在 ruby on rails 上编写了 json api。对于身份验证,我选择ng-token-auth + devise-token-auth。
用户json:
{
"data": {
"id": "1",
"type": "users",
"attributes": {
"name": "User1",
"email": "email@email.com",
"current-sign-in-at": "..",
"last-sign-in-at": "..",
"created-at": ".."
},
"relationships": {
"friends": {
"data": [
{
"id": "2",
"type": "users"
}
]
}
}
},
"included": [
{
"id": "2",
"type": "users",
"attributes": {
"name": "User2",
"email": "user@user.com",
"current-sign-in-at": "..",
"last-sign-in-at": "..",
"created-at": ".."
},
"relationships": {
"friends": {
"data": [ ]
}
}
}
]
}
我的用户序列化器:
class UserSerializer < ActiveModel::Serializer
attributes :id, :name, :email,:current_sign_in_at,
:last_sign_in_at, :created_at
has_many :friends, through: :friendships
end
当前用户对象作为响应:
{"success":true,"data":{"id":1,"provider":"email","uid":"0a56bb6b-dc72-4ef3-906e-1c17cb2fef46","name"
:"User1","nickname":null,"image":null,"email":"email@email.com"}}
这是我的问题,我无法获取用户关系信息。
我不知道为什么,但我认为对象名称是用户(不是 current_user),并且在我的控制器中无权访问它。 问题是我如何从这个对象中获得一些额外的信息,以及如何为我的控制器提供当前用户对象访问权限。
【问题讨论】:
标签: ruby-on-rails angularjs json api ionic-framework