Questions tagged [rake-task]

Task is the basic unit of work in a Rakefile.

Tasks have associated actions (possibly more than one) and a list of prerequisites. When invoked, a task will first ensure that all of its prerequisites have an opportunity to run and then it will execute its own actions.

Tasks are not usually created directly using the new method, but rather use the file and task convenience methods.

689 questions
110
votes
25 answers

PG undefinedtable error relation users does not exist

I saw this question up before, but only for rspec. I haven't created test yet because it's too advanced for me but one day soon i will! :P I get this error when I try to sign-up/login into my app. I used devise to create user and also omniauth2 to…
Naomi K
  • 1,437
  • 4
  • 13
  • 20
54
votes
5 answers

Simple rails rake task refuse to run with error "Don't know how to build task", why?

I have this simple rake task which refuses to run. I just don't see why it looks correct. Who can pinpoint me to the probably very simple mistake I made? Thank you! /lib/tasks/reindex.rb: namespace :db do desc "Tire reindex profiles" task…
Rubytastic
  • 15,001
  • 18
  • 87
  • 175
45
votes
5 answers

rake db:create encoding error with postgresql

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…
fespinozacast
  • 2,484
  • 4
  • 23
  • 38
43
votes
1 answer

Rails Rake Task - Access to model class

I would like to define a Ruby (1.9.2)-on-Rails(3.0.5) rake task which adds a user to the User table. The file looks like this: #lib/tasks/defaultuser.rake require 'rake' namespace :defaultuser do task :adduser do u=User.new …
Jay Godse
  • 15,163
  • 16
  • 84
  • 131
32
votes
5 answers

How to fix "uninitialized constant" in a Rake task

I have a problem when I do: namespace :xaaron do task :get_roles do roles = Xaaron::Role.all puts roles end task :get_role, [:name] do |t, args| role = Xaaron::Role.find(args[:name].parameterize) puts role end end The…
SeekingTruth
  • 1,044
  • 2
  • 15
  • 23
32
votes
2 answers

Does Rails run initializers for rake task?

Are the scripts from config/initializers executed when I run rake task?
Paul
  • 25,812
  • 38
  • 124
  • 247
31
votes
2 answers

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

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…
dr.
  • 1,429
  • 12
  • 18
29
votes
3 answers

If i close my terminal would a rake task started on Heroku continue to run

I have a script which in need to run on my data. I have made a rake task for that. If i start the rake task by using heroku run rake my_task:my_action and after a while my internet disconnects. What would happen. Will the task continue to run as it…
AMBasra
  • 969
  • 8
  • 24
28
votes
4 answers

Rails: rake task with arguments not working

Here is my rake task namespace :users do task :change_role, [:role] => :environment do |t, args| puts args.role end end I am calling it like this: rake users:change_role["role"] but I am getting this error no matches found:…
dennismonsewicz
  • 25,132
  • 33
  • 116
  • 189
24
votes
2 answers

Invoke rake task with arguments from another task

I would like to be able to pass arguments for a task that I have to call from another task Invoking without arguments works for me like this: Rake::Task["mytask1"].invoke However with arguments like this it does…
Karim Mtl
  • 1,223
  • 3
  • 11
  • 39
20
votes
3 answers

How to execute commands within Rake tasks?

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…
palani
  • 4,661
  • 8
  • 31
  • 36
19
votes
3 answers

Removing whitespaces in a CSV file

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…
xdsemx
  • 1,159
  • 1
  • 8
  • 14
18
votes
4 answers

My rake task is not showing up in rake -T

I don't know wtf is going on but I just created a new Rails app and can't get any rake tasks to work or show up in $ rake -T lib/tasks/hello.rake namespace :hello do desc "hello" task :you do puts "hello" end end $ rake -T it does not…
Timmy Von Heiss
  • 2,160
  • 17
  • 39
15
votes
2 answers

Dealing with very long running rake task

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 …
JZ.
  • 21,147
  • 32
  • 115
  • 192
15
votes
8 answers

Skipping the first line when reading in a file in 1.9.3

I'm using ruby's File to open and read in a text file inside of a rake task. Is there a setting where I can specify that I want the first line of the file skipped? Here's my code so far: desc "Import users." task :import_users => :environment…
Andrew Lauer Barinov
  • 5,694
  • 10
  • 59
  • 83
1
2 3
45 46