Rake task with args and environment

Hi all,

I need to create a rake task that both receives the environment and
some command line arguments (as per http://rubyforge.org/pipermail/rake-devel/2007-December/000352.html)

For example, creating a demo user:

namespace :db do
namespace :user do
    desc 'Create demo user'
    task :create :username, :first_name, :last_name, :password do |t,
args>
      puts "login => #{args[:login]}"
      puts "first_name => #{args[:first_name]}"
      puts "last_name => #{args[:last_name]}"
      puts "password => #{args[:password]}"
  end
end

Works fine, printing out the arguments. However, I need access to the
rails environment ( => :environment) in order to user my AR models.

What would be the correct syntax to accomplish this? I was trying
something like the line below, but no go.

task :create :username, :first_name, :last_name, :password
=> :environment do ... end

Thanks,
-Harold

Hi all,

I need to create a rake task that both receives the environment and
some command line arguments (as per http://rubyforge.org/pipermail/rake-devel/2007-December/000352.html)

[snip]

Works fine, printing out the arguments. However, I need access to the
rails environment ( => :environment) in order to user my AR models.

What would be the correct syntax to accomplish this? I was trying
something like the line below, but no go.

Read a little further from the url you linked:

task :upload, :file1, :file2, :needs => [:pre_upload] do ... end

Fred

Harold wrote:

Works fine, printing out the arguments. However, I need access to the
rails environment ( => :environment) in order to user my AR models.

What would be the correct syntax to accomplish this? I was trying
something like the line below, but no go.

Hi Harold,

Try ENV['RAILS_ENV']

Peace,
Phillip

Thanks Fred, that did it.

Harold wrote:

Thanks Fred, that did it.

On Aug 16, 10:20�pm, Frederick Cheung <frederick.che...@gmail.com>

And this is exactly why I preface many of my posts with "If I understand
correctly...". I obviously did *not* understand correctly this time.

Peace,
Phillip