diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-01-24 18:27:36 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-01-24 18:27:36 +0000 |
commit | 1b1ddf17367f902dfbacf9143f0c90b7c42436dc (patch) | |
tree | e37757a3671f4a835825597660b144e912979f34 /activeresource/lib/active_resource | |
parent | 873f5e2f3ca1be0d260b44e0f09aa59aa824a1b9 (diff) | |
download | rails-1b1ddf17367f902dfbacf9143f0c90b7c42436dc.tar.gz rails-1b1ddf17367f902dfbacf9143f0c90b7c42436dc.tar.bz2 rails-1b1ddf17367f902dfbacf9143f0c90b7c42436dc.zip |
Loading a resource preserves its prefix_options. Closes #7353. Silence prefix redefinition warnings; fix type in logged error.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6032 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/lib/active_resource')
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index faf0f046d6..a4e21b3253 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -45,13 +45,17 @@ module ActiveResource # Sets the resource prefix # prefix/collectionname/1.xml def prefix=(value = '/') + # Replace :placeholders with '#{embedded options[:lookups]}' prefix_call = value.gsub(/:\w+/) { |key| "\#{options[#{key}]}" } - instance_eval <<-end_eval, __FILE__, __LINE__ + + # Redefine the new methods. + code = <<-end_code def prefix_source() "#{value}" end def prefix(options={}) "#{prefix_call}" end - end_eval + end_code + silence_warnings { instance_eval code, __FILE__, __LINE__ } rescue - logger.error "Couldn't set prefix: #{$!}\n #{method_decl}" + logger.error "Couldn't set prefix: #{$!}\n #{code}" raise end @@ -235,7 +239,7 @@ module ActiveResource resource = find_or_create_resource_for(key) resource.new(value) when ActiveResource::Base - value.class.new(value.attributes) + value.class.new(value.attributes, value.prefix_options) else value.dup rescue value end |