Rails 3 Controller: Difference between revisions
Jump to navigation
Jump to search
Created page with '== Routes == defined in <code>config/routes.rb</code>: <pre> match ':controller(/:action(/:id(.:format)))' # default route, :id and :format may be accessed as parameters in the …' |
|||
Line 7: | Line 7: | ||
match '/teams/search/:query' => 'teams#search', :as => 'search' # named route, defines search_url and search_path methods | match '/teams/search/:query' => 'teams#search', :as => 'search' # named route, defines search_url and search_path methods | ||
</pre> | </pre> | ||
< | <pre> | ||
search_url gives http://example.com/teams/search | |||
search_path gives /teams/search | |||
</pre> | |||
useful in something like | useful in something like | ||
<source lang="ruby"> | <source lang="ruby"> | ||
link_to "Search", search_path | link_to "Search", search_path | ||
</source> | </source> |
Revision as of 21:26, 30 June 2011
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