Forum: Ruby on Rails Best practices for handling associations in ctrlrs/views

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
50aeab2d063ed4514ad5d2d4a371e6d8?d=identicon&s=25 Jim Nicholson (jnicholson)
on 2006-02-14 05:14
Forgive me if this topic has come up before. I'm new to Rails (from a
Java background, with a good deal of Perl as well.) I'm very much
attracted to the idea of having an integrated MVC stack, and from what I
see, Rails is "the right thing."

To set up my question, here's some background. In an app I am building,
there are three models:

an item has many attributes
an attribute belongs to an item
an attribute belongs to a type
a type has many attributes

For editing items and types, I am building views by extending the
scaffolding. For  attributes, though, the situation is different. Since
it makes little sense to maintain an attribute independent of the item
that owns it, I'm thinking of building the CRUD logic for attributes
into the edit view for items. My thought was to use AJAX for this.

Assuming for a moment that this is the desired approach, I can see
several ways to implement it. For example, the methods required to
create a new attribute or delete an existing one would be called by
AJAX. I could thus

1) implement the action methods on the ItemController object, or
2) implement the action methods on the AttributeController object.

Similarly, the "view" logic for attributes associated with an item will
be invoked for each attribute that belongs to an item. This logic could:

1) be written as a partial, and rendered inside of logic within the edit
view for an item (render :partial)

2) be written as an action and view, and be rendered via logic within
item's view that invokes render :action

3) be written as a partial, and be called from within a helper method in

I'm sure there are other ways to do this. My question (to those who
presumably have been around Rails longer than I) is, how would *you* do
this, and why would you do it that way?

= Jim
This topic is locked and can not be replied to.