ruby on rails - How to make the "update" function -
i new ror. started make registration of user login, showing , deleting, cant make edit/update function. going post register function , html form used register , want same use edit/update.
the register function
def register @name = params[:name] @surname = params[:surname] @username = params[:username] @password = params[:password] @email = params[:email] @tel = params[:tel] @role_id = params[:role_id] user = user.create_with_password(@name,@surname,@username,@email,@password,@tel,@role_id) if user #session[:signed_in] = true session[:username] = user.username redirect_to "/menaxhimi_pushimit/index" else redirect_to "/menaxhimi_pushimit/index" end
end
user model
def self.create_with_password(name, surname, username, email, password, tel, role_id) salt = securerandom.hex password_hash = self.generate_hash(password, salt) self.create( name: name, surname: surname, username: username, email: email, salt: salt, password_hash: password_hash, tel: tel, role_id: role_id ) end def verify_password(password) self.password_hash == user.generate_hash(password, self.salt) end def self.generate_hash(password, salt) digest = openssl::digest::sha256.new digest.update(password) digest.update(salt) digest.to_s end
end
my html form
<form action='/menaxhimi_pushimit/update' class='validate-form' method='post'> <input type="name" placeholder="name" name="name" required /> <input type="surname" placeholder="surname" name="surname" required /> <input type="username" placeholder="username" name="username" required /> <input type="password" placeholder="password" name="password" required /> <input type="email" placeholder="email" name="email" required /> <input type="tel" placeholder="tel" name="tel" required /> <input type="roli" placeholder="roli" name="role_id" required /> <input type="submit" value="sign up" /> </form>
can how modify register edit/update
thanks in advance
the benefit using rails conventions if use them u don't have write own custom code. need google , learn basic crud operations using rails-4.
here link of demo user authentication app u can follow code , make own.
Comments
Post a Comment