レールでのダイブに関して、次の問題があります。
すべてのリクエストとレスポンスは JSON です
/partners/sign_inにサインインすると、次の応答が返されます。
HTTP/1.1 200 OK {"成功":true}
/partners/sign_outからサインアウトした後、次の応答が返されます。
HTTP/1.1 200 OK {"成功":true}
今私の質問: どうすれば自分の RegisterController を作成できますか? github/devise で検索しましたが、例が見つかりません。
何か別の応答をしたいのですが、認証が失敗した場合は HTTP 404 ERROR を応答したいです
ルート.rb
devise_for :partners, :controllers => { :sessions => "sessions" }
session_controller.rb
class SessionsController < Devise::SessionsController
def create
resource = warden.authenticate!(:scope => resource_name, :recall => :failure)
return sign_in_and_redirect(resource_name, resource)
end
def destroy
redirect_path = after_sign_out_path_for(resource_name)
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
set_flash_message :notice, :signed_out if signed_out
respond_to do |format|
format.html { redirect_to redirect_path }
format.json { render :json => {:success => true} }
end
end
private
def sign_in_and_redirect(resource_or_scope, resource=nil)
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource ||= resource_or_scope
sign_in(scope, resource) unless warden.user(scope) == resource
return render :json => {:success => true}
end
def failure
return render:json => {:success => false, :errors => ["Login failed."]}
end
end