3

APIを使用してRails3アプリを作成しようとしています。認証システムとしてDeviseを使用しています。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

私のコメントで述べたように、これはおそらく非常に間違っているので、誰かがそれを機能させる方法について私にガイダンスを与えることができるかどうか疑問に思います。アカウントはユーザーのネストされたリソースであることにも言及する必要があります。

また、Deviseを使用してAPIでログインおよびログアウト機能をどのように設定する必要があるのか​​疑問に思います。

ありがとう!

4

1 に答える 1

4

この他のSOの質問はあなたを助けるかもしれません。よく似ています。答えにリンクされている要点に特に注意してください。

于 2012-06-06T16:18:27.403 に答える