Using rails 4.2.1
.
I want to call a rake
task on every config/routes.rb
file save. How would I go about doing this?
Note: the rake
task does require the rails
environment. i.e. it's of the task :task_name => :environment do #...
nature.
Using rails 4.2.1
.
I want to call a rake
task on every config/routes.rb
file save. How would I go about doing this?
Note: the rake
task does require the rails
environment. i.e. it's of the task :task_name => :environment do #...
nature.
Take a look into filewatcher gem.
You can define actions to be taken depending on what changes are made to specified file (or directory):
require 'filewatcher'
FileWatcher.new("config/routes.rb").watch() do |filename, event|
if(event == :changed)
your_rake_task
end
if(event == :delete)
# ...
end
if(event == :new)
# ...
end
end
In rails 4.2.1
# development.rb
require 'rake'
Rails.application.configure do
#...
Rails.application.load_tasks
# code executes on routes change
ActionDispatch::Reloader.to_prepare do
Rails.application.reload_routes!
if JsRoutes.assert_usable_configuration!
Rake::Task['js_routes:generate'].reenable
Rake::Task['js_routes:generate'].invoke
end
end
#...
end
Based off of https://stackoverflow.com/a/27046271/749477