【发布时间】:2012-06-10 16:41:18
【问题描述】:
我正在尝试使用 API 创建 Rails 3 应用程序。我使用设计作为我的身份验证系统。我想让注册和稍后通过 API 登录成为可能。我不太确定我应该怎么做。我创建了单独的控制器来管理 API,即api/v1/account/1/projects.json。我目前正在尝试为 API 创建一个自定义 Devise::RegistrationsController,但我不太确定如何执行此操作。
我的创建操作目前如下所示:
class API::V1::RegistrationsController < Devise::RegistrationsController
redpond_to :json, :xml
def create
build_resource
if resource.save
if resource.active_for_authentication?
# Account is a nested resource for User, I want to
# create an associated account when the User signs up through the client,
# how should I do this?
account = resource.accounts.build
# How can I get the sign_in to work?
sign_in(resource_name, resource)
# Probably wrong
respond_with resource, :location => after_sign_up_path_for(resource)
else
# probably wrong
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
# probably wrong, or?
clean_up_passwords resource
end
end
正如我的 cmets 中提到的那样,这可能是非常不正确的,所以我想知道是否有人可以给我任何关于如何使其工作的指导。还应该提到帐户是用户的嵌套资源。
我还想知道如何使用 Devise 在 API 中设置登录和注销功能。
谢谢!
【问题讨论】:
标签: ruby-on-rails ruby api ruby-on-rails-3.1 devise