Saturday, August 16, 2008

Controlling what your homepage shows

Your home page is (say): http://www.something.com/, and you want this home page to show some meaningful dynamic output, rather than a static output.
Dynamic output comes from calling a controller (say, "product") and action (say "listall"). To do this, first rename your index.html file (public/index.html). If you don't, rails will display the index.html file by default.
Next, open your routes.rb file (config/routes.rb) and add the following line:

map.connect ' ', :controller => "product", :action => "listall"

This will ensure that the home page will show the output of action "listall" in controller "product".

No comments: