I tried to separate my model as a rails engine, to use that in more then one application.
In order to achieve this I created rails plugin new engine_name --full
so that I can use all the routes and models without mounting in an isolated namespace.
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
scope :find_user, ->(id) { where(id: id)}
def self.say_hello(str)
puts "Welcome #{str}"
end
end
the above is my plugin without module encapsulated (because it created with --full)
I can successfully include this into any rails app and can access the route and create user.
also I'm able to access class methods from the model using
2.1.5 :015 > User.say_hello("ferdy")
Welcome ferdy
when I try to access the model using
User.create(email:"ferdsfd@sdfds.com",password:12345678)
ActiveRecord::StatementInvalid: Could not find table 'users'
what would be the problem? could any one help how to access plugin model?
Aucun commentaire:
Enregistrer un commentaire