0
votes

Im following this tutorial. http://www.sitepoint.com/rails-userpassword-authentication-from-scratch-part-i/ i just the part titled Adding Some Validations to the User Model

When i go to http://localhost:3000/users/new i get an routing error. But based on my knowledge the rout looks fine. Whats wrong?

enter image description here

user_controller.rb

class UsersController < ApplicationController
  def new
    @user = User.new
  end
  def create
    @user = User.new(params[:user])
    if @user.save
      flash[:notice] = "You signed up successfully"
      flash[:color]= "valid"
    else
      flash[:notice] = "Form is invalid"
      flash[:color]= "invalid"
    end
    render "new"
  end
end

routes.rb

Rails.application.routes.draw do
  get 'users/new'

Model user.rb

class User < ActiveRecord::Base
  attr_accessor :password
  EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
  validates :username, :presence => true, :uniqueness => true, :length => { :in => 3..20 }
  validates :email, :presence => true, :uniqueness => true, :format => EMAIL_REGEX
  validates :password, :confirmation => true #password_confirmation attr
  validates_length_of :password, :in => 6..20, :on => :create
end
1
Can you provide the error message?nishu
It should work; can you paste the output of rake routes?mdesantis
sorry i just added the error to post then.joeyk16
Rename user_controller.rb to users_controller.rb.Mike Sherrill 'Cat Recall'
$ rake routes DL is deprecated, please use Fiddle Prefix Verb URI Pattern Controller#Action users_new GET /users/new(.:format) users#newjoeyk16

1 Answers

3
votes

Rename your file implementing UsersController to users_controller.rb.

Also, your regexp EMAIL_REGEX in User class causes an error. You should modify it as error says:

EMAIL_REGEX = /\A[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\z/i