I want to show different root page for users in Rails.
I defined the root:
root :to => 'welcome#index'
And the welcome control:
class WelcomeController < ApplicationController
before_filter :authenticate_user!
def index
end
end
Currently it is ok for logged in users, but the not logged in users redirected to /users/sign_in
I want to show static root page and not redirect.
The answer, suggested by Puneet Goyal will not work in Rails 4. See this . The solution is to use an alias for one of the two routes like this:
authenticated do
root :to => 'welcome#index', as: :authenticated
end
root :to => 'home#static_page'
In your routes.rb
:
authenticated do
root :to => 'welcome#index'
end
root :to => 'home#static_page'
This will ensure that root_url
for all authenticated users is welcome#index
For your reference: https://github.com/plataformatec/devise/pull/1147
This answer should work. This was posted on the page Bradley linked.
Put this in your Welcome controller.
def index
if authenticate_user?
redirect_to :controller=>'dashboard', :action => 'index'
else
redirect_to '/public/example_html_file.html'
end
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.