Created
September 21, 2012 01:08
-
-
Save tyler-smith/3759222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update | |
@user = User.find(params[:id]) | |
if @user.update_attributes(params[:user]) | |
flash[:notice] = 'Dados salvos com sucesso' | |
redirect_to :action => 'edit' | |
else | |
flash[:error] = 'Falha ao salvar dados' | |
render :edit | |
end | |
# Get user data by id | |
@user = User.find(params[:id]) | |
end | |
#model | |
class User < ActiveRecord::Base | |
attr_accessible :created, :email, :name, :password | |
before_save :encrypt_password | |
validates :name, :length => {:in => 3..50} | |
# Validates email with regex | |
validates :email, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i | |
# I need pass by here | |
validates :password, :length => {:in => 3..50}, :if => :has_password? | |
def has_password? | |
[email protected]? | |
end | |
def encrypt_password | |
if password.present? | |
self.password = BCrypt::Engine.hash_secret(password, BCrypt::Engine.generate_salt) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment