로그인하지 않은 사용자를 등록 # 새 페이지로 보내고 싶습니다.
로그인 정보를 입력하고 제출을 클릭하면 registrations # show 페이지로 이동합니다.
로그인하지 않으면 registrations # new 페이지로 이동합니다 (지금까지 정확함). 그러나 로그인 양식을 제출하면 리디렉션 루프와 함께 오류가 전송됩니다. 서버의 출력은이 블록이 계속해서 반복됩니다.
Started GET "/" for 127.0.0.1 at 2013-09-25 02:31:59 -0400
Processing by RegistrationsController#new as HTML
User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = 8 ORDER BY "users"."id" ASC LIMIT 1
Redirected to http://lvh.me:3000/
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 2ms (ActiveRecord: 0.7ms)
나는 그것을 알아낼 수없는 것 같다. 수동으로 다른 페이지로 이동하여 확인할 수 있지만 authenticated
루트 경로가 올바르게 작동하지 않는 것을 알 수 있으므로 로그인합니다. 내 경로 파일에서 몇 가지 다른 조합을 시도했지만 얻을 수없는 것 같습니다. 내가 사용하는 코드는 이 스레드를 기반으로합니다.
내 응용 프로그램 컨트롤러에는 before_filter :authenticate_user!
내 경로 파일 :
devise_for :users, :controllers => {
:registrations => "registrations"
}
devise_scope :user do
root to: "registrations#new"
end
authenticated :user do
root to: "registrations#show", :as => "profile"
end
unauthenticated do
root to: "registrations#new", :as => "unauthenticated"
end
먼저 사용자 정의해야합니다 Devise::RegistrationsController
(파일 추가 가능 app/controllers/registrations_controller.rb
).
그리고 devise 에서 prepend_before_filter 를 참조하십시오.registrations_controller.rb
prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
show
작업 추가prepend_before_filter :authenticate_scope!
registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy, :show]
# GET /resource/sign_up
def new
super
end
# POST /resource
def create
super
end
# GET /resource/edit
def edit
super
end
def update
super
end
# DELETE /resource
def destroy
super
end
def show
end
protected
def after_sign_up_path_for(resource)
after_sign_in_path_for(resource)
end
end
또한 장치 등록 (편집 및 새 템플릿) 보기를에 복사하고 프로필 페이지 용 폴더에 /app/views/registrations/
파일 show.html.erb
을 만들 수 있습니다 /app/views/registrations/
.
고안 경로의 경우 다음과 같습니다.
devise_for :users, :skip => [:registrations]
devise_for :users, :controllers => {
:registrations => "registrations"
}
authenticated :user do
devise_scope :user do
root to: "registrations#show", :as => "profile"
end
end
unauthenticated do
devise_scope :user do
root to: "registrations#new", :as => "unauthenticated"
end
end
마지막으로, 당신은의 "경로"를 설정 after_sign_in_path_for(resource)
하고 after_sign_out_path_for(resource_or_scope)
파일에 application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery
private
def after_sign_in_path_for(resource)
# After you enter login info and click submit, I want you to be sent to the registrations#show page
profile_path
end
def after_sign_out_path_for(resource_or_scope)
new_user_session_path
end
end
참고 : 샘플 앱을 만들기 위해 이것을 시도했으며 작동합니다. 여기 에서 로그인 할 때 로그를 확인하고 여기 에서 로그 아웃 하십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다