# Where to put helper fns for fixtures?

**URL:** <https://www.ruby-forum.com/t/where-to-put-helper-fns-for-fixtures/197193>\
**Category:** Rails\
**Created:** [March 7, 2010, 8:55pm UTC](https://www.ruby-forum.com/t/where-to-put-helper-fns-for-fixtures/197193 "2010-03-07T20:55:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [March 7, 2010, 8:55pm UTC](https://www.ruby-forum.com/t/where-to-put-helper-fns-for-fixtures/197193/1 "2010-03-07T20:55:44Z")

</div>

I’m writing a fixture in test/fixtures/parrots\_model.yml, and I’m  
happily using ERB to flesh out my fixture. Suddenly, I realize that I  
need a helper function to call from my erb code, such as:

polly:  
subtype: parakeet  
weight\_kg: \<%= ounces\_to\_kg(22.3) %\>

alex:  
subtype: african gray  
weight\_kg: \<%= ounces\_to\_kg(170.3) %\>

Where’s the right place to stash the “ounces\_to\_kg()” function so that  
it’s available when I rake db:load:fixtures? (And does the answer  
change if its a method specific to the parrot model?)

tia.

---

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [March 9, 2010, 6:48pm UTC](https://www.ruby-forum.com/t/where-to-put-helper-fns-for-fixtures/197193/2 "2010-03-09T18:48:27Z")

</div>

Fearless F. wrote:

> I’m writing a fixture in test/fixtures/parrots\_model.yml, and I’m  
> happily using ERB to flesh out my fixture. Suddenly, I realize that I  
> need a helper function to call from my erb code, such as:
> 
> polly:  
> subtype: parakeet  
> weight\_kg: \<%= ounces\_to\_kg(22.3) %\>
> 
> alex:  
> subtype: african gray  
> weight\_kg: \<%= ounces\_to\_kg(170.3) %\>
> 
> Where’s the right place to stash the “ounces\_to\_kg()” function so that  
> it’s available when I rake db:load:fixtures?

Nowhere, because IMHO it’s never right to use Rails fixtures. Use  
factories instead – I’m fond of Machinist, but there are other  
solutions out there. This will solve your problem and also give you  
many other advantages.

Fixtures are a horribly broken feature of Rails. Don’t bother with  
them.

> (And does the answer  
> change if its a method specific to the parrot model?)
> 
> tia.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [March 10, 2010, 2:14am UTC](https://www.ruby-forum.com/t/where-to-put-helper-fns-for-fixtures/197193/3 "2010-03-10T02:14:42Z")

</div>

Marnen Laibow-Koser wrote:

> > …snip…  
> > Where’s the right place to stash the “ounces\_to\_kg()” function so that  
> > it’s available when I rake db:load:fixtures?
> 
> Nowhere, because IMHO it’s never right to use Rails fixtures. Use  
> factories instead – I’m fond of Machinist, but there are other  
> solutions out there. This will solve your problem and also give you  
> many other advantages.
> 
> Fixtures are a horribly broken feature of Rails. Don’t bother with  
> them.

Thanks Marnen – very helpful.
