최근에/signin 및/signup 경로를 사용하여 새 홈페이지 (index.html)를 내 레일 앱 (폴더 public/index.html에 있음)에 구현했습니다. 내 웹 사이트에서 index.html을 구현하기 전에 로그인 또는 가입 한 후 root_url (home.html.erb)으로 사용자를 리디렉션했습니다. 로그 아웃하면 root_path로 리디렉션했습니다.로그인하거나 가입 한 후 index.html로 리디렉션되는 것을 방지하는 방법은 무엇입니까?
이 새로운 index.html 이후에 사용자가 로그인하거나 등록하려고하면 index.html로 다시 연결됩니다. 많은 코드를 수정하지 않아도 원래 root_url에 성공적으로 로그인 할 수 있습니까?
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by_email(params[:session][:email])
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_to root_path
else
flash.now[:error] = "Invalid email/password combination"
render 'new'
end
end
def destroy
sign_out
redirect_to root_path
end
end
UsersController
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome!"
redirect_to root_path
else
render 'new'
end
end
이가 내 routes.rb에서 컨트롤러 명을 처리하는 컨트롤러의 이름이어야합니다 home_ControllerName_path
와 root_path
을 변경하는
root to: 'static_pages#home'
session_controller 또는 users_controller에서 login/sign_up 조치를 찾으십시오. 그러면 둘 다 끝에 리디렉션 조치가 적용됩니다. redirect_to '무엇이든지'대신 redirect_to root_path로 변경하십시오. – Zippie
두 컨트롤러에서 def create 명령으로 root_path로 변경했지만 여전히 동일한 문제가 발생합니다. – johbones
업데이트 된 코드에 코드를 게시했습니다. rake route를 실행하고 home.html.erb이 실제로 root_path인지 확인할 수 있습니까? – Zippie