Best way of implementing controllers for m:n model relation (Car->Parts)

Hello,

in the last few weeks I`ve taken a clooser look on Ruby and I am
actually impressed on how helpful this “toolset” is.

However, prior to ruby I was mainly working with functional languages
like ASP and PHP for web development.

So my question to you is an archtictural one, as i`m having some
difficulties on how to implement the MVC model correctly:

Let`s say I have a model “Car” and “Part”. A car can have one or more
parts (m:n).

On a specific page the user should be able to change the cars details
and it`s parts (add part, remove part, set quantity etc.).

How would you implement the controllers ?

I would have used the following approach but ran into several problems:

CarsController
–> index
–> show
–> new (needs PartsController/index to display parts)
–> create
–> edit
–> update

PartsController
–> index (displays all parts of a car)
–> show (displays single part of a car)
–> new (add part)
–> create
–> edit (set quantity)
–> update

When I tried to embed the template of “PartsController/index” into the
template “CarsController/new” by using the “render” helper in the
template it doesn`t work.

Example (CarsController/new.html.erb): <%= render @car.pars %> // empty
output

Is this approach the most common way to implement this or I am wrong ?
IF it is correct how do I include another action of another controller
in a view ?

Please be kind, I am a newbie trying the (correct) MVC way…

Thank you very much !

On 2012-04-08, at 1:19 PM, Thomas Tschofenig wrote:

CarsController
→ new (add part)

Is this approach the most common way to implement this or I am wrong ?
IF it is correct how do I include another action of another controller
in a view ?

Please be kind, I am a newbie trying the (correct) MVC way…

This looks like a Rails question, and one place to start looking for
Rails answers is at http://railscasts.com. Does
#196 Nested Model Form Part 1 - RailsCasts give you any
ideas?

Regards,

Mike

Mike S. [email protected]
http://www.stok.ca/~mike/

The “`Stok’ disclaimers” apply.

Thomas Tschofenig wrote in post #1055527:

However, prior to ruby I was mainly working with functional languages
like ASP and PHP for web development.

I think we have a terminology problem here :slight_smile:
ASP and PHP as functional languages?

On Tue, Apr 10, 2012 at 15:57, Földes László [email protected]
wrote:

Thomas Tschofenig wrote in post #1055527:

However, prior to ruby I was mainly working with functional languages
like ASP and PHP for web development.

I think we have a terminology problem here :slight_smile:
ASP and PHP as functional languages?

Maybe he meant dysfunctional? :wink:

-Dave