23.3 Helpers for Formatting, Linking, and Pagination 21 Action Controller: Routing and URLs
ls app/controllers/*_controller.rb
app/controllers/admin_controller.rb
app/controllers/application_controller.rb
app/controllers/info_controller.rb
app/controllers/line_items_controller.rb
app/controllers/orders_controller.rb
app/controllers/products_controller.rb
app/controllers/store_controller.rb
app/controllers/users_controller.rb
irb e1/routing/config2/routes_for_depot.rb
Switch to inspect mode.
>> require "./config/environment.rb"
=> true
>> ActionController::Base.session_store = nil
=> nil
>> ActionController::Routing.use_controllers! ["store", "admin", "coupon"]
=> ["store", "admin", "coupon"]
>> load "config/routes.rb"
=> []
>> rs = ActionController::Routing::Routes
=> #<ActionController::Routing::RouteSet:0x8861520 @configuration_files=["/home/rubys/git/awdwr/work-192-236/depot/config/routes.rb"], @routes=[GET /users(.:format)? {:controller=>"users", :action=>"index"}, POST /users(.:format)? {:controller=>"users", :action=>"create"}, GET /users/new(.:format)? {:controller=>"users", :action=>"new"}, GET /users/:id/edit(.:format)? {:controller=>"users", :action=>"edit"}, GET /users/:id(.:format)? {:controller=>"users", :action=>"show"}, PUT /users/:id(.:format)? {:controller=>"users", :action=>"update"}, DELETE /users/:id(.:format)? {:controller=>"users", :action=>"destroy"}, GET /line_items(.:format)? {:controller=>"line_items", :action=>"index"}, POST /line_items(.:format)? {:controller=>"line_items", :action=>"create"}, GET /line_items/new(.:format)? {:controller=>"line_items", :action=>"new"}, GET /line_items/:id/edit(.:format)? {:controller=>"line_items", :action=>"edit"}, GET /line_items/:id(.:format)? {:controller=>"line_items", :action=>"show"}, PUT /line_items/:id(.:format)? {:controller=>"line_items", :action=>"update"}, DELETE /line_items/:id(.:format)? {:controller=>"line_items", :action=>"destroy"}, GET /orders(.:format)? {:controller=>"orders", :action=>"index"}, POST /orders(.:format)? {:controller=>"orders", :action=>"create"}, GET /orders/new(.:format)? {:controller=>"orders", :action=>"new"}, GET /orders/:id/edit(.:format)? {:controller=>"orders", :action=>"edit"}, GET /orders/:id(.:format)? {:controller=>"orders", :action=>"show"}, PUT /orders/:id(.:format)? {:controller=>"orders", :action=>"update"}, DELETE /orders/:id(.:format)? {:controller=>"orders", :action=>"destroy"}, GET /products(.:format)? {:controller=>"products", :action=>"index"}, POST /products(.:format)? {:controller=>"products", :action=>"create"}, GET /products/new(.:format)? {:controller=>"products", :action=>"new"}, GET /products/:id/edit(.:format)? {:controller=>"products", :action=>"edit"}, GET /products/:id(.:format)? {:controller=>"products", :action=>"show"}, PUT /products/:id(.:format)? {:controller=>"products", :action=>"update"}, DELETE /products/:id(.:format)? {:controller=>"products", :action=>"destroy"}, ANY /:controller/:action/:id/ {}, ANY /:controller/:action/:id(.:format)? {}, GET /users(.:format)? {:controller=>"users", :action=>"index"}, POST /users(.:format)? {:controller=>"users", :action=>"create"}, GET /users/new(.:format)? {:controller=>"users", :action=>"new"}, GET /users/:id/edit(.:format)? {:controller=>"users", :action=>"edit"}, GET /users/:id(.:format)? {:controller=>"users", :action=>"show"}, PUT /users/:id(.:format)? {:controller=>"users", :action=>"update"}, DELETE /users/:id(.:format)? {:controller=>"users", :action=>"destroy"}, GET /line_items(.:format)? {:controller=>"line_items", :action=>"index"}, POST /line_items(.:format)? {:controller=>"line_items", :action=>"create"}, GET /line_items/new(.:format)? {:controller=>"line_items", :action=>"new"}, GET /line_items/:id/edit(.:format)? {:controller=>"line_items", :action=>"edit"}, GET /line_items/:id(.:format)? {:controller=>"line_items", :action=>"show"}, PUT /line_items/:id(.:format)? {:controller=>"line_items", :action=>"update"}, DELETE /line_items/:id(.:format)? {:controller=>"line_items", :action=>"destroy"}, GET /orders(.:format)? {:controller=>"orders", :action=>"index"}, POST /orders(.:format)? {:controller=>"orders", :action=>"create"}, GET /orders/new(.:format)? {:controller=>"orders", :action=>"new"}, GET /orders/:id/edit(.:format)? {:controller=>"orders", :action=>"edit"}, GET /orders/:id(.:format)? {:controller=>"orders", :action=>"show"}, PUT /orders/:id(.:format)? {:controller=>"orders", :action=>"update"}, DELETE /orders/:id(.:format)? {:controller=>"orders", :action=>"destroy"}, GET /products(.:format)? {:controller=>"products", :action=>"index"}, POST /products(.:format)? {:controller=>"products", :action=>"create"}, GET /products/new(.:format)? {:controller=>"products", :action=>"new"}, GET /products/:id/edit(.:format)? {:controller=>"products", :action=>"edit"}, GET /products/:id(.:format)? {:controller=>"products", :action=>"show"}, PUT /products/:id(.:format)? {:controller=>"products", :action=>"update"}, DELETE /products/:id(.:format)? {:controller=>"products", :action=>"destroy"}, ANY /:controller/:action/:id/ {}, ANY /:controller/:action/:id(.:format)? {}], @named_routes=#<ActionController::Routing::RouteSet::NamedRouteCollection:0x88614d0 @routes={:users=>GET /users(.:format)? {:controller=>"users", :action=>"index"}, :new_user=>GET /users/new(.:format)? {:controller=>"users", :action=>"new"}, :edit_user=>GET /users/:id/edit(.:format)? {:controller=>"users", :action=>"edit"}, :user=>GET /users/:id(.:format)? {:controller=>"users", :action=>"show"}, :line_items=>GET /line_items(.:format)? {:controller=>"line_items", :action=>"index"}, :new_line_item=>GET /line_items/new(.:format)? {:controller=>"line_items", :action=>"new"}, :edit_line_item=>GET /line_items/:id/edit(.:format)? {:controller=>"line_items", :action=>"edit"}, :line_item=>GET /line_items/:id(.:format)? {:controller=>"line_items", :action=>"show"}, :orders=>GET /orders(.:format)? {:controller=>"orders", :action=>"index"}, :new_order=>GET /orders/new(.:format)? {:controller=>"orders", :action=>"new"}, :edit_order=>GET /orders/:id/edit(.:format)? {:controller=>"orders", :action=>"edit"}, :order=>GET /orders/:id(.:format)? {:controller=>"orders", :action=>"show"}, :products=>GET /products(.:format)? {:controller=>"products", :action=>"index"}, :new_product=>GET /products/new(.:format)? {:controller=>"products", :action=>"new"}, :edit_product=>GET /products/:id/edit(.:format)? {:controller=>"products", :action=>"edit"}, :product=>GET /products/:id(.:format)? {:controller=>"products", :action=>"show"}}, @helpers=[:hash_for_users_url, :users_url, :hash_for_users_path, :users_path, :hash_for_new_user_url, :new_user_url, :hash_for_new_user_path, :new_user_path, :hash_for_edit_user_url, :edit_user_url, :hash_for_edit_user_path, :edit_user_path, :hash_for_user_url, :user_url, :hash_for_user_path, :user_path, :hash_for_line_items_url, :line_items_url, :hash_for_line_items_path, :line_items_path, :hash_for_new_line_item_url, :new_line_item_url, :hash_for_new_line_item_path, :new_line_item_path, :hash_for_edit_line_item_url, :edit_line_item_url, :hash_for_edit_line_item_path, :edit_line_item_path, :hash_for_line_item_url, :line_item_url, :hash_for_line_item_path, :line_item_path, :hash_for_orders_url, :orders_url, :hash_for_orders_path, :orders_path, :hash_for_new_order_url, :new_order_url, :hash_for_new_order_path, :new_order_path, :hash_for_edit_order_url, :edit_order_url, :hash_for_edit_order_path, :edit_order_path, :hash_for_order_url, :order_url, :hash_for_order_path, :order_path, :hash_for_products_url, :products_url, :hash_for_products_path, :products_path, :hash_for_new_product_url, :new_product_url, :hash_for_new_product_path, :new_product_path, :hash_for_edit_product_url, :edit_product_url, :hash_for_edit_product_path, :edit_product_path, :hash_for_product_url, :product_url, :hash_for_product_path, :product_path], @module=#<Module:0x8861444>>, @combined_regexp=nil, @routes_by_controller=nil, @builder=#<ActionController::Routing::RouteBuilder:0x8bb3cdc @separators=["/", ".", "?"], @optional_separators=["/"], @separator_regexp=/[\/\.\?]/, @nonseparator_regexp=/\A([^\/\.\?]+)/, @interval_regexp=/(.*?)((?-mix:[\/\.\?])|$)/>, @routes_last_modified=2010-05-24 06:27:06 -0400>
>> app = ActionController::Integration::Session.new
=> #<ActionController::Integration::Session:0x99ca21c @application=#<ActionController::Dispatcher:0x99ca1cc @output=#<IO:<STDOUT>>>, @headers=nil, @path=nil, @status=nil, @status_message=nil, @result=nil, @https=false, @cookies={}, @response=nil, @request=nil, @controller=nil, @request_count=0, @host="www.example.com", @remote_addr="127.0.0.1", @accept="text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", @named_routes_configured=true>
>> puts rs.routes
GET /users(.:format)? {:controller=>"users", :action=>"index"}
POST /users(.:format)? {:controller=>"users", :action=>"create"}
GET /users/new(.:format)? {:controller=>"users", :action=>"new"}
GET /users/:id/edit(.:format)? {:controller=>"users", :action=>"edit"}
GET /users/:id(.:format)? {:controller=>"users", :action=>"show"}
PUT /users/:id(.:format)? {:controller=>"users", :action=>"update"}
DELETE /users/:id(.:format)? {:controller=>"users", :action=>"destroy"}
GET /line_items(.:format)? {:controller=>"line_items", :action=>"index"}
POST /line_items(.:format)? {:controller=>"line_items", :action=>"create"}
GET /line_items/new(.:format)? {:controller=>"line_items", :action=>"new"}
GET /line_items/:id/edit(.:format)? {:controller=>"line_items", :action=>"edit"}
GET /line_items/:id(.:format)? {:controller=>"line_items", :action=>"show"}
PUT /line_items/:id(.:format)? {:controller=>"line_items", :action=>"update"}
DELETE /line_items/:id(.:format)? {:controller=>"line_items", :action=>"destroy"}
GET /orders(.:format)? {:controller=>"orders", :action=>"index"}
POST /orders(.:format)? {:controller=>"orders", :action=>"create"}
GET /orders/new(.:format)? {:controller=>"orders", :action=>"new"}
GET /orders/:id/edit(.:format)? {:controller=>"orders", :action=>"edit"}
GET /orders/:id(.:format)? {:controller=>"orders", :action=>"show"}
PUT /orders/:id(.:format)? {:controller=>"orders", :action=>"update"}
DELETE /orders/:id(.:format)? {:controller=>"orders", :action=>"destroy"}
GET /products(.:format)? {:controller=>"products", :action=>"index"}
POST /products(.:format)? {:controller=>"products", :action=>"create"}
GET /products/new(.:format)? {:controller=>"products", :action=>"new"}
GET /products/:id/edit(.:format)? {:controller=>"products", :action=>"edit"}
GET /products/:id(.:format)? {:controller=>"products", :action=>"show"}
PUT /products/:id(.:format)? {:controller=>"products", :action=>"update"}
DELETE /products/:id(.:format)? {:controller=>"products", :action=>"destroy"}
ANY /:controller/:action/:id/ {}
ANY /:controller/:action/:id(.:format)? {}
GET /users(.:format)? {:controller=>"users", :action=>"index"}
POST /users(.:format)? {:controller=>"users", :action=>"create"}
GET /users/new(.:format)? {:controller=>"users", :action=>"new"}
GET /users/:id/edit(.:format)? {:controller=>"users", :action=>"edit"}
GET /users/:id(.:format)? {:controller=>"users", :action=>"show"}
PUT /users/:id(.:format)? {:controller=>"users", :action=>"update"}
DELETE /users/:id(.:format)? {:controller=>"users", :action=>"destroy"}
GET /line_items(.:format)? {:controller=>"line_items", :action=>"index"}
POST /line_items(.:format)? {:controller=>"line_items", :action=>"create"}
GET /line_items/new(.:format)? {:controller=>"line_items", :action=>"new"}
GET /line_items/:id/edit(.:format)? {:controller=>"line_items", :action=>"edit"}
GET /line_items/:id(.:format)? {:controller=>"line_items", :action=>"show"}
PUT /line_items/:id(.:format)? {:controller=>"line_items", :action=>"update"}
DELETE /line_items/:id(.:format)? {:controller=>"line_items", :action=>"destroy"}
GET /orders(.:format)? {:controller=>"orders", :action=>"index"}
POST /orders(.:format)? {:controller=>"orders", :action=>"create"}
GET /orders/new(.:format)? {:controller=>"orders", :action=>"new"}
GET /orders/:id/edit(.:format)? {:controller=>"orders", :action=>"edit"}
GET /orders/:id(.:format)? {:controller=>"orders", :action=>"show"}
PUT /orders/:id(.:format)? {:controller=>"orders", :action=>"update"}
DELETE /orders/:id(.:format)? {:controller=>"orders", :action=>"destroy"}
GET /products(.:format)? {:controller=>"products", :action=>"index"}
POST /products(.:format)? {:controller=>"products", :action=>"create"}
GET /products/new(.:format)? {:controller=>"products", :action=>"new"}
GET /products/:id/edit(.:format)? {:controller=>"products", :action=>"edit"}
GET /products/:id(.:format)? {:controller=>"products", :action=>"show"}
PUT /products/:id(.:format)? {:controller=>"products", :action=>"update"}
DELETE /products/:id(.:format)? {:controller=>"products", :action=>"destroy"}
ANY /:controller/:action/:id/ {}
ANY /:controller/:action/:id(.:format)? {}
=> nil
>> rs.recognize_path "/store"
=> {:controller=>"store", :action=>"index"}
>> rs.recognize_path "/store/add_to_cart/1"
=> {:controller=>"store", :action=>"add_to_cart", :id=>"1"}
>> rs.recognize_path "/store/add_to_cart/1.xml"
=> {:controller=>"store", :action=>"add_to_cart", :id=>"1", :format=>"xml"}
>> rs.generate :controller => :store
=> "/store"
>> rs.generate :controller => :store, :id => 123
=> "/store/index/123"
>> rs.recognize_path "/coupon/show/1"
=> {:controller=>"coupon", :action=>"show", :id=>"1"}
>> load "config/routes.rb"
=> []
>> rs.recognize_path "/coupon/show/1"
=> {:controller=>"coupon", :action=>"show", :id=>"1"}
>> app.url_for :controller => :store, :action => :display, :id => 123
=> "http://www.example.com/store/display/123"
ruby -rubygems /home/rubys/git/rails/railties/bin/rails view
create
create app/controllers
create app/helpers
create app/models
create app/views/layouts
create config/environments
create config/initializers
create config/locales
create db
create doc
create lib
create lib/tasks
create log
create public/images
create public/javascripts
create public/stylesheets
create script/performance
create test/fixtures
create test/functional
create test/integration
create test/performance
create test/unit
create vendor
create vendor/plugins
create tmp/sessions
create tmp/sockets
create tmp/cache
create tmp/pids
create Rakefile
create README
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create config/database.yml
create config/routes.rb
create config/locales/en.yml
create db/seeds.rb
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/new_rails_defaults.rb
create config/initializers/session_store.rb
create config/initializers/cookie_verification_secret.rb
create config/environment.rb
create config/boot.rb
create config/environments/production.rb
create config/environments/development.rb
create config/environments/test.rb
create script/about
create script/console
create script/dbconsole
create script/destroy
create script/generate
create script/runner
create script/server
create script/plugin
create script/performance/benchmarker
create script/performance/profiler
create test/test_helper.rb
create test/performance/browsing_test.rb
create public/404.html
create public/422.html
create public/500.html
create public/index.html
create public/favicon.ico
create public/robots.txt
create public/images/rails.png
create public/javascripts/prototype.js
create public/javascripts/effects.js
create public/javascripts/dragdrop.js
create public/javascripts/controls.js
create public/javascripts/application.js
create doc/README_FOR_APP
create log/server.log
create log/production.log
create log/development.log
create log/test.log
cp -v /home/rubys/git/awdwr/data/code/e1/views/app/controllers/*.rb app/controllers
`/home/rubys/git/awdwr/data/code/e1/views/app/controllers/array_controller.rb' -> `app/controllers/array_controller.rb'
`/home/rubys/git/awdwr/data/code/e1/views/app/controllers/article_controller.rb' -> `app/controllers/article_controller.rb'
`/home/rubys/git/awdwr/data/code/e1/views/app/controllers/blog1_controller.rb' -> `app/controllers/blog1_controller.rb'
`/home/rubys/git/awdwr/data/code/e1/views/app/controllers/blog2_controller.rb' -> `app/controllers/blog2_controller.rb'
`/home/rubys/git/awdwr/data/code/e1/views/app/controllers/blog_controller.rb' -> `app/controllers/blog_controller.rb'
`/home/rubys/git/awdwr/data/code/e1/views/app/controllers/builder_controller.rb' -> `app/controllers/builder_controller.rb'
`/home/rubys/git/awdwr/data/code/e1/views/app/controllers/form_controller.rb' -> `app/controllers/form_controller.rb'
`/home/rubys/git/awdwr/data/code/e1/views/app/controllers/form_for_controller.rb' -> `app/controllers/form_for_controller.rb'
`/home/rubys/git/awdwr/data/code/e1/views/app/controllers/pager_controller.rb' -> `app/controllers/pager_controller.rb'
`/home/rubys/git/awdwr/data/code/e1/views/app/controllers/partial_controller.rb' -> `app/controllers/partial_controller.rb'
`/home/rubys/git/awdwr/data/code/e1/views/app/controllers/products_controller.rb' -> `app/controllers/products_controller.rb'
`/home/rubys/git/awdwr/data/code/e1/views/app/controllers/rhtml_controller.rb' -> `app/controllers/rhtml_controller.rb'
`/home/rubys/git/awdwr/data/code/e1/views/app/controllers/test_controller.rb' -> `app/controllers/test_controller.rb'
`/home/rubys/git/awdwr/data/code/e1/views/app/controllers/upload_controller.rb' -> `app/controllers/upload_controller.rb'
irb e1/routing/config2/routes_for_blog.rb
Switch to inspect mode.
>> require 'rubygems'
=> false
>> require 'action_controller'
=> true
>> ActionController::Base.session_store = nil
=> nil
>> ActionController::Routing.use_controllers! [ "article", "blog" ]
=> ["article", "blog"]
>> rs = ActionController::Routing::Routes
=> #<ActionController::Routing::RouteSet:0x8e451a8 @configuration_files=[], @routes=[], @named_routes=#<ActionController::Routing::RouteSet::NamedRouteCollection:0x8e4516c @routes={}, @helpers=[], @module=#<Module:0x8e45130>>>
>> app = ActionController::Integration::Session.new
=> #<ActionController::Integration::Session:0x85b8cb0 @application=#<ActionController::Dispatcher:0x8472ff4 @output=#<IO:<STDOUT>>, @app=#<Rack::Lock:0x824f768 @app=#<ActionController::Failsafe:0x824fb8c @app=#<ActionController::ParamsParser:0x824fd08 @app=#<Rack::MethodOverride:0x824ff4c @app=#<Rack::Head:0x8250528 @app=#<ActionController::StringCoercion:0x8250848 @app=#<Proc:0x8472f90@/home/rubys/git/awdwr/work-192-236/view/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:130 (lambda)>>>>>>, @lock=#<Mutex:0x824f754>>>, @headers=nil, @path=nil, @status=nil, @status_message=nil, @result=nil, @https=false, @cookies={}, @response=nil, @request=nil, @controller=nil, @request_count=0, @host="www.example.com", @remote_addr="127.0.0.1", @accept="text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", @named_routes_configured=true>
?> ActionController::Routing::Routes.draw do |map|
?> # Straight 'http://my.app/blog/' displays the index
?> map.connect "blog/",
?> :controller => "blog",
?> :action => "index"
?> # Return articles for a year, year/month, or year/month/day
?> map.connect "blog/:year/:month/:day",
?> :controller => "blog",
?> :action => "show_date",
?> :requirements => { :year => /(19|20)\d\d/,
?> :month => /[01]?\d/,
?> :day => /[0-3]?\d/},
?> :day => nil,
?> :month => nil
>> # Show an article identified by an id
?> map.connect "blog/show/:id",
?> :controller => "blog",
?> :action => "show",
?> :id => /\d+/
>> # Regular Rails routing for admin stuff
?> map.connect "blog/:controller/:action/:id"
>> # Catchall so we can gracefully handle badly formed requests
?> map.connect "*anything",
?> :controller => "blog",
?> :action => "unknown_request"
>> end
=> [ActionController::Base, ActionView::Base]
>> rs.recognize_path "/blog"
=> {:controller=>"blog", :action=>"index"}
>> rs.recognize_path "/blog/show/123"
=> {:controller=>"blog", :action=>"show", :id=>"123"}
>> rs.recognize_path "/blog/2004"
=> {:controller=>"blog", :action=>"show_date", :year=>"2004"}
>> rs.recognize_path "/blog/2004/12"
=> {:controller=>"blog", :action=>"show_date", :year=>"2004", :month=>"12"}
>> rs.recognize_path "/blog/2004/12/25"
=> {:controller=>"blog", :action=>"show_date", :year=>"2004", :month=>"12", :day=>"25"}
>> rs.recognize_path "/blog/article/edit/123"
=> {:controller=>"article", :action=>"edit", :id=>"123"}
>> rs.recognize_path "/blog/article/show_stats"
=> {:controller=>"article", :action=>"show_stats"}
>> rs.recognize_path "/blog/wibble"
=> {:controller=>"blog", :action=>"unknown_request", :anything=>["blog", "wibble"]}
>> rs.recognize_path "/junk"
=> {:controller=>"blog", :action=>"unknown_request", :anything=>["junk"]}
>> last_request = rs.recognize_path "/blog/2006/07/28"
=> {:controller=>"blog", :action=>"show_date", :year=>"2006", :month=>"07", :day=>"28"}
>> rs.generate({:day => 25}, last_request)
=> "/blog/2006/07/25"
>> rs.generate({:year => 2005}, last_request)
=> "/blog/2005"
>> app.url_for :controller => 'blog', :action => 'show_date', :year => 2002
=> "http://www.example.com/blog/2002"
>> app.url_for :controller => 'blog', :action => 'show_date', :overwrite_params => {:year => "2002" }
DEPRECATION WARNING: The :overwrite_params option is deprecated. Specify all the necessary parameters instead. (called from url_for at /home/rubys/git/awdwr/work-192-236/view/vendor/rails/actionpack/lib/action_controller/integration.rb:244)
=> "http://www.example.com/blog/2002"
23.3 Helpers for Formatting, Linking, and Pagination 21 Action Controller: Routing and URLs