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'
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With