0
votes

Rails default localhost:3000 mapped to welcome_controller#index page, i want to use my custom landing page in the root. am also using devise for authentication set up.

when i give localhost:3000 devise automatically redirects to localhost:3000/users/sign_in.

how to change the root for custom page and where to place the index.html file so that can see the landing page.

1
Mani, try my answer and let me know if you have any question. - K M Rakibul Islam

1 Answers

0
votes

You can add this to the top of your routes.rb file:

get "/" => "custom_controller#custom_action", as: :custom_root_path

which will give you this route:

custom_root_path   GET      /     custom_controller#custom_action

Then, you can just put the contents of your custom landing page in the corresponding view (custom_action.html.erb file) of the custom_controller's custom_action.

For example, if you name your custom controller as landing_pages_controller and the action is index, then the route will be:

get "/" => "landing_pages#index", as: :custom_root_path

Then, you will have a index method in your landing_pages_controller.rb file and will have a app/views/landing_pages/index.html.erb file where you can put the contents of your custom landing page.