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

Time:04-15

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

CodePudding user response:

Simplest way is to just do an alias_attribute.

That will delegate :email and :email= to :Email and :Email=.

class Account
  alias_attribute :email, :Email
end
  • Related