Undefined method 'devise' when including User model outside Rails
activerecord, devise, ruby, ruby-on-rails
Solution
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
Problem
I am developing an application that consists in two parts: A ruby command line application and a Rails application for the front-end. I've been using ActiveRecord and the Rails models in the Ruby application by including them individually the following way: ``` Dir[File.dirname(__FILE__) + '/../../RailsApp/app/models/*.rb'].each do |file| filename = File.basename(file, File.extname(file)) require_relative "../../RailsApp/app/models/" + filename end ``` And by manually mantaining two nearly identical Gemfile files for dependencies (an approach that I think is not the best) Yesterday I added Devise to the Rails application, and now when the ruby app tries to include the user model, the message `undefined method devise for class <xxxxx>` appears. I added the devise gem in my ruby app's Gemfile, but the error continues. If I understand correctly, Devise is a Rails Engine, which is why it's not being loaded just by requiring the gem. I read that a better approach to include Rails models inside another application is by requiring the `environment.rb` file, but when I tried that, I got an error with ActionMailer: ``` undefined method `action_mailer' for #<Rails::Application::Configuration:0xbbb54bc> ``` How can I solve the issue with devise? Is there a better way to include Rails models inside another application than the one I'm currently using to avoid mantaining two gemfiles ? Thanks