Hi Patrick, That was immensely helpful. I did take your advice, and have a fresh Rails 5.2 app to test with.
I may be in touch if I find myself intractably stuck again, but I believe you've got me pointed back in the right direction! Best, Salvatore On Fri, Aug 10, 2018, 8:30 AM Patrick Crowley <[email protected]> wrote: > Alrighty, Sal. Let’s take a look. > > - First up, let’s look at the stack trace more closely. We’re getting an > error inside the #find_for_authentication method in your User model. > > - So let’s go look at the User model. As the name implies, > #find_for_authentication is used to find the first matching active user > when we need to authenticate a user (to login, etc.) This is a common > pattern for auth code because when a user logs in, we only want to be > dealing with a single account (even if they have somehow created more than > one account with the same email address). That way, whenever you need to > interact with the current_user, there’s only one — and you don’t have to > write code like `if current_user && current_user.size == 1`. > > - Another observation: you've defined this method, but you’re not > explicitly using it within your model. So, while it’s possible that this > method is only used in a controller, it made me think you might be > redefining a method originally defined by your auth gem. > > And, indeed, a quick search for the method name reveals that the method > belongs to Devise: > https://www.rubydoc.info/github/plataformatec/devise/Devise/Models/Authenticatable/ClassMethods > > - But, back to the stacktrace and model for a second: the method is trying > to find the first active user (using the :email param), but it’s failing. > But look at it closely. Line 77 is just an ActiveRecord finder. It’s > essentially `User.find(:first, :conditions)`. > > - So now let’s look at the docs for ActiveRecord in Rails 2.3: > https://guides.rubyonrails.org/v2.3.11/active_record_querying.html > > - Scroll down to section 1.1.2: > `Model.find(:first, options) is equivalent to Model.first(options)` > > - That’s the same ActiveRecord finder your code is using! > > - So now let’s look at these same docs in Rails 5.2: > https://guides.rubyonrails.org/active_record_querying.html > > - There is no mention of using the :first param with #find. And that’s > because later versions of Rails switched to `User.first`. > > So I think that’s the source of your error. User.find(:first) is no longer > support in Rails. > > To get things working, you would just need to update your ActiveRecord > syntax to work with Rails 5.2. > > def self.find_for_authentication(conditions={}) > first.where(conditions, active: true) > end > > But, even simpler, if you look at those Devise docs again, the sample code > for customizing #find_for_authentication has changed a bit: > > def self.find_for_authentication(tainted_conditions) > find_first_by_auth_conditions(tainted_conditions, active: true) > end > > It’s using a different ActiveRecord syntax — presumably still valid -- for > finding that first record, so that’s an option too. > > And remember: as you do this upgrade, you’re upgrading Ruby code, Ruby on > Rails code, and, in this case, Devise code — so you want to make sure > that’s current too. > > Also, as we discussed in person, I recommend creating a separate, > brand-new Rails 5.2 app as you work on the upgrade. You can use that as a > test bed for getting working 5.2 code in a completely clean code base with > zero legacy issues. > > So, for instance, it might be worth building out a new Devise > implementation for basic authentication in this separate 5.2 app, and then > once it’s all working, backport the new auth code into the old app. > > Good luck! > > Cheers, > Patrick > > > > > On Aug 9, 2018, at 6:23 pm, Salvatore McCarty <[email protected]> wrote: > > > > > > Hi Ben, > > > > I've attached a PDF of the trace and here's a link to a gist with the > Gemfile (and .lock) and the user.rb file that the trace points to. > > https://gist.github.com/SalMac86/6dc23b6fe9a090bc12024de3fa723957 > > > > Thanks!, > > > > Sal > > On Thursday, August 9, 2018 at 4:07:06 PM UTC-7, Benjamin Wanicur wrote: > > Hi Sal > > > > Can you post the error stacktrace and some code ? Or create a Gist ? > > > > On Thu, Aug 9, 2018 at 2:00 PM Salvatore McCarty <[email protected]> > wrote: > > Hello, > > > > It was great meeting all of you and attending the event last Thursday. > > > > I am still in the midst of the upgrade of that inherited project from > Rails 3.2 to 5.2 and would greatly appreciate any help! > > > > Right now it seems like something in the controllers has changed, and > I'm getting an invalid number of arguments error for just about everything. > > > > If anyone wants to connect with me and maybe take a peek, I would be > grateful! > > > > Best, > > > > Sal > > > > -- > > -- > > SD Ruby mailing list > > [email protected] > > http://groups.google.com/group/sdruby > > --- > > You received this message because you are subscribed to the Google > Groups "SD Ruby" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected]. > > For more options, visit https://groups.google.com/d/optout. > > > > -- > > -- > > SD Ruby mailing list > > [email protected] > > http://groups.google.com/group/sdruby > > --- > > You received this message because you are subscribed to the Google > Groups "SD Ruby" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected]. > > For more options, visit https://groups.google.com/d/optout. > > <Action Controller_ Exception caught.pdf> > > -- > -- > SD Ruby mailing list > [email protected] > http://groups.google.com/group/sdruby > --- > You received this message because you are subscribed to the Google Groups > "SD Ruby" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- -- SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby --- You received this message because you are subscribed to the Google Groups "SD Ruby" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
