Undefined method `users_path '

<%= form_for @user1 do |f| %>

    Username: <%= f.text_field :username %>      <br />
    Password: <%= f.password_field :password %>  <br />.
    Email:    <%= f.email_field :email %> <br />

    <%= submit_tag "Add" %>

<% end %>

I am new to ruby ​​and I am trying to create simple programs, but I have this error and I can not understand why. I have this error

undefined method `users_path' for #<#<Class:0x000000020576f0>:0x0000000335d5d8>

What is the solution here?

class UserController < ApplicationController
  def add
    @user1 = User.new
    respond_to do |format|
      format.html
      format.json {render :json => @user1}
    end
  end
+3
source share
3 answers

Determined routes in config/routes.rb?

Rails.application.routes.draw do
  resources :users
  # ...
end
+20
source

Your UserController Class

route: get / signup, to: 'user # new',, resources: users ---> plural ... because you will register multiple users.

0
source

, config/routes.rb user ():

resources :user

users ( ):

resources :users
0

All Articles