rake-task

How to build task 'elasticsearch:import:model'

蹲街弑〆低调 提交于 2019-12-04 09:34:11
问题 Well, I have elasticsearch-rails gem installed (version 0.1.5) and I can clearly see the task inside the gem files. But when I run bundle exec rake environment elasticsearch:import:model CLASS='Comment' I get this error. Running rake environment -D doesn't show me the task either. elasticsearch is running, if I curl http://localhost:9200 it responds me. Why isn't this working? 回答1: you need create elasticsearch.rake cat lib/tasks/elasticsearch.rake require 'elasticsearch/rails/tasks/import'

How to parse rake arguments with OptionParser

喜欢而已 提交于 2019-12-04 03:05:24
问题 Reffering that answer I was trying to use OptionParser to parse rake arguments. I simplified example from there and I had to add two ARGV.shift to make it work. require 'optparse' namespace :user do |args| # Fix I hate to have here puts "ARGV: #{ARGV}" ARGV.shift ARGV.shift puts "ARGV: #{ARGV}" desc 'Creates user account with given credentials: rake user:create' # environment is required to have access to Rails models task :create => :environment do options = {} OptionParser.new(args) do

Removing whitespaces in a CSV file

隐身守侯 提交于 2019-12-04 00:52:31
I have a string with extra whitespace: First,Last,Email ,Mobile Phone ,Company,Title ,Street,City,State,Zip,Country, Birthday,Gender ,Contact Type I want to parse this line and remove the whitespaces. My code looks like: namespace :db do task :populate_contacts_csv => :environment do require 'csv' csv_text = File.read('file_upload_example.csv') csv = CSV.parse(csv_text, :headers => true) csv.each do |row| puts "First Name: #{row['First']} \nLast Name: #{row['Last']} \nEmail: #{row['Email']}" end end end You can strip your hash first: csv.each do |unstriped_row| row = {} unstriped_row.each{|k,

Does Rails run initializers for rake task?

强颜欢笑 提交于 2019-12-03 15:44:16
问题 Are the scripts from config/initializers executed when I run rake task? 回答1: It does if your rake task depends on :environment . i.e, you declare your task like so: task :my_task => :environment do ... end 回答2: Mostly yes. rake loads a complete rails environment including initializers, when your task depends on :environment . 来源: https://stackoverflow.com/questions/11509439/does-rails-run-initializers-for-rake-task

How do you declare a Rake task that depends on a parameterized task?

微笑、不失礼 提交于 2019-12-03 09:30:55
I have seen examples where a task has parameters and a dependency task like: task :name, [:first_name, :last_name] => [:pre_name] do |t, args| args.with_defaults(:first_name => "John", :last_name => "Dough") puts "First name is #{args.first_name}" puts "Last name is #{args.last_name}" end How would you pass parameters to the name task if it was a task dependency like: task :sendLetter => :name #do something end xtoddx Args are passed down through the call stack. You just need to make sure your top-level task captures all the arguments all of the dependencies require. In your case you'll want

Dealing with very long running rake task

偶尔善良 提交于 2019-12-03 07:18:51
问题 I am interested in running a very long running rake task, one that would take hours to complete and I am interested in learning about best practices for dealing with this problem. Possible solutions I have found: Set up a cron job delayed_job resque cron seems like a simple solution to set up, but is it ideal for a very long task? What do you use and what are the advantages/disadvantages of your solution? 回答1: Personally I love Resque, you can use the resque-scheduler gem for dealing with

rake db:create encoding error with postgresql

一个人想着一个人 提交于 2019-12-03 02:14:46
问题 I'm importing an existing rails project that I was working on into my new arch linux system, I already installed all gems and postgresql correctly, but I having some issues when runing: rake db:create I get the following error PGError: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII) HINT: Use the same encoding as in the template database, or use template0 as template. : CREATE DATABASE "System_test" ENCODING = 'unicode' I created manually the

Dealing with very long running rake task

孤人 提交于 2019-12-02 20:52:37
I am interested in running a very long running rake task, one that would take hours to complete and I am interested in learning about best practices for dealing with this problem. Possible solutions I have found: Set up a cron job delayed_job resque cron seems like a simple solution to set up, but is it ideal for a very long task? What do you use and what are the advantages/disadvantages of your solution? Personally I love Resque, you can use the resque-scheduler gem for dealing with long running or periodic tasks. If you don't have to run your task very often, you can demonize the the rake

rake db:create encoding error with postgresql

瘦欲@ 提交于 2019-12-02 14:14:23
I'm importing an existing rails project that I was working on into my new arch linux system, I already installed all gems and postgresql correctly, but I having some issues when runing: rake db:create I get the following error PGError: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII) HINT: Use the same encoding as in the template database, or use template0 as template. : CREATE DATABASE "System_test" ENCODING = 'unicode' I created manually the database with the correct encoding and the migrations worked well, but I can run the rake db:test:clone

rake aborted! uninitialized constant Object::Country, why can't see model?

点点圈 提交于 2019-12-01 18:52:07
I have rails 3.1, I am trying to populate data with seeds.rb I have a model Country which is migrated into a countries table But it seems that rails can't see Country model from seeds.rb I get this error: rake aborted! uninitialized constant Object::Country Tasks: TOP => db:seed my seeds.rb file looks like this: # encoding: UTF-8 Country.delete_all my Country model: class Country < ActiveRecord::Base has_many :students has_many :instructors end any idea please ? EDIT I am in development environment, with config.threadsafe! 来源: https://stackoverflow.com/questions/8628830/rake-aborted