# How to get human readable size in controller

**URL:** <https://www.ruby-forum.com/t/how-to-get-human-readable-size-in-controller/133192>\
**Category:** Rails\
**Created:** [March 28, 2008, 4:33pm UTC](https://www.ruby-forum.com/t/how-to-get-human-readable-size-in-controller/133192 "2008-03-28T16:33:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iqbalhyd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d78d45/32.png) [@iqbalhyd](https://www.ruby-forum.com/u/iqbalhyd)\
**Post date:** [March 28, 2008, 4:33pm UTC](https://www.ruby-forum.com/t/how-to-get-human-readable-size-in-controller/133192/1 "2008-03-28T16:33:57Z")

</div>

hi,

```
     i know i can use human_size helper in views, but what if I need 

```

to  
emit human readable size in the controller e.g. in an error message?

–  
Ishaq  
[http://blogs.kahaf.com/ishaq](http://blogs.kahaf.com/ishaq)

- Programming can be fun, so can be cryptography, however they should  
not be  
combined …

---

<div class="post-metadata">

**Author:** ![iqbalhyd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d78d45/32.png) [@iqbalhyd](https://www.ruby-forum.com/u/iqbalhyd)\
**Post date:** [March 31, 2008, 6:39pm UTC](https://www.ruby-forum.com/t/how-to-get-human-readable-size-in-controller/133192/2 "2008-03-31T18:39:21Z")

</div>

find the relevant code from human\_size, copy it, and put it someplace  
that’s accessible to your models

---

<div class="post-metadata">

**Author:** ![iqbalhyd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d78d45/32.png) [@iqbalhyd](https://www.ruby-forum.com/u/iqbalhyd)\
**Post date:** [April 1, 2008, 6:42am UTC](https://www.ruby-forum.com/t/how-to-get-human-readable-size-in-controller/133192/3 "2008-04-01T06:42:38Z")

</div>

Here’s a good suggestion:

> **[\[Rails\] Calling view helpers from your controller](https://calvincorreli.com/blog/1017-rails-calling-view-helpers-from-your)**
>
> When developing with Rails, I often find myself wanting to use the truncate or pluralize text helpers from a controller when I’m setting the flash ...

-Danimal
