Reputation: 5619
I have a backup.rake file in the lib/tasks folder
task looks like this:
require 'find'
namespace :backup do
desc "Backup the database to a file."
task :mysqldump => [:environment] do
end
end
Now I want to call this from a controller like this:
system "RAILS_ENV="+Rails.env+"rake backup:mysqldump"
But I got this error:
sh: 1: backup:mysqldump: not found
What is the problem? I do exactly the same with other tasks ...
Upvotes: 1
Views: 773
Reputation: 1601
In controller you can use like this:
def method
%x[rake rake backup:mysqldump]
redirect_to root_path
end
Upvotes: 1
Reputation: 991
It should be like this
system "RAILS_ENV="+Rails.env+" rake backup:mysqldump"
a space between " rake
Upvotes: 3