I’m a newbie to rails, and really to the whole DRY and MVC thing as
well, except where I accidentally fell into things doing it my own way
in the past.
I’ve got a fairly complex DB structure I want to create an interface for
using Rails. Getting simple tables to display, edit, save, not too much
problem there. But where I’m having trouble is figuring out where to
place some code I have had to write to get info from multiple tables
into one view. For example, for a list view of “projects” (main table),
I have this code in the list.rhtml:
<% odd_or_even = 0 for project in @projects @project_translations = ProjectTranslation.find(project.id) @business_unit = BusinessUnit.find(project.business_unit_id) @requestor = User.find(project.requester_user_id) @vendor_projects =
@vendor = Vendor.find(@vendor_projects.vendor_id)
odd_or_even = 1 - odd_or_even
This code I would probably need in other views as well. For the list
that customers see, for individual record views, etc. The question is:
where should I be putting that code? In the controller? In the model?
and how, exactly?
I have another question semi-related to this about how ids work and why
I have to do find all the time, but I’ll post that in a different