NoMethodError in User # new RubyOnRails

1

controller:

class UsuarioController < ApplicationController

    def index
        @usuarios = Usuario.order :nome
    end

    def new 
        @usuario = Usuario.new
    end

    def show
        @usuario = Usuario.find(params[:id])
    end

    def destroy
        @usuario = Usuario.find(params[:id])
        @usuario.destroy

        redirect_to(action: "index")
    end

end

View:

New User

<%= form_for @usuario do |f| %>
  Nome: <%= f.text_field :nome %><br/>
<% end %>

Error:

  NoMethodError in Usuario#new
Showing /vagrant/crudexemplo/app/views/usuario/new.html.erb where line #4 raised:

undefined method 'usuarios_path' for #<#<Class:0x007fce441b1e20>:0x007fce31f1e148>
    
asked by anonymous 16.12.2015 / 17:31

1 answer

1

You need to add the route in config / routes.rb

Sample::Application.routes.draw do
  #outras rotas...

  resource :usuario #adicione essa linha
end

and the name of the controller always in the plural eg: UsersController

    
16.12.2015 / 18:06