I have this error in form_for Undefined method equipment_index_path

Asked

Viewed 24 times

1

I’m trying to make a form_for to register an equipment, but whenever it goes to the view to create the equipment get error.

Model of Equipment:

class Equipment < ApplicationRecord
  validates :name, presence: true
  has_many :orderequipments, dependent: :destroy
  has_many :orders, through: :orderequipments
end

Controller:

def new
   @equipment = Equipment.new
 end

 def create
   @equipment = Equipment.new(equipment_params)
   if @equipment.save
     redirect_to equipments_path
   else
     render :new
   end
 end

 def equipment_params
   params.require(:equipment).permit(:name)
 end

And the view of new:

<div class="container">
  <div class="container-form">
  <%= simple_form_for(@equipment) do |f| %>
    <div class="product-new text-center">Cadastro de Equipamento:</div>
    <div class="form-inputs">
      <%= f.input :name, label: "Equipamento" %>
    </div>
    <div class="form-actions text-center">
      <%= f.button :submit, "Enviar" %>
    </div>
  <% end %>
  </div>
</div>

But when it goes to view of new it always appears to me this error:

NoMethodError in Equipments#new
Showing /home/eduardo/code/eduardototi/vegoorapp/app/views/equipments/new.html.erb where line #3 raised:

undefined method `equipment_index_path' for #<#<Class:0x00007fac0c0d4480>:0x00007fac0c0e2b98>
Did you mean?  equipment_path
Extracted source (around line #3):

1 <div class="container">
2  <div class="container-form">
3  <%= simple_form_for(@equipment) do |f| %>
4    <div class="product-new text-center">Cadastro de Equipamento:</div>
5    <div class="form-inputs">
6      <%= f.input :name, label: "Equipamento" %>  

Rails.root: /home/eduardo/code/eduardototi/vegoorapp

Application Trace | Framework Trace | Full Trace
app/views/equipments/new.html.erb:3

Would someone explain to me why this mistake is happening?

1 answer

0

I think your problem lies in the use of the word "equipments". If you open the Rails console run 'equipment'.pluralize you will see that the plural of "equipment" is "equipment".

So I would do a research on your project and replace any instance of "equipments" for "equipment" and I believe that it would solve.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.