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 !

···

--
Posted via http://www.ruby-forum.com/.

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

···

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

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...

--

Mike Stok <mike@stok.ca>
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?

···

--
Posted via http://www.ruby-forum.com/\.

Maybe he meant dysfunctional? :wink:

-Dave

···

On Tue, Apr 10, 2012 at 15:57, Földes László <lists@ruby-forum.com> 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?

--
Dave Aronson: Available Cleared Ruby on Rails Freelancer
(NoVa/DC/Remote) -- see www.DaveAronson.com, and blogs at
www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.com