I'm trying to add the function that is defined in the controller.rb file to the rake file. The Name of this controller file is "home_controller.rb". Here I put a part of the code.
class HomeController < ApplicationController
def rclass_creation
#output = "rclass is created"
a = Rclass.all
a.destroy_all...
I made my_namespace.rake file under tasks in the lib folder. Here I put the code a bit.
namespace :my_namespace do
desc "TODO"
task my_task2: :environment do
a = Userpool.all
a.each do |user|
puts user.name
end
puts "wow it is working"
I was able to call the database. I think this is because the rake file has an access to the database ( Userpool ). In this rake file, I want to call the function "rclass_creation" that was stated in the "home_controller.rb" because I want to avoid the situation that I have to do hardcopy.
The sudo code might look like this ( I hope (: )
namespace :my_namespace do
desc "TODO"
task my_task2: :environment do
status = rclass_creation <= from home_controller.rb
a = Userpool.all
a.each do |user|
puts user.name
end
puts "wow it is working"
The function I want to call is "rclass_creation" from the home_controller. How can I call the function from the controller to rake file ? I'm looking forward to seeing opinions from the experts!!