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 3677004
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:10:08+00:00 2026-05-19T03:10:08+00:00

I cant understand why edit and new links doesn’t work. I have controller named

  • 0

I cant understand why edit and new links doesn’t work. I have controller named CargoController and have model Car.
CargoController is:

  def new_auto

  end

  def edit_auto

  end
  def index
    @cars=Car.find_all_by_UserId(session[:user_id])
    if @cars.nil?
    end
  end

Car model is:

class Car < ActiveRecord::Base
  validates_presence_of     :TransportTypeId
  validates_presence_of     :CarModelId
  set_primary_key :CarId
  has_one :TransportType
  has_one :CarModel
  belongs_to :User
  has_many :PropertyOfCar, :dependent => :destroy
  has_many :CarProperty, :through => :PropertyOfCar
end

The View CargoController index.erb is:

<%if !@cars.blank?%>
    <table width="100%" border="0" cellpadding="0px" cellspacing=1px">
      <% @cars.each do |car|   %>
      <tr valign="top" class="<%= cycle('list-line-odd', 'list-line-even') %>">
        <td>
          <table border="0" width="100%" style="color:black">
            <tr>
              <td width="15%" align="left" valign="top" >Тип ТС:</td>
              <td width="70%" align="left" valign="top"><%= TransportType.find_by_TransportTypeId(car.TransportTypeId).Name %></td>
              <td align="right" valign="top" rowspan="2">
                <img alt=""  src="/images/Truck-icon.png"/>
              </td>
            </tr>
            <tr>
              <td width="15%" align="left" valign="top">Car model:</td>
              <td width="70%" align="left" valign="top"><%= CarModel.find_by_CarModelId(car.CarModelId).ModelName %></td>
            </tr>
            <tr>
              <td align="center" valign="top" colspan="3">
                  <label class="Chars"> Properties</label>
              </td>
            </tr>
            <tr colspan="3">
              <td>
                <%=  button_to 'Edit', :controller=>:cargo,:action=>:edit_auto,:id=>car.CarId %>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    <% end %>
    </table>
  <% end %>

the view edit and new is :

<div class="center">
 <%= render 'form' %>
</div>

The template _form is:

<%= form_for(@car) do |form| %>
<table >
      <tr>
        <td>
          <label for="transport_type">Car Type:</label>
        </td>
        <td>
          <%= form.select(:TransportTypeId, TransportType.all.collect {|p| [ p.Name, p.TransportTypeId ] }, { :include_blank => 'Select type'},{:style=>'width: 200px'}) %>
        </td>
      </tr>
      <tr>
        <td>
          <label for="transport_type">Car model:</label>
        </td>
        <td>
          <%= form.select(:CarModelId, CarModel.all.collect {|p| [ p.ModelName, p.CarModelId ] }, { :include_blank => 'Select model' },{:style=>'width: 200px'}) %>
        </td>
      </tr>
      <tr>
        <td colspan="2">
          <%= button_to "add property",{:controller=>:cargo,:action=>:new_property},{:class =>"Button_style"} %>
        </td>
      </tr>
       <tr>
        <td colspan="2" align="left">
           <%= form.submit "Add car", :class => "submit" ,:class =>"Button_style"%>
        </td>
      </tr>
    </table>
<% end %>

So then i try to add or update car rails ask a car controller or write

ActionView::Template::Error (undefined method `model_name' for NilClass:Class):
    1: <%= form_for(@car) do |form| %>
    2: <table >
    3:       <tr>
    4:         <td>. 

What shall i do to make it work?
In a routes i have

  get "cargo/index"

  get "cargo/new_auto"
match ':controller(/:action(/:id))' 
  • 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-05-19T03:10:09+00:00Added an answer on May 19, 2026 at 3:10 am

    I think that you don’t create instance variables for each actions.

    def new_auto
      @car = Car.new
    end
    
    def edit_auto
      @car = Car.find(params[:id])
    end
    

    And you should write “resources :cars” routes.rb as follwing:

    resources :cars
    

    I think that you should be able to see the new_auto page.

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

Sidebar

Related Questions

I cant seem to find much info on haskells layout features, as I understand
[edit]sigh... the spam protection here isn't letting me post the links, so I guess
I have a new web app that is packaged as a WAR as part
Can't understand why the following takes place: String date = 06-04-2007 07:05; SimpleDateFormat fmt
I can't understand the concept and, first of all, where it belongs. Is it
I am converting an excel sheet formula to java but I can't understand how
I'm reading some code in the Ogre3D implementation and I can't understand what a
Ignoring the IE case, are there any other browsers that can't understand the application/xhtml+xml
I'm using Pyro in a project, and can't seem to understand how to transfer
I understand what System.WeakReference does, but what I can't seem to grasp is a

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.