Frederick John Frederick John - 1 year ago 64
MySQL Question

Rails 5 'nomethod' error during sign up

I'm receiving the nomethod name error during user sign up. However, there isn't a name column in my users table in the database and there isn't a name field in the form so I don't understand why this error is being thrown. Here is the error and then my form, controller, and schema. noMethodError in Users#Create (wtf?)

<%= form_for(user) do |f| %>
<% if user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:</h2>
<% user.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
<% end %>

<div class="field">
<%= f.label :first_name %>
<%= f.text_field :first_name %>

<div class="field">
<%= f.label :last_name %>
<%= f.text_field :last_name %>

<div class="field">
<%= f.label :email %>
<%= f.email_field :email %>

<div class="field">
<%= f.label :display_name %>
<%= f.text_field :display_name %>
<div class="field">
<%= f.label :password %>
<%= f.password_field :password %>
<div class="field">
<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation %>
<div class="actions">
<%= f.submit %>
<% end %>

and here is my users controllers. The error is originating from the users controller create action.

def create
@user =

respond_to do |format|
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: @user }
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }

And of course I thought it may have been the DB schema but it isn't. Here is the schema.

ActiveRecord::Schema.define(version: 20161109225217) do

create_table "users", force: :cascade do |t|
t.string "first_name"
t.string "last_name"
t.string "email"
t.string "display_name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "password_digest"


I have no idea what is causing this error. Any suggestions please!?

class User < ApplicationRecord
attr_accessor :password
before_save { = email.downcase }
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :password, presence: true, length: { minimum: 6 }

And my user params -

# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])

# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:first_name, :last_name, :email, :display_name, :password, :password_confirmation)

Answer Source

Go and check your model you made mistake in validate field

your code

 validates :name, presence: true, length: { maximum: 50 }`

change to like this

 validates :first_name, :last_name, presence: true, length: { maximum: 50 }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download