Skip to content
Browse files

Fix when database column name has some symbolic characters. [#5818 st…

…ate:resolved]
  • Loading branch information...
1 parent cb2c5c5 commit c75e4aeca398c1c48bf40ef24bd89067a87124fc @paneq paneq committed with spastorino
Showing with 5 additions and 5 deletions.
  1. +5 −5 activemodel/lib/active_model/attribute_methods.rb
View
10 activemodel/lib/active_model/attribute_methods.rb
@@ -93,10 +93,10 @@ module ClassMethods
def define_attr_method(name, value=nil, &block)
sing = singleton_class
sing.class_eval <<-eorb, __FILE__, __LINE__ + 1
- if method_defined?(:original_#{name})
- undef :original_#{name}
+ if method_defined?(:'original_#{name}')
+ undef :'original_#{name}'
end
- alias_method :original_#{name}, :#{name}
+ alias_method :'original_#{name}', :'#{name}'
eorb
if block_given?
sing.send :define_method, name, &block
@@ -269,8 +269,8 @@ def define_attribute_methods(attr_names)
method_name = matcher.method_name(attr_name)
generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
- if method_defined?(:#{method_name})
- undef :#{method_name}
+ if method_defined?(:'#{method_name}')
+ undef :'#{method_name}'
end
def #{method_name}(*args)
send(:#{matcher.method_missing_target}, '#{attr_name}', *args)

11 comments on commit c75e4ae

@dkubb

Is the #{} interpolated inside a single quoted string? I didn't think it would be.

@tenderlove
Ruby on Rails member

o_O

Common @spastorino.

y u no

@ryanorr

I have such a man-crush on Tenderlove.

@spastorino
Ruby on Rails member

@dkubb the interpolation it's done inside a here documents string.

@tenderlove I've backported the commit of this guy to 3-0-stable and added tests here, here, here and here

@jacortinas

This is completely relevant to Rails. tenderlover

@tenderlove
Ruby on Rails member

@spastorino common:

lol

@jacortinas lol!

@guilleiguaran
Ruby on Rails member

@tenderlove I've backported the commit of this guy to 3-0-stable and added tests here, here, here and here

@spastorino
Ruby on Rails member

Lol, I should have replied differently.
Understand me guys, @tenderlove use to be always right, that was my opportunity :P.

@dkubb

@spastorino: duh, sorry I missed that. Also, probably another dumb question but what if name or method_name include a single quote?

@spastorino
Ruby on Rails member

@dkubb yes this code is not good we will need to refactor, but meanwhile I'm going to do ...

method_defined?(:#{method_name.inspect})

HHHHHAAAAACCCCKKKK :(:(:(

@spastorino
Ruby on Rails member

@dkubb I also meant yes it's an error :)

Please sign in to comment.
Something went wrong with that request. Please try again.