# Rake question

**URL:** <https://www.ruby-forum.com/t/rake-question/141923>\
**Category:** Rails\
**Created:** [July 1, 2008, 8:10pm UTC](https://www.ruby-forum.com/t/rake-question/141923 "2008-07-01T20:10:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkoebbe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ec9cab/32.png) [@pkoebbe](https://www.ruby-forum.com/u/pkoebbe)\
**Post date:** [July 1, 2008, 8:10pm UTC](https://www.ruby-forum.com/t/rake-question/141923/1 "2008-07-01T20:10:48Z")

</div>

I’ve searched this group and google, but have not found the answer to my  
question. If there is a post about it somewhere, I’d greatly appreciate  
a link. I also started to dig into the rake code, but, frankly, didn’t  
understand it.

Question:

Why does it seem that :environment is required in order to have  
ActiveRecord::Base.configurations populated with the contents of  
database.yml.

Explanation:

namespace :phillip do  
task :mytask do  
ActiveRecord::Base.configurations.each\_value do |config|  
p config[‘database’]  
end  
end  
end

prints nothing. Yet

namespace :phillip do  
task :mytask =\> :environment do  
ActiveRecord::Base.configurations.each\_value do |config|  
p config[‘database’]  
end  
end  
end

outputs the database names in my database.yml file.

I understand that if I’m actually trying to do something, I’d need the  
environment. But it seems that the configurations would be available  
without knowing a specific environment.

Peace,  
Phillip

---

<div class="post-metadata">

**Author:** ![pkoebbe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ec9cab/32.png) [@pkoebbe](https://www.ruby-forum.com/u/pkoebbe)\
**Post date:** [July 1, 2008, 8:13pm UTC](https://www.ruby-forum.com/t/rake-question/141923/2 "2008-07-01T20:13:51Z")

</div>

:environment is a task that loads up environment.rb.

When you do

task :foo =\> :environment

you’re saying “my task depends on another task called :environment, so  
invoke that first , and then do my stuff”

On Tue, Jul 1, 2008 at 1:10 PM, Phillip K. \<

---

<div class="post-metadata">

**Author:** ![pkoebbe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ec9cab/32.png) [@pkoebbe](https://www.ruby-forum.com/u/pkoebbe)\
**Post date:** [July 1, 2008, 9:04pm UTC](https://www.ruby-forum.com/t/rake-question/141923/3 "2008-07-01T21:04:16Z")

</div>

On 1 Jul 2008, at 19:10, Phillip K. wrote:

> outputs the database names in my database.yml file.
> 
> I understand that if I’m actually trying to do something, I’d need the  
> environment. But it seems that the configurations would be available  
> without knowing a specific environment.

Well at a very basic level, ActiveRecord::Base.configurations isn’t  
going to populate itself. rails isn’t even loaded if your task doesn’t  
depend on :environment

Fred

---

<div class="post-metadata">

**Author:** ![pkoebbe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ec9cab/32.png) [@pkoebbe](https://www.ruby-forum.com/u/pkoebbe)\
**Post date:** [July 1, 2008, 9:06pm UTC](https://www.ruby-forum.com/t/rake-question/141923/4 "2008-07-01T21:06:30Z")

</div>

Brian H. wrote:

> :environment is a task that loads up environment.rb.
> 
> When you do
> 
> task :foo =\> :environment
> 
> you’re saying “my task depends on another task called :environment, so  
> invoke that first , and then do my stuff”

Thanks for the explanation, Brian. That makes much more sense now. I see  
that I was confusing a task with a variable/parameter/argument.

Peace,  
Phillip

---

<div class="post-metadata">

**Author:** ![pkoebbe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ec9cab/32.png) [@pkoebbe](https://www.ruby-forum.com/u/pkoebbe)\
**Post date:** [July 2, 2008, 3:44am UTC](https://www.ruby-forum.com/t/rake-question/141923/5 "2008-07-02T03:44:56Z")

</div>

Thanks for that Brian I didn’t know either!

---

<div class="post-metadata">

**Author:** ![pkoebbe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ec9cab/32.png) [@pkoebbe](https://www.ruby-forum.com/u/pkoebbe)\
**Post date:** [July 1, 2008, 9:09pm UTC](https://www.ruby-forum.com/t/rake-question/141923/6 "2008-07-01T21:09:25Z")

</div>

Frederick C. wrote:

> Well at a very basic level, ActiveRecord::Base.configurations isn’t  
> going to populate itself. rails isn’t even loaded if your task doesn’t  
> depend on :environment
> 
> Fred

Thanks, Fred. I’m understanding now. I haven’t ventured into rake until  
now and didn’t get it. I read through some of the rake docs, but  
apparently didn’t actually digest anything.

Phillip
