diff options
author | Jamis Buck <jamis@37signals.com> | 2006-09-28 19:32:40 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2006-09-28 19:32:40 +0000 |
commit | c0eccc9aef21c3eac9d89d3af93b82ce906b04dd (patch) | |
tree | c2466fe2ed1814cfed136f7dc8e981733fbc7dc2 /actionpack/lib | |
parent | b2ede64a89a5837a047e75f21a1522324a614514 (diff) | |
download | rails-c0eccc9aef21c3eac9d89d3af93b82ce906b04dd.tar.gz rails-c0eccc9aef21c3eac9d89d3af93b82ce906b04dd.tar.bz2 rails-c0eccc9aef21c3eac9d89d3af93b82ce906b04dd.zip |
modify head so that you can specify a bare status code as the first parameter
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5200 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rwxr-xr-x | actionpack/lib/action_controller/base.rb | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index bd2256f44d..94e2d6a25f 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -837,15 +837,31 @@ module ActionController #:nodoc: # This allows you to easily return a response that consists only of # significant headers: # - # head :status => :created, :location => person_path(@person) + # head :created, :location => person_path(@person) # # It can also be used to return exceptional conditions: # - # return head(:status => :method_not_allowed) unless request.post? - # return head(:status => :bad_request) unless valid_request? + # return head(:method_not_allowed) unless request.post? + # return head(:bad_request) unless valid_request? # render - def head(options = {}) - status = interpret_status(options.delete(:status) || :ok) + def head(*args) + if args.length > 2 + raise ArgumentError, "too many arguments to head" + elsif args.empty? + raise ArgumentError, "too few arguments to head" + elsif args.length == 2 + status = args.shift + options = args.shift + elsif args.first.is_a?(Hash) + options = args.first + else + status = args.first + options = {} + end + + raise ArgumentError, "head requires an options hash" if !options.is_a?(Hash) + + status = interpret_status(status || options.delete(:status) || :ok) options.each do |key, value| headers[key.to_s.dasherize.split(/-/).map { |v| v.capitalize }.join("-")] = value.to_s |