title: Run a custom rake task on rails
body: <p>I am trying to make a custom <code>rake</code> task, but I cannot seem to get it working. My code looks like this:</p>
  
  <pre><code>namespace :demotask do
  
    desc "display the current environment of rake"
    task :current_environment =&gt; :environment do
      puts "You are running rake task in #{Rails.env} environment"
    end
  
  end
  </code></pre>
  
  <p>and is placed in a file named <code>test.rake</code> under <code>lib/tasks</code>. The <code>Rakefile</code> is there, but I do get this error when running the task in the console:</p>
  
  <blockquote>
    <p><code>NameError: undefined local variable or method 'current_environment' for main:Object</code></p>
  </blockquote>
  
  <p>I tried to restart the server as well.</p>