aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/resources.rb
diff options
context:
space:
mode:
authorTarmo Tänav <tarmo@itech.ee>2009-01-30 13:37:59 +0200
committerMichael Koziarski <michael@koziarski.com>2009-02-01 14:47:56 +1300
commit80747e9db16ec60eb0d95b510baf051612ec0768 (patch)
tree062a879107363bb72d77633473fca803d4afaa47 /actionpack/lib/action_controller/resources.rb
parentec8f04584479aff895b0b511a7ba1e9d33f84067 (diff)
downloadrails-80747e9db16ec60eb0d95b510baf051612ec0768.tar.gz
rails-80747e9db16ec60eb0d95b510baf051612ec0768.tar.bz2
rails-80747e9db16ec60eb0d95b510baf051612ec0768.zip
Removed map.resources :only/:except inheritance
It's very rare for these options to apply identically to nested child resources, and with this inheritance on it's very difficult to have a child resource with more actions than the parent. This reverts commit 2ecec6052f7f290252a9fd9cc27ec804c7aad36c. Signed-off-by: Michael Koziarski <michael@koziarski.com> [#1826 state:committed]
Diffstat (limited to 'actionpack/lib/action_controller/resources.rb')
-rw-r--r--actionpack/lib/action_controller/resources.rb35
1 files changed, 19 insertions, 16 deletions
diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb
index e8988aa737..3af21967df 100644
--- a/actionpack/lib/action_controller/resources.rb
+++ b/actionpack/lib/action_controller/resources.rb
@@ -42,7 +42,7 @@ module ActionController
#
# Read more about REST at http://en.wikipedia.org/wiki/Representational_State_Transfer
module Resources
- INHERITABLE_OPTIONS = :namespace, :shallow, :actions
+ INHERITABLE_OPTIONS = :namespace, :shallow
class Resource #:nodoc:
DEFAULT_ACTIONS = :index, :create, :new, :edit, :show, :update, :destroy
@@ -119,7 +119,7 @@ module ActionController
end
def has_action?(action)
- !DEFAULT_ACTIONS.include?(action) || @options[:actions].nil? || @options[:actions].include?(action)
+ !DEFAULT_ACTIONS.include?(action) || action_allowed?(action)
end
protected
@@ -135,24 +135,29 @@ module ActionController
end
def set_allowed_actions
- only = @options.delete(:only)
- except = @options.delete(:except)
+ only, except = @options.values_at(:only, :except)
+ @allowed_actions ||= {}
- if only && except
- raise ArgumentError, 'Please supply either :only or :except, not both.'
- elsif only == :all || except == :none
- options[:actions] = DEFAULT_ACTIONS
+ if only == :all || except == :none
+ only = nil
+ except = []
elsif only == :none || except == :all
- options[:actions] = []
- elsif only
- options[:actions] = DEFAULT_ACTIONS & Array(only).map(&:to_sym)
+ only = []
+ except = nil
+ end
+
+ if only
+ @allowed_actions[:only] = Array(only).map(&:to_sym)
elsif except
- options[:actions] = DEFAULT_ACTIONS - Array(except).map(&:to_sym)
- else
- # leave options[:actions] alone
+ @allowed_actions[:except] = Array(except).map(&:to_sym)
end
end
+ def action_allowed?(action)
+ only, except = @allowed_actions.values_at(:only, :except)
+ (!only || only.include?(action)) && (!except || !except.include?(action))
+ end
+
def set_prefixes
@path_prefix = options.delete(:path_prefix)
@name_prefix = options.delete(:name_prefix)
@@ -403,8 +408,6 @@ module ActionController
# # --> POST /posts/1/comments (maps to the CommentsController#create action)
# # --> PUT /posts/1/comments/1 (fails)
#
- # The <tt>:only</tt> and <tt>:except</tt> options are inherited by any nested resource(s).
- #
# If <tt>map.resources</tt> is called with multiple resources, they all get the same options applied.
#
# Examples: