rake-task

Rake aborted! Don't know how to build task

走远了吗. 提交于 2019-12-06 08:38:02
问题 I have a rake task in semester.rake file. It looks like this namespace :db do desc "generate semester data" task semester: :environment do semester = Semester.create!(name: "SummerSemseter") semester = Semester.create!(name: "WinterSemester") semester = Semester.create!(name: "Spring Semester") end end and I run the task as rake semester . This gives me error rake aborted! Don't know how to build task 'semester' (see --tasks) /home/john/.rvm/gems/ruby-2.2.4/gems/rake-11.3.0/exe/rake:27:in `

How to pass different arguments in rake multitask

雨燕双飞 提交于 2019-12-06 05:57:21
I want to pass different arguments to every method and need to run all methods parallel using rake task Here is rake task calling example Rake::Task['test:sync'].invoke(user.id, user.address) Rake::Task['test:sync'].invoke(user.id, user.address) Rake::Task['test:sync'].invoke(user.id, user.address) I have seen the multitask example like this multitask :copy_files => [:copy_src, :copy_doc, :copy_bin] do puts "All Copies Complete" end Here they are calling with the task name alone. But in my case i want to pass task name with parameters . How can i achieve it. Extract the functionality into its

Rspec Rake Task: How to parse a parameter?

半腔热情 提交于 2019-12-06 03:16:42
I have a rake task which generates a new User. Values of email, password and password_confirmation (confirm) needs to be typed in through the command line. This is my rake task code: namespace :db do namespace :setup do desc "Create Admin User" task :admin => :environment do ui = HighLine.new email = ui.ask("Email: ") password = ui.ask("Enter password: ") { |q| q.echo = false } confirm = ui.ask("Confirm password: ") { |q| q.echo = false } user = User.new(email: email, password: password, password_confirmation: confirm) if user.save puts "User account created." else puts puts "Problem creating

how to run rake task in background in rails

强颜欢笑 提交于 2019-12-05 16:47:34
This is my command bundle exec rake resque:work QUEUE="*" --trace I want to run this command on my server as a background process. please help me. A method I often use is: nohup bundle exec rake resque:work QUEUE="*" --trace > rake.out 2>&1 & This will keep the task running even if you exit your shell. Then if I want to just observe trace output live, I do: tail -f rake.out And you can examine rake.out at any time. If you need to kill it before completion, you can find it with ps and kill the pid. Just in case somebody finds this 4 years later, bundle has an elegant way of doing this now. For

How can I run a ruby class from rake file?

僤鯓⒐⒋嵵緔 提交于 2019-12-05 14:50:37
I want to run a ruby class from a sample.rake file. Consider myruby.rb is a ruby file. I want to run this from sample.rake like ruby myruby.rb Adding to what @tobias has to say here you go with an example script sample content of myruby.rb puts "hello world" Create file called Rakefile task :default => [:test] task :test do ruby "my_file.rb" end Now if you invoke rake it should file up hello world text in console. Update It would make more sense if you wrap your call in a function call as suggested already by @tobias So your Rakefile would become something like require './myruby.rb' task

Removing whitespaces in a CSV file

六月ゝ 毕业季﹏ 提交于 2019-12-05 14:37:29
问题 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']}"

Ruby rake loaderror - bundle exec rake not working

折月煮酒 提交于 2019-12-05 13:07:25
I'm trying to run the command rake db:migrate but I keep getting this error: /Users/[name]/.rvm/gems/ruby-2.2.1/bin/rake:23:in `load': cannot load such file -- /Users/[name]/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/specifications/default/bin/rake (LoadError) from /Users/[name]/.rvm/gems/ruby-2.2.1/bin/rake:23:in `<main>' from /Users/[name]/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval' from /Users/[name]/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>' Trying bundle exec rake db:migrate also gives me the same error. Is there a way I can solve this issue? (I'm on Mac

How to execute commands within Rake tasks?

半世苍凉 提交于 2019-12-04 22:36:02
I have the rake tasks in my rails application. i want to run a commandline commands with in rake task. how can i do this. i tried by the following but fails desc "Sending the newsletter to all the users" task :sending_mail do run "cd #{RAILS_ROOT} && ar_sendmail -o -t NewsLetters -v" system "cd #{RAILS_ROOT} && ar_sendmail -o -t NewsLetters -v &" end The above run command throws run method undefined & System command not throwing any errors but not executed. krunal shah This links may help you run command line command into ruby ... http://zhangxh.net/programming/ruby/6-ways-to-run-shell

Rake aborted! Don't know how to build task

扶醉桌前 提交于 2019-12-04 12:42:22
I have a rake task in semester.rake file. It looks like this namespace :db do desc "generate semester data" task semester: :environment do semester = Semester.create!(name: "SummerSemseter") semester = Semester.create!(name: "WinterSemester") semester = Semester.create!(name: "Spring Semester") end end and I run the task as rake semester . This gives me error rake aborted! Don't know how to build task 'semester' (see --tasks) /home/john/.rvm/gems/ruby-2.2.4/gems/rake-11.3.0/exe/rake:27:in `<top (required)>' /home/john/.rvm/gems/ruby-2.2.4/bin/ruby_executable_hooks:15:in `eval' /home/john/.rvm

How to set up a Rake task for seeding

徘徊边缘 提交于 2019-12-04 10:11:54
(This is really a newbie question about Rake & Rails & dependencies in general. Trying to wrap my head around how all this fits together) Basically, I want a Rake task that acts like seed.rb but is called separately. It adds test data for the development environment, while my seed.rb provides basic data for all environments. The script, family_seed.rb, uses FactoryGirl to generate some records. It looks like this: require File.expand_path('../../config/environment', __FILE__) require './spec/factories' Family.delete_all Member.delete_all zinsser = Factory.create(:family, :last_name=>'Zinsser',