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?
views:
652answers:
2
+4
A:
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
Barry Gallagher
2009-07-03 20:42:01
Thanks. So this would require the index.html.erb page to exist in the views folder associated with a particular controller - I have to move it out of the public folder where my current index.html file is?
parlia
2009-07-03 20:47:02
Yup. I should have mentioned that you must delete the default index.html file out of your public folder before the change I listed above will take effect :)
Barry Gallagher
2009-07-03 20:56:36
+1
A:
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'
Michael Sofaer
2009-07-03 20:58:03