Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7780553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:56:06+00:00 2026-06-01T18:56:06+00:00

i`ve a theoretical question on how to implement the MVC concept the best way

  • 0

i`ve a theoretical question on how to implement the MVC concept the best way in Ruby (as i am more familiar with non-MVC -thx for the hint- languages like ASP, PHP).

In my example app you have to manage a Car and its Parts. Following this I would (in my opinion) implement the following two controllers:
– CarsController
– PartsController

Both have its default actions (index,show,edit,delete).

In the “index” action of the PartsController all linked parts for the car are displayed.

In the “index” action of the CarsController all car details are getting displayed and additionally I would include the content of the “index” action of the PartsController passing the cars id to it (or those in session).

Example layout
(CarsController/show/1)
– Car: Porsche GT
– Brand: Porsche
– Model: GT
– PS: 400
– Parts (coming from PartsController/index, parts of car were cached by CarsController before):
— Doorlock
— Engine 400

I tried using

render "cars/index"  
render :action => "cars/index"  
render :template => "cars/index"  
render :controller => "cars", :action => "index"

in my index.html.erb template but no one of them works (I everytime get the error message “template is missing”).

Because I had a lot of trouble with this already I think my concept/implementation may be wrong.

Any suggestions on this to find a better way ?

Thank you for your help !

UPDATE:

Okay here is a more specific example.Lets say the user goes to localhost/cars/1. Here are the templates of my controllers for doing this:

app/view/cars/show.html.erb

<%= form_for(@car) do |f| %>
  <div class="field">
    <%= f.label :brand %><br />
    <%= f.text_field :brand %>
  </div>
  <div class="field">
    <%= f.label :model %><br />
    <%= f.text_field :model %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>
<%= render "parts/index" %>

app/view/parts/index.html.erb

<table>
  <% @parts.each do |part| %>
  <tr id="part-<%= part.id %>">
    <td><%= part.amount %></td>
    <td><%= part.price_total %></td>
  </tr>
  <% end %>
</table>

Parts are loaded from cache therefore no car id needed for PartsController (not yet)!

routes.rb

resources :cars do
  resources :parts
end

Then i`ll get the following error:

Missing partial parts/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
* “D:/Dev/Ruby/MyCRM/app/views”
* “C:/Ruby193/lib/ruby/gems/1.9.1/gems/datagrid-0.5.3/app/views”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:56:08+00:00Added an answer on June 1, 2026 at 6:56 pm

    It like what you’re trying to do is called ‘rendering a partial’ in Rails.

    The basic idea is, you have a stub piece of html (in this case, a parts template to render a list of parts for a certain car), and that piece gets included in one or more full pages.

    render "parts/index"
    

    isn’t working, because it’s looking for a partial named ‘index’ under the parts folder, not a full page. By convention, partials in Rails are named with a leading underscore.

    To get this to work, you should create a partial, i.e., app/views/parts/_list.html.erb

    The second part is, that partial will need to have access to the parts list. Unless your car controller creates an @parts variable, this will need to be deduced. The way this is done in practice is by passing local variables. So, you’d rewrite _list.html.erb to use ‘parts’ instead of ‘@parts’, then in your car controller, you’d render it like this:

    render "parts/list", :locals => {:parts => @car.parts}
    

    in your index for parts, if you want to list all the parts, you’d render the partial like this:

    render "list", :locals => {:parts => @parts}
    

    for more information, and a more detailed walkthrough, read:
    http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very theoretical question: Is there a way to ban the use
This is more of a theoretical question than an actual problem I have. If
I'd like to ask your opinion on this. This is a theoretical question. I'm
More of a theoretical question, but wouldn't it make more sense to have only
This is a more theoretical question about macros (I think). I know macros take
This is more a theoretical question than a practical one, but given I undestand
This is more of a theoretical question than code: What i did till now
This is a theoretical question, I was wondering if there is a good way
This is a theoretical question more than anything else. In the case of C#
it's a theoretical question: suppose I come up with an outstanding new scripting language

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.