MVC Best Foot Forwarded

I’d like to know the best way forward with regards to Rails and MVC.
This is really concerning the controller.

I have a ‘register’ controller which allows a company to register with
the site. Once registered, they go into a backend where they can add
employees, activities etc.

At the moment, these are all handled by the ‘register’ controller but to
me, it’s heading the wrong way.

Each object has it’s own model for example Company, Employee, Activity,
Qualification.

my register controller is now going along these lines with regards to
actions … add_employee, update_employee, add_activity,
update_activity etc.

Does that make sense or in this case, should each object have a
controller called from the main menu ‘register.rhtml’ such as

link_to ‘My Emplyees’, :controller => ‘employee’, :action => ‘do_sth’
link_to ‘My Activities’, :controller => ‘activity’, :action => ‘do_sth’

CIA

-Ants


What kind of emailer are you? Find out today - get a free analysis of
your email personality. Take the quiz at the Yahoo! Mail Championship.

I would definitely go with the latter.
Also, I would take a look at any of the numerous blog entries that are
cropping up regarding Rails and REST… it’s a style of designing
controllers/models that might make sense to you, given the kind of site
you’re building.

I also might think about, even if you don’t go with rest, abstracting
the
register controller to be an action of a different controller.
You might have several administrative tasks that are associated with an
overal business… updating business info, maybe adding or removing
admin
users to their business account… you may want to make a controller
that
contains functions pertaining to overall business activities, and make
register an action of that controller.

I would compare this to something like having a regular user
login/logout
type of situation.
Instead of having a register controller for when a new user signs up,
you
might want to have a User controller with a register action, a login
action,
a logout action, an edit action, etc. Again, this lends itself to REST,
so
definitely read up on that.

If you are using Rails 1.1.6 then spagetti code will result. If you
are using Rails 1.2.2 to build a RESTful app, then your design becomes
clean when you embrace the RESTful design concepts.

All registration activities will be handled by RegistrationController,
employee management by EmployeeController and so on.

Yeah, have been thinking about this and was also wondering about the
controller noun / verb thing. So, that’s clearer :wink:

The way forward now looks like being something like UserContoller (for
the company) and controllers for EmployeeController etc. After
registration, go to UserAdminController which will link to the other
contollers.

What d’ya think of that?! Cleaner … correct?

Thanks for replying and taking an interest, too. As a developer, setting
things up is the hardest part, the actual work isn’t a problem. But if
the design isn’t intuitive from the beginning then it’s just plain
wrong!!

Luke I. [email protected] wrote: Actually, if he were building a
restful app, I would imagine registration would, as I said, become a
member of other controllers… REST generally implies that the
controllers be nouns, not verbs, and that verbs be the actions of the
controllers.

On 2/26/07, Bala P. [email protected] wrote:
If you are using Rails 1.1.6 then spagetti code will result. If you
are using Rails 1.2.2 to build a RESTful app, then your design becomes
clean when you embrace the RESTful design concepts.

All registration activities will be handled by RegistrationController,
employee management by EmployeeController and so on.

On 2/26/07, Anthony G. [email protected] wrote:

I’d like to know the best way forward with regards to Rails and MVC. This is
really concerning the controller.


New Yahoo! Mail is the ultimate force in competitive emailing. Find out
more at the Yahoo! Mail Championships. Plus: play games and win prizes.

On 2/27/07, Anthony G. [email protected] wrote:

Yeah, have been thinking about this and was also wondering about the
controller noun / verb thing. So, that’s clearer :wink:

The way forward now looks like being something like UserContoller (for the
company) and controllers for EmployeeController etc. After registration, go
to UserAdminController which will link to the other contollers.

What d’ya think of that?! Cleaner … correct?

The UserAdmin thing remains somewhat of a bone of contention in a lot of
communities… it seems as though that’s a fairly good way to structure
it,
but if you’re going pure REST, then probably it isn’t: a controller name
should imply the noun on which it’s verb actions take place, and in this
case, you’re not performing an action on “a useradmin”… but
meta-controllers are a fact of life when it comes to doing any kind of
decent sized web app.

That being said, in your particular case I think you might be able to do
something like having a different layout depending on whether or not
someone
is logged in, with the logged in layout having a menu bar with links to
the
various controllers, so you can get from any controller to any other
controller without having to use the meta-controller.

Thanks for replying and taking an interest, too. As a developer, setting

things up is the hardest part, the actual work isn’t a problem. But if the
design isn’t intuitive from the beginning then it’s just plain wrong!!

**

You’re welcome, I agree, and damn right.

Actually, if he were building a restful app, I would imagine
registration
would, as I said, become a member of other controllers… REST generally
implies that the controllers be nouns, not verbs, and that verbs be the
actions of the controllers.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs