aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-12-22 03:16:50 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-12-22 03:16:50 +0000
commit68d2926ab09d49086eb4101c53d8ae604bd4b334 (patch)
tree7cc5e4debdb46b4ec5578046a274a63a8bb8008b /actionpack/lib
parenta1ca37ec8659800e5620630490ee8fa46bb3a217 (diff)
downloadrails-68d2926ab09d49086eb4101c53d8ae604bd4b334.tar.gz
rails-68d2926ab09d49086eb4101c53d8ae604bd4b334.tar.bz2
rails-68d2926ab09d49086eb4101c53d8ae604bd4b334.zip
Singleton resources: POST /singleton => create, GET /singleton/new => new
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5772 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/resources.rb55
1 files changed, 31 insertions, 24 deletions
diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb
index a6ab9dcdba..94f944f842 100644
--- a/actionpack/lib/action_controller/resources.rb
+++ b/actionpack/lib/action_controller/resources.rb
@@ -68,27 +68,13 @@ module ActionController
class SingletonResource < Resource #:nodoc:
def initialize(entity, options)
- @singular = entity
- @plural = options[:plural] || singular.to_s.pluralize
-
- @options = options
+ @plural = @singular = entity
+ @options = options
arrange_actions
add_default_actions
set_prefixes
end
- def controller
- @controller ||= (options[:controller] || singular).to_s
- end
-
- def path
- @path ||= "#{path_prefix}/#{singular}"
- end
-
- def new_path
- nil
- end
-
alias_method :member_path, :path
alias_method :nesting_path_prefix, :path
end
@@ -251,27 +237,37 @@ module ActionController
# map.resource :account
#
# class AccountController < ActionController::Base
+ # # POST account_url
+ # def create
+ # # create an account
+ # end
+ #
+ # # GET new_account_url
+ # def new
+ # # return an HTML form for describing the new account
+ # end
+ #
# # GET account_url
# def show
- # # find and return a specific message
+ # # find and return the account
# end
- #
+ #
# # GET edit_account_url
# def edit
- # # return an HTML form for editing a specific message
+ # # return an HTML form for editing the account
# end
- #
+ #
# # PUT account_url
# def update
- # # find and update a specific message
+ # # find and update the account
# end
- #
+ #
# # DELETE account_url
# def destroy
- # # delete a specific message
+ # # delete the account
# end
# end
- #
+ #
# Along with the routes themselves, #resource generates named routes for use in
# controllers and views. <tt>map.resource :account</tt> produces the following named routes and helpers:
#
@@ -291,6 +287,7 @@ module ActionController
with_options :controller => resource.controller do |map|
map_collection_actions(map, resource)
+ map_default_collection_actions(map, resource)
map_new_actions(map, resource)
map_member_actions(map, resource)
@@ -304,6 +301,9 @@ module ActionController
resource = SingletonResource.new(entities, options)
with_options :controller => resource.controller do |map|
+ map_collection_actions(map, resource)
+ map_default_singleton_actions(map, resource)
+ map_new_actions(map, resource)
map_member_actions(map, resource)
if block_given?
@@ -330,7 +330,9 @@ module ActionController
)
end
end
+ end
+ def map_default_collection_actions(map, resource)
map.named_route("#{resource.name_prefix}#{resource.plural}", resource.path, :action => "index", :conditions => { :method => :get })
map.named_route("formatted_#{resource.name_prefix}#{resource.plural}", "#{resource.path}.:format", :action => "index", :conditions => { :method => :get })
@@ -338,6 +340,11 @@ module ActionController
map.connect("#{resource.path}.:format", :action => "create", :conditions => { :method => :post })
end
+ def map_default_singleton_actions(map, resource)
+ map.connect(resource.path, :action => "create", :conditions => { :method => :post })
+ map.connect("#{resource.path}.:format", :action => "create", :conditions => { :method => :post })
+ end
+
def map_new_actions(map, resource)
resource.new_methods.each do |method, actions|
route_options = requirements_for(method)