Unable to load Rake task: the correct environment

I am running a custom rake task ...

namespace :import do

  desc "Import terms of service as HTML from stdin"
  task :terms => :environment do
    html = STDIN.read
    settings = ApplicationWideSetting.first
    settings.terms_and_conditions = html
    if settings.save
      puts "Updated terms of service"
    else
      puts "There was an error updating terms of service"
    end
  end

end

The ApplicationWideSetting model appears as undefined when the task starts in the environment production. However, when task is started in other environments (i.e. development, staging, test.) Task executes normally.

Process execution in the rails console in all environments terminates normally.

Does anyone know what is happening, what can I check?

note : I completed the task with

puts Rails.env 

To check var shell environment, RAILS_ENV set / read correctly. I also tried both with and without square brackets:

additional information: Rails v3.2.14

. , script . , . , .

+3
1

, Rails ( - ) rake Production.

- require, rake, , :

# explicitly require model
require 'application_wide_setting'

rails :

Rails.application.eager_load!

(.. )

+4

Source: https://habr.com/ru/post/1666855/


All Articles