title: How to access variables across multiple rake tasks with Ruby on Rails
body: <p>I've seen a few solutions that didn't seem to work for me. Suppose I have the following code-</p>
  
  <pre><code>  namespace :genie do
  
      task :test =&gt; :environment do
        test_user = User.find_or_create_by_username('test') do |i|
            i.email = 'email@email.com'
      end
  
      task :test_reset =&gt; :environment do
  
        test_user.update_attributes({
          :email =&gt; 'test@email.com',       
        })
  
      end
  </code></pre>
  
  <p>This code fails when running rake genie:test, rake genie:test_reset because test_user is not defined in the second rake task. How can I call test_user without having to define it each time?</p>