Skip to content

Instantly share code, notes, and snippets.

@ndrluis
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save ndrluis/11159876 to your computer and use it in GitHub Desktop.

Select an option

Save ndrluis/11159876 to your computer and use it in GitHub Desktop.
class SignupController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
redirect_to login_path,
notice: t("flash.signup.create.notice")
else
render :new
end
end
private
def user_params
params
.require(:user)
.permit(:name, :email, :password, :password_confirmation)
end
end
class User < ActiveRecord::Base
validates_presence_of :name
validates_format_of :email, with: /\A[a-z0-9_.+]+@[-a-z0-9.]+\.[a-z]{2,4}\z/i
validates_uniqueness_of :email
has_secure_password
has_many :tasks
def pending_tasks_count
tasks.pending.count
end
def done_tasks_count
tasks.done.count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment