Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I redirect to root - public/index.html?

I wish to do a redirection to index.html in my application/public folder.

def get_current_user    @current_user = current_user    if @current_user.nil?         redirect_to root_path    end  end 

How do I achieve this ?

I haven't modified the root in my routes.rb ( Its still commented )

 # root :to => "welcome#index" 

I get an error saying root_path is undefined.

How do I modify routes.rb so that root_path points to public/index.html ?

like image 552
geeky_monster Avatar asked Jun 06 '11 20:06

geeky_monster


1 Answers

You can assign a named route to a static file by passing any non-empty string as :controller and the path to the file as the :action for the route:

Application.routes.draw do    root :controller => 'static', :action => '/'    # or   # root :controller => 'static', :action => '/public/index.html'  end  # elsewhere  redirect_to root_path # redirect to / 

Assuming you have a public/index.html, this is what will be served.

like image 80
meagar Avatar answered Oct 05 '22 01:10

meagar