我正在使用Rails 4.2.5。如果用戶登錄,我想重定向他們,如果他們訪問http://localhost:3000/到http://localhost:3000/user_objects。所以,我已經加入這個我的config/routes.rb中文件在嘗試重定向用戶時遇到問題(如果他們已登錄)
constraints(AuthenticatedUser) do
root :to => "user_objects"
end
root 'pages#index'
然後我在LIB/authenticated_user.rb這個文件......
class AuthenticatedUser
def self.matches?(request)
user_signed_in?
end
end
不幸的是,當我登錄,我訪問http://localhost:3000/,我得到這個錯誤
NameError
uninitialized constant AuthenticatedUser
任何想法如何,我可以,如果有人登錄的用戶重定向到建議的網頁?
編輯:我的config/routes.rb中文件如下...
resources :user_objects, except: :update do
member do
patch :create
put :create
end
get :find_by_user_object_and_day, on: :collection
get :find_totals, on: :collection
end
get "users/edit" => "users#edit"
resources :users
root 'pages#index'
get '/auth/:provider/callback', to: 'sessions#create'
get '/logout', to: 'sessions#destroy'
delete '/logout', to: 'sessions#destroy'
什麼是對object_user輔助方法,當你'耙routes'? – toddmetheny
它試圖剪切和粘貼它有點混亂,但我想我的config/routes.rb文件,這是非常基本的。 – Dave