# Different views for a single model?

**URL:** <https://www.ruby-forum.com/t/different-views-for-a-single-model/155422>\
**Category:** Rails\
**Created:** [December 11, 2008, 5:32pm UTC](https://www.ruby-forum.com/t/different-views-for-a-single-model/155422 "2008-12-11T17:32:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e95f7d/32.png) [@Bill\_V](https://www.ruby-forum.com/u/Bill_V)\
**Post date:** [December 11, 2008, 5:32pm UTC](https://www.ruby-forum.com/t/different-views-for-a-single-model/155422/1 "2008-12-11T17:32:15Z")

</div>

How could you do it, in a _RESTful_ way?

I have a very simple model with 2 attrs and each view is a  
Model.find\_all\_by\_attr1 and \_attr2. How is this modeled in REST?

I’ve been in rails for 6 months now and REST is continuing giving me  
headaches and tbh, it seems to me that it’s unsuitable for user  
centric applications, where the same information could be presented in  
many different ways. index and show simply wouldn’t cut it as it seems  
to me that they are tightly coupled to a more DB-centric approach.

(Where is index fit into REST, if REST is based on CRUD? Can’t I have  
an "index2 or index\_by\_whatever\_criteria\_I\_want, and still be  
RESTful? )

Of course, decision logic could be moved to the view layer but that  
seems like a regression to MVC.

Im tempted to stop thinking in REST terms and simply move on; Maybe I  
just need a good reason to convince myself.

thank you

---

<div class="post-metadata">

**Author:** ![Bill\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e95f7d/32.png) [@Bill\_V](https://www.ruby-forum.com/u/Bill_V)\
**Post date:** [December 11, 2008, 7:11pm UTC](https://www.ruby-forum.com/t/different-views-for-a-single-model/155422/2 "2008-12-11T19:11:16Z")

</div>

map.resources can take additional specifications for either member-level  
methods (operating on a single instance of the model), or  
collection-level methods (operating on a collection).

You can extend your routes in a RESTful fashion to your hearts content.

[http://api.rubyonrails.org/classes/ActionController/Resources.html](http://api.rubyonrails.org/classes/ActionController/Resources.html)

---

<div class="post-metadata">

**Author:** ![Bill\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e95f7d/32.png) [@Bill\_V](https://www.ruby-forum.com/u/Bill_V)\
**Post date:** [December 11, 2008, 8:30pm UTC](https://www.ruby-forum.com/t/different-views-for-a-single-model/155422/3 "2008-12-11T20:30:38Z")

</div>

On Dec 11, 10:31 am, Bill V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How could you do it, in a _RESTful_ way?
> 
> I have a very simple model with 2 attrs and each view is a  
> Model.find\_all\_by\_attr1 and \_attr2. How is this modeled in REST?

Usually I do this by specifying the view/filtering criteria as query  
parameters:

> **[应用宝官网-全网最新最热手机应用游戏下载](https://sj.qq.com)**
>
> 应用宝是腾讯旗下官方手机app应用商店，致力于为您提供海量、优质、安全、最新的安卓应用游戏下载！

This calls the index action, and with params[:attr1] = val1 and params  
[:attr2] = val2

> I’ve been in rails for 6 months now and REST is continuing giving me  
> headaches and tbh, it seems to me that it’s unsuitable for user  
> centric applications, where the same information could be presented in  
> many different ways. index and show simply wouldn’t cut it as it seems  
> to me that they are tightly coupled to a more DB-centric approach.
> 
> (Where is index fit into REST, if REST is based on CRUD? Can’t I have  
> an "index2 or index\_by\_whatever\_criteria\_I\_want, and still be  
> RESTful? )

Index and Show are both from the R of CRUD.

> Of course, decision logic could be moved to the view layer but that  
> seems like a regression to MVC.
> 
> Im tempted to stop thinking in REST terms and simply move on; Maybe I  
> just need a good reason to convince myself.
> 
> thank you

Does this help at all? The Rails conventions don’t work 100% of the  
time, but for me it works 95% of the time - I just have to think a bit  
sometimes about what my action is accomplishing, and challenge myself  
on why one on the 7 actions _wouldn’t_ suffice.

Jeff

[purpleworkshops.com](http://purpleworkshops.com)

---

<div class="post-metadata">

**Author:** ![Bill\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e95f7d/32.png) [@Bill\_V](https://www.ruby-forum.com/u/Bill_V)\
**Post date:** [December 15, 2008, 1:24pm UTC](https://www.ruby-forum.com/t/different-views-for-a-single-model/155422/4 "2008-12-15T13:24:12Z")

</div>

Thank you all. It’s still difficult to REST my brain but I’ll get  
there eventually
