run rake task in rails console
require 'rake'
MyRailsApp::Application.load_tasks
Rake::Task['task_name'].invoke
require 'rake'
: Imports the Rake gem, which is Ruby's build program.MyRailsApp::Application.load_tasks
: Loads the tasks defined in the Rails application.Rake::Task['task_name'].invoke
: Invokes a specific Rake task named'task_name'
, executing its associated functionality within the Rails environment. Replace'task_name'
with the actual name of the task you want to execute.