Answer the question
In order to leave comments, you need to log in
How to access models that are stored in the gem?
There is a rails application, most of which, including models, is in an included gem.
I'm writing a class to use it in rake task'e, it's in /lib
. The class needs access to the application's models. How to get it?
Answer the question
In order to leave comments, you need to log in
let's say you write your_task.rake file
you can write it like this and load the default rails environment (note the :environment )
namespace :your_task do
desc "my description"
task :my_task => :environment do
<...>
end
end
require_relative '../lib/your_path'
namespace :your_task do
desc "my description"
task :my_task do
<...>
end
end
All gems are loaded into memory when a rail application is initialized, so all objects are available in the code without additional libraries. The plug-in library model is a regular ruby class, most likely you can get to it by the full path, for example. SuperGem::SuperAR::SuperModel
You need to read the api documentation of the gem or look at the source code to understand how it works.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question