0

I have a helper method (create_employee) inside of a Rake task that I would like to use inside a Rails controller.

lib/taks/billing.rb

require 'rake'

task :billing => :environment do
  //logic in task
end

create_employee args1
  //logic to create new employee
end

How can I call this method within a Rails Controller?

Gpcnec76
  • 69
  • 1
  • 8

1 Answers1

0

system "RAILS_ENV="+Rails.env+" rake foo:bar"

Sagar.Patil
  • 991
  • 8
  • 17
  • So, how exactly would you use it inside controller? – Andrey Deineko Jul 22 '15 at 06:22
  • I might suggest string interpolation here as well as prepending `bundle exec` so do: `system "RAILS_ENV=#{Rails.env} bundle exec rake foo:bar"` @AndreyDeineko He's literally given you the exact command here. `system` runs shell commands as you would on the terminal command line. – lacostenycoder Jul 01 '17 at 09:50