diff options
author | José Valim <jose.valim@gmail.com> | 2010-09-27 21:33:03 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-09-27 21:33:03 +0200 |
commit | 8be911c698aadd389b1607b4dbcea47001761536 (patch) | |
tree | 837fc3d03fd74a5043160aab9224888ca70de12c /activeresource/lib/active_resource/base.rb | |
parent | 8aa3684e07db81244c61c9ac98347831a976666b (diff) | |
parent | f85b38a36b68488e94e9950fd15ec29a21bf6917 (diff) | |
download | rails-8be911c698aadd389b1607b4dbcea47001761536.tar.gz rails-8be911c698aadd389b1607b4dbcea47001761536.tar.bz2 rails-8be911c698aadd389b1607b4dbcea47001761536.zip |
Merge remote branch 'gramos/ares-missing-prefix-value'
Diffstat (limited to 'activeresource/lib/active_resource/base.rb')
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index d31db9f0ba..6135ce4ec1 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -166,6 +166,7 @@ module ActiveResource # # GET http://api.people.com:3000/people/999.xml # ryan = Person.find(999) # 404, raises ActiveResource::ResourceNotFound # + # # <tt>404</tt> is just one of the HTTP error response codes that Active Resource will handle with its own exception. The # following HTTP response codes will also result in these exceptions: # @@ -194,6 +195,16 @@ module ActiveResource # redirect_to :action => 'new' # end # + # When a GET is requested for a nested resource and you don't provide the prefix_param + # an ActiveResource::MissingPrefixParam will be raised. + # + # class Comment < ActiveResource::Base + # self.site = "http://someip.com/posts/:post_id/" + # end + # + # Comment.find(1) + # # => ActiveResource::MissingPrefixParam: post_id prefix_option is missing + # # === Validation errors # # Active Resource supports validations on resources and will return errors if any of these validations fail @@ -621,6 +632,8 @@ module ActiveResource # # => /posts/5/comments/1.xml?active=1 # def element_path(id, prefix_options = {}, query_options = nil) + check_prefix_options(prefix_options) + prefix_options, query_options = split_options(prefix_options) if query_options.nil? "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}.#{format.extension}#{query_string(query_options)}" end @@ -663,6 +676,7 @@ module ActiveResource # # => /posts/5/comments.xml?active=1 # def collection_path(prefix_options = {}, query_options = nil) + check_prefix_options(prefix_options) prefix_options, query_options = split_options(prefix_options) if query_options.nil? "#{prefix(prefix_options)}#{collection_name}.#{format.extension}#{query_string(query_options)}" end @@ -842,6 +856,14 @@ module ActiveResource end private + + def check_prefix_options(prefix_options) + p_options = HashWithIndifferentAccess.new(prefix_options) + prefix_parameters.each do |p| + raise(MissingPrefixParam, "#{p} prefix_option is missing") if p_options[p].blank? + end + end + # Find every resource def find_every(options) begin |