Undefined Method 'Devise' When Including User Model Outside Rails

Undefined method 'devise' when including User model outside Rails

Even though this architecture must change in the near future, we managed to work around this error by including devise and its initializer in the ruby application.

# FIXME: Dependency needed in Rails but not in the engine.
require 'devise'
require_relative "../../RailsApp/config/initializers/devise.rb"

#Load all the models

`method_missing': undefined method `devise' for User (call 'User.connection' to establish a connection)

This happens because you missed the command:

rails generate devise:install

You need just comment all devise lines temporally (in routes.rb / user.rb) to not get raise.

And run command again.

Rails error : undefined method `product' for #User:0x00007faaa8c42700 Did you mean? products products=

You have left behind an old validation in your user model.

Delete this line in the app/models/user.rb file
validates_length_of :product, maximum: 10

Add trackable (devise) to existing User model?

The Trackable module expects more than just the sign_in_count attribute.
The full list of required columns is listed in the documentation
If you add another migration for the remaining columns, everything should work as expected.

Rails 3 + Devise: user_signed_in? for a different user in the database?

I'm not the author of Devise, but from what I can tell of Warden / Devise neither keep track of who is logged in.

The problem with having an is_online column in the User table is that it is difficult to see who is active on the website. I would add a column to your User model called last_seen as a date-time, and update that with Devise every time the user requests a page. You could then easily add a User.online_count method or also see if a user has been seen at the website in the last 5 minutes.



Related Topics



Leave a reply



Submit