# Is accessing models in views bad?

**URL:** <https://www.ruby-forum.com/t/is-accessing-models-in-views-bad/52099>\
**Category:** Rails\
**Created:** [January 10, 2006, 10:49pm UTC](https://www.ruby-forum.com/t/is-accessing-models-in-views-bad/52099 "2006-01-10T22:49:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![csn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/db5fbb/32.png) [@csn](https://www.ruby-forum.com/u/csn)\
**Post date:** [January 10, 2006, 10:49pm UTC](https://www.ruby-forum.com/t/is-accessing-models-in-views-bad/52099/1 "2006-01-10T22:49:45Z")

</div>

I do it because:

1. Different retrieved records use different  
variations of the same template, and may want  
more/fewer/different queries and present them  
differently. Plus templates can display whatever they  
want and not have to rely on the controller to assign  
it data. e.g. index1.rhtml can retrieve and display  
categories, news, calendar; index2.rhtml can retrieve  
and display categories, news, users; etc. I don’t know  
of a simple way to do this in the controller.

2. Queries inside cache blocks aren’t executed  
(right?). I don’t know of a way to do this inside a  
controller. e.g.

\<% cache ‘abc’ do %\>  
\<% for item in Stuff.find(:all, :conditions=‘abc=123’  
%\>  
…  
\<% end %\>

Any thoughts? Thanks  
CSN

* * *

Do You Yahoo!?  
Tired of spam? Yahoo! Mail has the best spam protection around

> **[Yahoo Mail - Organized Email](https://mail.yahoo.com)**
>
> It's time to get stuff done with Yahoo Mail. Just add your Gmail, Outlook, AOL or Yahoo Mail to get going. We automatically organize all the things life throws at you, like receipts and attachments, so you can find what you need fast. Plus, we've got...
