사용자가 로그인하기 전에 게시물을 만들 수있는 컨트롤러 PostsController가 있습니다.하지만 저장하려면 Omniauth를 사용하여 로그인해야합니다. 가 PostsController에서before_filter 다른 컨트롤러의 메서드 사용
, 내가 가진 :
class PostsController < ApplicationController
before_filter :authenticate_user_by_service, :only => :create
def create
...
end
private
def authenticate_user_by_service
redirect_to user_omniauth_authorize_path(:facebook)
end
을 지금, 나는 ServicesController
라고 페이스 북에서 콜백을 처리 할 수있는 또 다른 컨트롤러가class ServicesController < ApplicationController
def create
auth = request.env["omniauth.auth"]
... authentication logic here ...
sign_in(:user, service.user)
end
method_alias: :facebook, :create
일반적으로, 인증, 로그인 한 후에 I 리디렉션 대상 : back.
그러나 여기서 services#create
은 before_filter로 사용됩니다. 이 경우 내 게시물 # 만들기로 되돌리려면 어떻게해야합니까?
업데이트 : 필터 체인을 말하는이 경고를 가지고 바로 내가 당신 잘못이 접근하고 다른 방법
Started POST "/posts" for 127.0.0.1 at 2013-02-26 23:47:41 -0500
Processing by PostsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"H0as8=", "post"=>{"post"=>"bla bla"}, "commit"=>"Create Post"}
Redirected to http://localhost:3000/users/auth/facebook
Filter chain halted as :authenticate_user_by_service rendered or redirected
매우 자세한 답변을 제공해 주셔서 감사합니다. 사용자가 로그인하지 않으면 Posts # create에서 어떤 일이 일어나는지 친절하게 설명 할 수 있습니까? 이 메소드 내에서 require_login을 호출해야합니까? – AdamNYC