I'm writing a gem and I want to have an access to the gem rake tasks from my rails app. To do this I use Railties.
I have lib/frontrockets-rails/railtie.rb
with
require 'frontrockets-rails'
require 'rails'
module FrontrocketsRails
class Railtie < Rails::Railtie
railtie_name :frontrockets
rake_tasks do
load 'tasks/frontrockets.rake'
end
end
end
and
lib/frontrockets-rails.rb
with
module FrontrocketsRails
require 'frontrockets-rails/railtie' if defined?(Rails)
end
and of course lib/tasks/frontrockets.rake
namespace :frontrockets do
desc 'Create .bowerrc file'
task :create_bowerrc do
touch '.bowerrc'
end
task :install => [:create_bowerrc] do
end
end
But when I install this gem in my Rails app I still can't execute this rake tasks, there are no them in the rake -T
list.
I've just restarted spring and new rake tasks appeared in my rake -T
list. :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.