Advice on the definition and use of a rails controller

Hello all,

I’m a java developer who has used tapestry for web development. I’m
trying to use rails now and am finding it very interesting. However
I’m by confused by the amount of functionality that should be included
in a controller.

In tapestry I am used to having multiple components on a page, where
each components logic is encapsulated in its own class, and the logic
for the page is encapsulated in a page class.

Can I think of the rails controller as a page class, where the logic
for each page is embedded in it and most of the actions in the
controller return the same view?

For some of you this might seem trivial, but until I get my head round
this I am not going to be very productive. I have read AWD 2nd edition
and am still not not sure how to approach the controllers. Can anybody
help?


Thanks

A Jabbar Azam

On 1/21/07, Jabbar [email protected] wrote:

Can I think of the rails controller as a page class, where the logic
for each page is embedded in it and most of the actions in the
controller return the same view?

I would say: Rails is not Tapestry. Forget Tapestry.

Controller actions should ‘set up’ the environment for a view. They
should be, mostly, brief. Your business logic should live in your
models. Your display logic should live in view helpers. Your
controller just needs to glue some things together and prepare
instance variables for your view. Different actions in a controller
usually each have a unique view and may not even share the same
layout.

Get a hot cup of tea and spend some time reading Jamis B.'s blog:
http://weblog.jamisbuck.org/

It has many great examples illustrating what goes where.


Chris W.

Hello Chris,

I would say: Rails is not Tapestry. Forget Tapestry.
Unfortunately I have legacy apps which need maintaining and some are
under development :frowning:

I think knowing other languages and frameworks will make you a better
programmer … fortunately Ruby and Rails gives me the same excitement
as I had when I had my Commodore 64 and was writing simple text games
for it in Commodore Basic.

Controller actions should ‘set up’ the environment for a view. They
should be, mostly, brief. Your business logic should live in your
models. Your display logic should live in view helpers. Your

I had the same feelings about view helpers, but weren’t sure if it was
the rails ways. I find it difficult to not think about components, but
I guess this is best practice in the rails world.

Get a hot cup of tea and spend some time reading Jamis B.'s blog:
http://weblog.jamisbuck.org/

You mean a cup of java :wink: Don’t want to start anything, but I think
both languages can coexist e.g. JRuby. I will definitely read all of
Jamis B.'s log …

On 21/01/07, Chris W. [email protected] wrote:

should be, mostly, brief. Your business logic should live in your


Chris W.
http://errtheblog.com


Thanks

A Jabbar Azam