Rails 3 Controller

From Wiki
Revision as of 21:26, 30 June 2011 by Scott (talk | contribs) (Routes)
Jump to navigation Jump to search

Routes

defined in config/routes.rb:

match ':controller(/:action(/:id(.:format)))'  # default route, :id and :format may be accessed as parameters in the action
match '/teams/home' => 'teams#index'           # call index action of teams controller
match '/teams/search/:query' => 'teams#search' # sends :query parameter to search action in teams controller
match '/teams/search/:query' => 'teams#search', :as => 'search'  # named route, defines search_url and search_path methods
search_url gives http://example.com/teams/search
search_path gives /teams/search

useful in something like

link_to "Search", search_path