Reputation: 37
My index.html
page for my project needs some Ruby code so I need to change it to a .erb
extension. How do I configure Rails to identify the index.html.erb
file as the starting page of the project instead of the index.html
file?
Upvotes: 3
Views: 5759
Reputation: 13
Or you could do root to:
config/routes.rb
root to: 'index.html.erb'
Be sure to delete index.html file
Upvotes: 1
Reputation: 7674
The answers here are now outdated. Assuming the index.html.erb
file is under a controller and a view called patients.
In rails 3 you would do it like this:
match "/" => "patients#index"
Upvotes: 0
Reputation: 2947
public/index.html is a flat file, and doesn't go through any templating (everything in /public/ is like this.)
If you want templating on your index page, you need to run the request through a controller and a view. You can map the root URL of your application to a controller with map.root:
map.root :controller => 'home'
Upvotes: 2
Reputation: 6246
You need to configure the map.root
path in your config/routes.rb
file.
map.root :controller => "blogs"
# This would recognize http://www.example.com/ as
params = { :controller => 'blogs', :action => 'index' }
# and provide these named routes
root_url # => 'http://www.example.com/'
root_path # => ''
http://api.rubyonrails.org/classes/ActionController/Routing.html
Upvotes: 6