Skip to content
Browse files

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

  • 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
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}'
- alias_method :original_#{name}, :#{name}
+ alias_method :'original_#{name}', :'#{name}'
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}'
def #{method_name}(*args)
send(:#{matcher.method_missing_target}, '#{attr_name}', *args)

11 comments on commit c75e4ae


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

Ruby on Rails member


Common @spastorino.

y u no


I have such a man-crush on Tenderlove.

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


This is completely relevant to Rails. tenderlover

Ruby on Rails member

@spastorino common:


@jacortinas lol!

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

Ruby on Rails member

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


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

Ruby on Rails member

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



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.