How to run rake in ruby-on-rails application in production?

10,628

Solution 1

You should go to the root path of your project directory in production and type the following command:

RAILS_ENV=production bundle exec rake app:elasticsearch

Note:

To check the available list of rake tasks, you can type rake -T

Solution 2

rake task-name RAILS_ENV=production
Share:
10,628
A j
Author by

A j

Updated on June 09, 2022

Comments

  • A j
    A j almost 2 years

    I am trying to figure out how to deploy my ruby-on-rails application in production.

    The operating system is ubuntu and the application uses Postgres. I have managed to deploy the application and am able to login etc... but there are certain functionality that is not working (I am new to the application and rails). The application uses elastic search, which I have installed and the service is running (I can access the page via http://localhost:9200). But when the application tries to access components of elastic search i get an error.

    There is a rake file in the directory /app/lib/tasks, which has several files and one of the them is elasticsearch.rake

    namespace :app do
      desc "Bootstraping Elasticsearch index"
      task(:elasticsearch => :environment) do
    
        Image.__elasticsearch__.create_index! force:true
        Image.import
    
        CaseStudy.__elasticsearch__.create_index! force:true
        CaseStudy.import
    
      end
    end
    

    As the description in the file says this bootstraps the elastic search index.
    What I don't know is how do I run all this in a production environment? There are other rake files as well and I want to know how to run them.

  • A j
    A j about 8 years
    when I run rake elasticsearch RAILS_ENV=production. I get the following error. rake aborted! Don't know how to build task 'elasticsearch.rake'