Search code examples
ruby-on-railssql-serverdevise

Rails 6 devise gem on existing SQL db with capitalized colum name


i'm attempting to do some tests in RoR (ruby v2.6.8, rails v6.1.5): I want to create a devise based on an existing database with existing user table (called Account, with capitalized A). I managed to execute the first steps to migrate the columns needed by Devise but i get stuck when i try to signup:

undefined method `email' for #<Account:0x0000000110cb34f8>


   Did you mean?  Email
                  Email=
                  Email?

Extracted source (around line #469):

   else
       match = matched_attribute_method(method.to_s)
       match ? attribute_missing(match, *args, &block) : super
     end
   end
   ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)

Any general suggestion how to handle this and possible future problems? Thanks a lot


Solution

  • The simplest solution is alias_attribute.

    That will delegate the :email and :email= methods to :Email and :Email= respectively

    class Account
      alias_attribute :email, :Email
    end