Redirect root url to somewhere else in Rails application Redirect root url to somewhere else in Rails application ruby-on-rails ruby-on-rails

Redirect root url to somewhere else in Rails application


In Rails 3 you can write:

root :to => redirect('/prepayments')

The following page has a good introduction to doing these redirects in Rails 3: http://www.railsdispatch.com/posts/rails-routing


redirect options don't seem to be documented too well.
here you go (@derek, see last example):

redirect to a subdomain on the current request's domain

root to: redirect(subdomain: 'foo', path: '/bar') # => foo.example.com/bar

redirect with substituted params from the matched route

get 'stores/:name(*all)', to: redirect(subdomain: 'stores', path: '/%{name}%{all}')

redirect with status code (eg. 302 instead of default 301)

redirect(path: '/foo', status: 302)

redirect with a conditional block

redirect(status: 302) { |params, request|  case request.host  when 'localhost'    '/foo'  when /example.com$/    '/bar'  else    '/baz'  end}


In Rails 4 (4.2.0 in my case), I added this: match "*path" => "main#index", :via => [:get, :post] to app/config/routes.rb.

To find out what you are supposed to put in place of main. Look in this file: app/controllers/main_controller.rb. Again, yours may not be called main_controller.rb, but it will be something_controller.rb, probably NOT application_controller.rb or servers_controller.rb. In that file, you'll see some code that looks like this:

class MainController < ApplicationController  def index    render :layout => "angular"  endend

Where there is MainController, you should be able to tell by the error message that rails provides in your browser what to do from here. Just replace main in match "*path" => "main#index", :via => [:get, :post] with whatever the prefix of the controller is.

Hope this makes sense. I am a ruby beginner as well