Using a Rails helper method in a Rake task?

916 views
Skip to first unread message

Walter McGinnis

unread,
Oct 14, 2007, 5:54:41 PM10/14/07
to WellR...@googlegroups.com
Hey there,

I would like to DRY up this code, so that I don't redefine the number_to_human_size Rails helper method:


Recommendations?  I've tried wrapping the Rails method in a local method that includes the module, but I get a "can't call private method" error.

Cheers,
Walter

Bonus points:  Make this db agnostic.

Will Bryant

unread,
Oct 14, 2007, 6:41:04 PM10/14/07
to WellR...@googlegroups.com
Hi Walter,

You can just "include ActionView::Helpers::NumberHelper" into pretty much any object, including the task context  - and then call number_to_human_size directly.  Check out the attached...

Cheers,
Will
db-disk-usage-report.rake

Walter McGinnis

unread,
Oct 14, 2007, 6:53:16 PM10/14/07
to WellR...@googlegroups.com
Sweet.  I had tried that sort of.  I had wrapped the call in a local method definition which was throwing the "private method" error.  By including the module and using it directly within the task, all is well.

Cheers,
Walter
Reply all
Reply to author
Forward
0 new messages