views:

35

answers:

1

I've got a rake task on a rails app that needs one parameter, called USER_ID.

I think I'd like to throw an exception that halts the execution. This is what my task looks like:

desc "My rake task"
task :my_task => :envionment do

  user_id = ENV["USER_ID"] or # THROW SOMETHING HERE

  # ... do stuff with user_id

end

What code goes on THROW SOMETHING HERE?

+2  A: 

What about something like this:

raise "Missing USER_ID!\n\ne.g: rake my_task USER_ID=6" if (user_id = ENV['USER_ID']).blank?
tsdbrown
wow, so simple! Thanks a lot.
egarcia
No problem , glad to help.
tsdbrown