이런 URL이 있습니다
example.com/users/1376
사용자가 로그인하지 않은 경우에도 누구나이 페이지를 볼 수 있습니다.
이와 같은 URL도 있습니다
example.com/users/1376?mode=1
로그인 한 사용자 만이 페이지를 볼 수 있습니다. 그렇지 않으면 사용자가 로그인 페이지 (new_users_session_path)로 리디렉션됩니다.
이럴 수 있을까요?
before_filter :authenticate_user!, :only => [:show(params[:mode]=1)]
그렇지 않은 경우이 문제를 해결하는 방법을 알려주십시오.
감사
레일 3.2 용
before_filter :redirect_user, :only => :show
레일 4 용
before_action :redirect_user, :only => :show
def redirect_user
if params[:mode] == 1 && current_user
redirect_to user_path(id: params[:id], mode: 1) #example.com/users/1376?mode=1
elsif !current_user && params[:mode].blank?
redirect_to user_path(id: params[:id])
else
redirect_to new_users_session_path
end
end
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다