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









share|improve this question


























    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









    share|improve this question
























      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









      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 at 19:22









      JP89

      7418




      7418
























          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.





          share|improve this answer





















          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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

























          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.





          share|improve this answer





















          • 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















          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.





          share|improve this answer





















          • 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













          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.





          share|improve this answer












          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.






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini