Setting the Default Root
Typing http://127.0.0.1:3000/photos or http://localhost:3000/photos is getting tedious. It would be easier to use http://127.0.0.1:3000/ and be directed to whatever page you want to designate as the starting page. You already know how Rails specifies routes. Edit config/routes.rb and find this section of comments:
# You can have the root of your site routed with map.root -- # just remember to delete public/index.html. # map.root :controller => "welcome"
Now, uncomment the last line and change it to:
map.root :controller => "photos"
With this new routing rule, anytime Rails sees an empty URL
(represented by the '' parameter), it
will invoke the index action in the
photos controller. Before this change
will work, you need to delete the public/index.html
file. If you don’t, the web server will serve up
public/index.html instead of
app/views/photos/index.html.erb whenever you browse
to http://127.0.0.1:3000/. Because the
index.html is static, Rails will never get
called.
Now, try browsing to http://127.0.0.1:3000/; you should see a nice new photos/index page, complete with thumbnails and navigation bar.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access