Rake Task: passing params and return values

H

Harp Oon

1. Is there a way to pass params to a rake task and have it return
values?

2. I have seen the ENV var being used to pass in the args to rake. Is it
thread safe? Are there any unintended consequences if two controllers
execute a new task?

3. Is it advisable to invoke a rake task (from a controller) to update
the DB?
 
H

Harp Oon

Harp said:
1. Is there a way to pass params to a rake task and have it return
values?

2. I have seen the ENV var being used to pass in the args to rake. Is it
thread safe? Are there any unintended consequences if two controllers
execute a new task?

3. Is it advisable to invoke a rake task (from a controller) to update
the DB?

My tasks.rake file has:

task :my_script => :environment do
puts "ID: = #{args.user_id}"
end

and I invoke it using:

load "#{RAILS_ROOT}/Rakefile"
def update_user
Rake::Task["my_script"].invoke
end

Using the code above, how would I pass in arguments to the script?
 
J

Julian Leviston

Hi,

Why use rake to update the database? You're better off using the
controller to update the database, with a model or two - that is,
after all, what the model was designed for.

Julian.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top