1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Scaffolding generates new routing dsl examples

This commit is contained in:
Joshua Peek 2009-12-09 18:57:16 -06:00
parent f9d570bdd8
commit 0fec53f243
8 changed files with 47 additions and 30 deletions

View file

@ -1,43 +1,60 @@
ActionController::Routing::Routes.draw do |map| ActionController::Routing::Routes.draw do |map|
# The priority is based upon order of creation: first created -> highest priority. # The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route: # Sample of regular route:
# map.connect 'products/:id', :controller => 'catalog', :action => 'view' # match 'products/:id', :to => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action # Keep in mind you can assign values other than :controller and :action
# Sample of named route: # Sample of named route:
# map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase' # match 'products/:id/purchase', :to => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id) # This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically): # Sample resource route (maps HTTP verbs to controller actions automatically):
# map.resources :products # resources :products
# Sample resource route with options: # Sample resource route with options:
# map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get } # resources :products do
# member do
# get :short
# post :toggle
# end
#
# collection do
# get :sold
# end
# end
# Sample resource route with sub-resources: # Sample resource route with sub-resources:
# map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller # resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources # Sample resource route with more complex sub-resources
# map.resources :products do |products| # resources :products do
# products.resources :comments # resources :comments
# products.resources :sales, :collection => { :recent => :get } # resources :sales do
# get :recent, :on => :collection
# end
# end # end
# Sample resource route within a namespace: # Sample resource route within a namespace:
# map.namespace :admin do |admin| # namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb) # # Directs /admin/products/* to Admin::ProductsController
# admin.resources :products # # (app/controllers/admin/products_controller.rb)
# resources :products
# end # end
# You can have the root of your site routed with map.root -- just remember to delete public/index.html. # You can have the root of your site routed with map.root
# map.root :controller => "welcome" # just remember to delete public/index.html.
# root :to => "welcome"
# See how all your routes lay out with "rake routes" # See how all your routes lay out with "rake routes"
# Install the default routes as the lowest priority. # Install the default route as the lowest priority.
# Note: These default routes make all actions in every controller accessible via GET requests. You should # Note: The default route make all actions in every controller accessible
# consider removing or commenting them out if you're using named routes and resources. # via GET requests. You should consider removing or commenting it out if
map.connect ':controller/:action/:id' # you're using named routes and resources.
map.connect ':controller/:action/:id.:format' match ':controller(/:action(/:id(.:format)))'
end end

View file

@ -16,7 +16,7 @@ module Rails
class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller" class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
def add_resource_route def add_resource_route
route "map.resource#{:s unless options[:singleton]} :#{pluralize?(file_name)}" route "resource#{:s unless options[:singleton]} :#{pluralize?(file_name)}"
end end
protected protected

View file

@ -17,7 +17,7 @@ Description:
For example, 'scaffold post title:string body:text published:boolean' For example, 'scaffold post title:string body:text published:boolean'
gives you a model with those three attributes, a controller that handles gives you a model with those three attributes, a controller that handles
the create/show/update/destroy, forms to create and edit your posts, and the create/show/update/destroy, forms to create and edit your posts, and
an index that lists them all, as well as a map.resources :posts an index that lists them all, as well as a resources :posts
declaration in config/routes.rb. declaration in config/routes.rb.
If you want to remove all the generated files, run If you want to remove all the generated files, run

View file

@ -1,3 +1,3 @@
ActionController::Routing::Routes.draw do |map| ActionController::Routing::Routes.draw do |map|
map.connect '/engine', :controller => "engine" match '/engine', :to => "engine"
end end

View file

@ -171,7 +171,7 @@ class ActionsTest < GeneratorsTestCase
def test_route_should_add_data_to_the_routes_block_in_config_routes def test_route_should_add_data_to_the_routes_block_in_config_routes
run_generator run_generator
route_command = "map.route '/login', :controller => 'sessions', :action => 'new'" route_command = "route '/login', :controller => 'sessions', :action => 'new'"
action :route, route_command action :route, route_command
assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/ assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/
end end

View file

@ -62,7 +62,7 @@ class ResourceGeneratorTest < GeneratorsTestCase
run_generator run_generator
assert_file "config/routes.rb" do |route| assert_file "config/routes.rb" do |route|
assert_match /map\.resources :accounts$/, route assert_match /resources :accounts$/, route
end end
end end
@ -70,7 +70,7 @@ class ResourceGeneratorTest < GeneratorsTestCase
run_generator ["account", "--singleton"] run_generator ["account", "--singleton"]
assert_file "config/routes.rb" do |route| assert_file "config/routes.rb" do |route|
assert_match /map\.resource :account$/, route assert_match /resource :account$/, route
end end
end end
@ -93,7 +93,7 @@ class ResourceGeneratorTest < GeneratorsTestCase
run_generator ["account"], :behavior => :revoke run_generator ["account"], :behavior => :revoke
assert_file "config/routes.rb" do |route| assert_file "config/routes.rb" do |route|
assert_no_match /map\.resources :accounts$/, route assert_no_match /resources :accounts$/, route
end end
end end

View file

@ -25,7 +25,7 @@ class ScaffoldGeneratorTest < GeneratorsTestCase
# Route # Route
assert_file "config/routes.rb" do |route| assert_file "config/routes.rb" do |route|
assert_match /map\.resources :product_lines$/, route assert_match /resources :product_lines$/, route
end end
# Controller # Controller
@ -99,7 +99,7 @@ class ScaffoldGeneratorTest < GeneratorsTestCase
# Route # Route
assert_file "config/routes.rb" do |route| assert_file "config/routes.rb" do |route|
assert_no_match /map\.resources :product_lines$/, route assert_no_match /resources :product_lines$/, route
end end
# Controller # Controller

View file

@ -16,7 +16,7 @@ class InfoControllerTest < ActionController::TestCase
def setup def setup
ActionController::Routing::Routes.draw do |map| ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id' match ':controller/:action'
end end
@controller.stubs(:consider_all_requests_local => false, :local_request? => true) @controller.stubs(:consider_all_requests_local => false, :local_request? => true)
end end