2013-02-26 2 views
2

그래서 Devise를 사용하여 첫 번째 앱을 만들었습니다! 나는 꽤 놀랐지 만 로그인 후 특정 페이지로 앱을 리디렉션하는 방법에 대해 알고 싶습니다. 즉 Devise를 사용하여 리디렉션하는 방법

,

대신 내가 어떻게 레일 예를 들어 microposts 페이지로 리디렉션합니까, 로그인 및 홈 페이지에 남아?

필자의 경우 구체적으로는 때로는 게시물 페이지로만 리디렉션되며, 다른 경우에는 초기 홈 페이지에만 머물러 있습니다.

가 여기 내 게시물 컨트롤러 : 기본적으로

class PostsController < ApplicationController 
before_filter :authenticate_user!, :except => [:show, :index] 

    def posts 
    @title = "Posts" 
    end 
end 
+0

그렇지 않으면 루트 경로로 리디렉션됩니다. –

답변

2

가 고안 루트로 리디렉션, 당신은 당신이 좋아하는 어쨌든 after_sign_in_path_for 방법을 사용자 정의 할 수 있습니다. 또한 사용자 정의 할 수있는 방법은 after_sign_out_path_for입니다.

ApplicationController < ActionController::Base 
    # extra stuff 

    def after_sign_in_path_for(user) 
    if something 
     posts_path 
    else 
     root_path 
    end 
    end 

    def after_sign_out_path_for(user) 
    new_some_other_path 
    end 
end 
관련 문제