Note that there are some explanatory texts on larger screens.

plurals
  1. POundefined method "_index_path" form_for problem
    primarykey
    data
    text
    <p>I'm trying to generate a form using the form_for helper in RoR but I am encountering what seems to be a routing error. Here are the relevant files:</p> <p><strong>models/equipment.rb</strong></p> <pre><code>class Equipment &lt; ActiveRecord::Base attr_accessible :name, :tracking_number validates :tracking_number, :presence =&gt; true, :uniqueness =&gt; { :case_sensitive =&gt; true } end </code></pre> <p><strong>controllers/equipments_controllers.rb</strong></p> <pre><code>class EquipmentsController &lt; ApplicationController def index @equipments = Equipment.paginate(:page =&gt; params[:page]) end def new @equipment = Equipment.new end end </code></pre> <p><strong>views/equipments/new.html.rb</strong></p> <pre><code>&lt;h1&gt;Add an equipment&lt;/h1&gt; &lt;%= form_for (@equipment) do |f| %&gt; &lt;%= render 'shared/error_messages', :object =&gt; f.object %&gt; &lt;div class="field"&gt; &lt;%= f.label :name %&gt; &lt;br /&gt; &lt;%= f.text_field :name %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :tracking_number %&gt;&lt;br /&gt; &lt;%= f.text_field :tracking_number %&gt; &lt;/div&gt; &lt;%= f.submit "Add" %&gt; &lt;% end %&gt; </code></pre> <p><strong>routes.rb</strong></p> <pre><code>EquipmentTracking::Application.routes.draw do root :to =&gt; "equipments#index" resources :equipments end </code></pre> <p>I don't see anything wrong but they output the following:</p> <pre><code>NoMethodError in Equipments#new Showing /opt/ror/equipment_tracking/app/views/equipments/new.html.erb where line #2 raised: undefined method `equipment_index_path' for #&lt;#&lt;Class:0xb6725a2c&gt;:0xb6724640&gt; </code></pre> <p>If I changed it to </p> <pre><code>&lt;%= form_for (:equipment) do |f| %&gt; </code></pre> <p>it seems to work ok. I'm also certain that the static variable @equipment is getting passed since </p> <pre><code>&lt;%= @equipment %&gt; </code></pre> <p>returns</p> <pre><code>#&lt;Equipment:0xb685ece0&gt; </code></pre> <p>I am at a loss here. I just did what I did while I was following the railstutorial.org book and I was able to finish the book.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload