Redirect from old domain to new one (SEO friendly)

In your controller action:

redirect_to "http://new.com#{request.request_uri}", :status => 301

However, Heroku has what may be a slightly better option for you documented in their dev center:

class ApplicationController
  before_filter :ensure_domain

  APP_DOMAIN = 'myapp.mydomain.com'

  def ensure_domain
    if request.env['HTTP_HOST'] != APP_DOMAIN
      # HTTP 301 is a "permanent" redirect
      redirect_to "http://#{APP_DOMAIN}#{request.request_uri}", :status => 301
    end
  end
end

Put this in a before filter in the ApplicationControlller:

class ApplicationController
  before_action :redirect_if_old

  protected

  def redirect_if_old
    if request.host == 'old.com'
      redirect_to "#{request.protocol}new.com#{request.fullpath}", :status => :moved_permanently 
    end
  end
end