Rails routes for a static landing page if user not logged in (Devise)
up vote
0
down vote
favorite
In my application I am using the Devise authentication gem which works really well. I also have built a static landing page which I currently have in the /public
directory.
I can of course browser to localhost:3000/landing
and see the page (as per the route below) but what I'm trying to achieve but cannot seem to figure out is how to setup my routes.rb
file so that the landing.html
file is the root, but when a user is logged in, their root becomes companies#index
.
Any help much appreciated!
Here is my routes.rb file
Rails.application.routes.draw do
devise_for :users
get 'dashboard/index'
get '/landing', :to => redirect('/landing.html')
root 'companies#index'
resources :companies do
resources :shareholders
resources :captables do
post :subscribe_to_captable
resources :events do
post :lock_event
post :unlock_event
resources :transactions
end
end
end
end
Here is my application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
end
ruby-on-rails devise
add a comment |
up vote
0
down vote
favorite
In my application I am using the Devise authentication gem which works really well. I also have built a static landing page which I currently have in the /public
directory.
I can of course browser to localhost:3000/landing
and see the page (as per the route below) but what I'm trying to achieve but cannot seem to figure out is how to setup my routes.rb
file so that the landing.html
file is the root, but when a user is logged in, their root becomes companies#index
.
Any help much appreciated!
Here is my routes.rb file
Rails.application.routes.draw do
devise_for :users
get 'dashboard/index'
get '/landing', :to => redirect('/landing.html')
root 'companies#index'
resources :companies do
resources :shareholders
resources :captables do
post :subscribe_to_captable
resources :events do
post :lock_event
post :unlock_event
resources :transactions
end
end
end
end
Here is my application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
end
ruby-on-rails devise
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
In my application I am using the Devise authentication gem which works really well. I also have built a static landing page which I currently have in the /public
directory.
I can of course browser to localhost:3000/landing
and see the page (as per the route below) but what I'm trying to achieve but cannot seem to figure out is how to setup my routes.rb
file so that the landing.html
file is the root, but when a user is logged in, their root becomes companies#index
.
Any help much appreciated!
Here is my routes.rb file
Rails.application.routes.draw do
devise_for :users
get 'dashboard/index'
get '/landing', :to => redirect('/landing.html')
root 'companies#index'
resources :companies do
resources :shareholders
resources :captables do
post :subscribe_to_captable
resources :events do
post :lock_event
post :unlock_event
resources :transactions
end
end
end
end
Here is my application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
end
ruby-on-rails devise
In my application I am using the Devise authentication gem which works really well. I also have built a static landing page which I currently have in the /public
directory.
I can of course browser to localhost:3000/landing
and see the page (as per the route below) but what I'm trying to achieve but cannot seem to figure out is how to setup my routes.rb
file so that the landing.html
file is the root, but when a user is logged in, their root becomes companies#index
.
Any help much appreciated!
Here is my routes.rb file
Rails.application.routes.draw do
devise_for :users
get 'dashboard/index'
get '/landing', :to => redirect('/landing.html')
root 'companies#index'
resources :companies do
resources :shareholders
resources :captables do
post :subscribe_to_captable
resources :events do
post :lock_event
post :unlock_event
resources :transactions
end
end
end
end
Here is my application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
end
ruby-on-rails devise
ruby-on-rails devise
asked Nov 7 at 19:22
JP89
7418
7418
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
One way is to put the redirect inside your CompaniesController.rb
index
method do this.
CompanesController.rb (or whatever it is called)
def index
unless user_signed_in?
redirect_to landing_pages_path (or whatever the name of the route is)
end
end
Then change the route in the routes.rb
file.
get '/landing', to: 'companies#landing' * change companies here to the name of the controller holding the landing page's method if it is not in the companies controller.
Ah, so I don't actually have any controller for the landing page - it's simply an html file in the /public folder. Should probably change that. Thanks for your help!
– JP89
Nov 7 at 19:52
1
If you do change it this will work
– Rockwell Rice
Nov 7 at 19:54
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
One way is to put the redirect inside your CompaniesController.rb
index
method do this.
CompanesController.rb (or whatever it is called)
def index
unless user_signed_in?
redirect_to landing_pages_path (or whatever the name of the route is)
end
end
Then change the route in the routes.rb
file.
get '/landing', to: 'companies#landing' * change companies here to the name of the controller holding the landing page's method if it is not in the companies controller.
Ah, so I don't actually have any controller for the landing page - it's simply an html file in the /public folder. Should probably change that. Thanks for your help!
– JP89
Nov 7 at 19:52
1
If you do change it this will work
– Rockwell Rice
Nov 7 at 19:54
add a comment |
up vote
1
down vote
accepted
One way is to put the redirect inside your CompaniesController.rb
index
method do this.
CompanesController.rb (or whatever it is called)
def index
unless user_signed_in?
redirect_to landing_pages_path (or whatever the name of the route is)
end
end
Then change the route in the routes.rb
file.
get '/landing', to: 'companies#landing' * change companies here to the name of the controller holding the landing page's method if it is not in the companies controller.
Ah, so I don't actually have any controller for the landing page - it's simply an html file in the /public folder. Should probably change that. Thanks for your help!
– JP89
Nov 7 at 19:52
1
If you do change it this will work
– Rockwell Rice
Nov 7 at 19:54
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
One way is to put the redirect inside your CompaniesController.rb
index
method do this.
CompanesController.rb (or whatever it is called)
def index
unless user_signed_in?
redirect_to landing_pages_path (or whatever the name of the route is)
end
end
Then change the route in the routes.rb
file.
get '/landing', to: 'companies#landing' * change companies here to the name of the controller holding the landing page's method if it is not in the companies controller.
One way is to put the redirect inside your CompaniesController.rb
index
method do this.
CompanesController.rb (or whatever it is called)
def index
unless user_signed_in?
redirect_to landing_pages_path (or whatever the name of the route is)
end
end
Then change the route in the routes.rb
file.
get '/landing', to: 'companies#landing' * change companies here to the name of the controller holding the landing page's method if it is not in the companies controller.
answered Nov 7 at 19:47
Rockwell Rice
1,99041835
1,99041835
Ah, so I don't actually have any controller for the landing page - it's simply an html file in the /public folder. Should probably change that. Thanks for your help!
– JP89
Nov 7 at 19:52
1
If you do change it this will work
– Rockwell Rice
Nov 7 at 19:54
add a comment |
Ah, so I don't actually have any controller for the landing page - it's simply an html file in the /public folder. Should probably change that. Thanks for your help!
– JP89
Nov 7 at 19:52
1
If you do change it this will work
– Rockwell Rice
Nov 7 at 19:54
Ah, so I don't actually have any controller for the landing page - it's simply an html file in the /public folder. Should probably change that. Thanks for your help!
– JP89
Nov 7 at 19:52
Ah, so I don't actually have any controller for the landing page - it's simply an html file in the /public folder. Should probably change that. Thanks for your help!
– JP89
Nov 7 at 19:52
1
1
If you do change it this will work
– Rockwell Rice
Nov 7 at 19:54
If you do change it this will work
– Rockwell Rice
Nov 7 at 19:54
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53196388%2frails-routes-for-a-static-landing-page-if-user-not-logged-in-devise%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown