title: require lib in rake task
body: <p>I have a file alert_import in lib/models/alert_import', I would like to use in my task sth like this:</p>
  
  <pre><code>task :send_automate_alerts =&gt; :environment do
   # STDERR.puts "Path is #{$:}"
    Rake.application.rake_require '../../lib/models/alert_import'
    ai = AlertImport::Alert.new(2)
    ai.send_email_with_notifcations
  end
  </code></pre>
  
  <p>In this code I get error:</p>
  
  <p>Can't find ../../lib/models/alert_import</p>
  
  <p>in AlertImport I have:</p>
  
  <pre><code>module AlertImport
  
    class Alert
  
      def initialize(number_days)
        @number_days = number_days
      end
  
      def get_all_alerts
        alerts = { }
        Organization.automate_import.each do |o|
          last_import = o.import_histories.where(import_type: "automate").last
          last_successful_import = ImportHistory.last_automate_successful_import(o)
          if last_import
            if last_import.created_at + @number_days.days &gt;= Time.now
              alerts[o.id] ="Error during last automate import Last successful import was #{ last_successful_import ? last_successful_import.created_at : "never"}" if last_import.status == "failure"
              alerts[o.id] ="Error during last automate import - status pending Last successful import was #{ last_successful_import ? last_successful_import.created_at : "never"}" if last_import.status == "pending"
            else
              alerts[o.id] = "There were no new files uploaded within #{@number_days} days"
            end
          else
            alerts[o.id] = "The import was never triggered at all"
          end
        end
        alerts
      end
  
      def send_email_with_notifcations
        alerts =get_all_alerts
        unless alerts.empty?
          AlertMailer.email_notifications(alerts).deliver
        end
      end
  
    end
  
  end
  </code></pre>
  
  <p>The correct solution is:</p>
  
  <pre><code>desc "Send alerts about automate imports"
  
  task :send_automate_alerts =&gt; :environment do
    require "#{Rails.root}/lib/models/alert_import"
    ai = AlertImport::Alert.new(2)
    ai.send_email_with_notifcations
  end
  </code></pre>