Ruby on rails 4 登录后将root更改为usershow
我似乎无法在Rails 4应用程序中找到更改的根。我只想在用户登录后更改根目录,以便它指向用户显示页面 我得到以下错误: 找不到没有ID的用户 My routes.rb看起来是这样的:Ruby on rails 4 登录后将root更改为usershow,ruby-on-rails-4,devise,routes,Ruby On Rails 4,Devise,Routes,我似乎无法在Rails 4应用程序中找到更改的根。我只想在用户登录后更改根目录,以便它指向用户显示页面 我得到以下错误: 找不到没有ID的用户 My routes.rb看起来是这样的: devise_for :users, :path_names => {:sign_up => "register", } authenticated :user do root to: "users#show", as: :authenticated_root end unau
devise_for :users, :path_names => {:sign_up => "register", }
authenticated :user do
root to: "users#show", as: :authenticated_root
end
unauthenticated do
get 'welcome/index'
root to: "static#index"
end
match 'users/:id' => 'users#show', as: :user, via: :get
get "/asian-century" => "static#asian-century"
get "/pricing" => "static#about"
get "/about" => "static#pricing"
get "/chatroom" => "static#chatroom"
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
def index
@users = User.all
end
def show
if params[:id]
@user = User.find(params[:id])
else
@user = current_user
end
@userlessons = @user.lessons_to_attend.where("starts_at > ?", Time.now.advance(:hours => -1)).order(starts_at: :asc)
unless @user == current_user
redirect_to :back, :alert => "Access denied."
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params[:user]
end
end
...
我的用户控制器喜欢这样:
devise_for :users, :path_names => {:sign_up => "register", }
authenticated :user do
root to: "users#show", as: :authenticated_root
end
unauthenticated do
get 'welcome/index'
root to: "static#index"
end
match 'users/:id' => 'users#show', as: :user, via: :get
get "/asian-century" => "static#asian-century"
get "/pricing" => "static#about"
get "/about" => "static#pricing"
get "/chatroom" => "static#chatroom"
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
def index
@users = User.all
end
def show
if params[:id]
@user = User.find(params[:id])
else
@user = current_user
end
@userlessons = @user.lessons_to_attend.where("starts_at > ?", Time.now.advance(:hours => -1)).order(starts_at: :asc)
unless @user == current_user
redirect_to :back, :alert => "Access denied."
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params[:user]
end
end
...
你能发布完整的错误跟踪吗?@Pavan这有帮助吗?New edit.Yes.您可以发布控制器的设置用户方法吗?