# MVC question

**URL:** <https://www.ruby-forum.com/t/mvc-question/100847>\
**Category:** Rails\
**Created:** [August 1, 2006, 2:28pm UTC](https://www.ruby-forum.com/t/mvc-question/100847 "2006-08-01T14:28:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bartels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@bartels](https://www.ruby-forum.com/u/bartels)\
**Post date:** [August 1, 2006, 2:28pm UTC](https://www.ruby-forum.com/t/mvc-question/100847/1 "2006-08-01T14:28:31Z")

</div>

Should I create a separate controller for each model or should I use 1  
controller for all models?  
Having 1 “admin” controller for all backend stuff seems logic to me, but  
when I scaffold it rather makes 1 controller per model.

I’m fairly new to the MVC pattern, so what’s the prefered way of doing  
it?

I’m also wondering if the API is up to date? When scaffolding, the  
rhtml’s make use of “mymodel.send(column.name)”. I tried to lookup the  
send() function in the API(ActiveRecord::Base) but it was nowhere to be  
found.

thx in advance.

---

<div class="post-metadata">

**Author:** ![bartels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@bartels](https://www.ruby-forum.com/u/bartels)\
**Post date:** [August 1, 2006, 2:31pm UTC](https://www.ruby-forum.com/t/mvc-question/100847/2 "2006-08-01T14:31:41Z")

</div>

btw, atm I’m sticking everything in 1 controller cuz I have no idea how  
to assign 1 layout to different controllers/views.

---

<div class="post-metadata">

**Author:** ![bartels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@bartels](https://www.ruby-forum.com/u/bartels)\
**Post date:** [August 1, 2006, 2:42pm UTC](https://www.ruby-forum.com/t/mvc-question/100847/3 "2006-08-01T14:42:30Z")

</div>

Bart E. wrote:

> btw, atm I’m sticking everything in 1 controller cuz I have no idea how  
> to assign 1 layout to different controllers/views.

I’m pretty new too, but to use a layout for multiple controllers, just  
put the line:

layout “name\_of\_layout”

at the top of your controller class definition and obviously make sure a  
file with this name exists in the layouts folder.

---

<div class="post-metadata">

**Author:** ![bartels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@bartels](https://www.ruby-forum.com/u/bartels)\
**Post date:** [August 1, 2006, 2:53pm UTC](https://www.ruby-forum.com/t/mvc-question/100847/4 "2006-08-01T14:53:43Z")

</div>

On Aug 1, 2006, at 8:28 AM, Bart E. wrote:

> rhtml’s make use of “mymodel.send(column.name)”. I tried to lookup the  
> send() function in the API(ActiveRecord::Base) but it was nowhere  
> to be  
> found.
> 
> thx in advance.

I think organization of controllers is partly up to you. I tend to  
use one controller per “area” of my app (usually one model, sometimes  
not) and just use before\_filter to lock out administrative  
functions. If you’re running into path problems with the layouts  
(like I did when I was first starting) you can just use the path to  
the layout file starting just after ‘app/views/’ so if a layout was  
somewhere other than app/views/layouts you can still get at it.

The reason you can’t find send() in rails api is that it’s a ruby  
function. If you’re curious, type “ri send” on the command line.  
-Mat

---

<div class="post-metadata">

**Author:** ![bartels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@bartels](https://www.ruby-forum.com/u/bartels)\
**Post date:** [August 1, 2006, 2:57pm UTC](https://www.ruby-forum.com/t/mvc-question/100847/5 "2006-08-01T14:57:31Z")

</div>

On 8/1/06, Bart E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> rhtml’s make use of “mymodel.send(column.name)”. I tried to lookup the  
> send() function in the API(ActiveRecord::Base) but it was nowhere to be  
> found.
> 
> thx in advance.

The controller should encapsulate a logical group of actions. Your  
example  
of an admin controller to handle backend stuff is correct. The  
scoffolding  
is very rudimentary, even in the way it creates controllers. The job of  
the  
scaffolding is to create CRUD functionality on a single model (Create  
Read  
Update Delete). Sometimes this is what you need to do in production,  
often  
it is not. Your instinct to make the controllers more logically  
organize  
like actions - even though they go across multiple models - is correct.

The send() function does not show up in the rails api because it is a  
built  
in part of the Ruby language. Check out [www.rubycentral.com](http://www.rubycentral.com)

-Derrick

---

<div class="post-metadata">

**Author:** ![bartels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@bartels](https://www.ruby-forum.com/u/bartels)\
**Post date:** [August 1, 2006, 3:17pm UTC](https://www.ruby-forum.com/t/mvc-question/100847/6 "2006-08-01T15:17:44Z")

</div>

thx for the replies.  
It’s probably gonna take a while before I’ll be productive with rails  
but I’m liking it so far. 🙂
