# Tidying up views

**URL:** <https://www.ruby-forum.com/t/tidying-up-views/114798>\
**Category:** Rails\
**Created:** [September 17, 2007, 5:13pm UTC](https://www.ruby-forum.com/t/tidying-up-views/114798 "2007-09-17T17:13:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tobycatlin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@tobycatlin](https://www.ruby-forum.com/u/tobycatlin)\
**Post date:** [September 17, 2007, 5:13pm UTC](https://www.ruby-forum.com/t/tidying-up-views/114798/1 "2007-09-17T17:13:43Z")

</div>

Hi,

I have the following code in one of my partials and it’s slightly  
ridiculous so I was wondering whether anyone could give me some hints  
as to the best way to tidy it up. The formatting performed here gets  
performed in a number of places throughout the views.

I’m not sure whether to add methods to the model to deal with this  
formatting or to use helpers or what.

I’d also be able to go the other way when it comes to the data fields,  
i.e., be able to enter ‘1.8 M’ in a form field and have that converted  
to bytes.

 \<%= top\_talker\_row.rank %\> \<%= h top\_talker\_row.ip\_address %\> \<%= h top\_talker\_row.date\_first\_seen.to\_s(:db) %\> \<%= h top\_talker\_row.data\_date.date.strftime("%Y-%m-%d")%\> \<%= h number\_to\_time(top\_talker\_row.duration) %\> \<%= h top\_talker\_row.protocol.humanize %\> \<%= h number\_with\_delimiter(number\_with\_precision(top\_talker\_row.flows, 0)) %\> \<%= h number\_with\_delimiter(number\_with\_precision(top\_talker\_row.packets, 0)) %\> \<%= h number\_to\_human\_size(top\_talker\_row.bytes) %\> \<%= h number\_with\_delimiter(number\_with\_precision(top\_talker\_row.packets\_per\_second, 0)) %\> \<%= h number\_with\_delimiter(number\_with\_precision(top\_talker\_row.bits\_per\_second, 0)) %\> \<%= h number\_to\_human\_size(top\_talker\_row.bytes\_per\_packet) %\> \<%= h top\_talker\_row.network.name.humanize %\> \<%= h top\_talker\_row.top\_talker\_type.name.titlecase %\> \<%= link\_to( image\_tag('icons/application\_form\_magnify.png', :alt =\> 'Show'), top\_talker\_row, :title =\> 'Show' ) %\> 

Any help would be appreciated,  
Thanks,  
Toby

---

<div class="post-metadata">

**Author:** ![tobycatlin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@tobycatlin](https://www.ruby-forum.com/u/tobycatlin)\
**Post date:** [September 17, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/tidying-up-views/114798/2 "2007-09-17T17:28:48Z")

</div>

On Sep 17, 8:12 am, Toby C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I’d also be able to go the other way when it comes to the data fields,  
> i.e., be able to enter ‘1.8 M’ in a form field and have that converted  
> to bytes.

that part’s easy:  
[http://api.rubyonrails.com/classes/ActiveSupport/CoreExtensions/Numeric/Bytes.html](http://api.rubyonrails.com/classes/ActiveSupport/CoreExtensions/Numeric/Bytes.html)
