Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.27 KB | None | 0 0
  1. class Backoffice::ClientsController < ApplicationController
  2. layout 'backoffice'
  3. before_action :set_client , only: [:edit , :update, :destroy]
  4.   def index
  5.     @clients = User.all
  6.   end
  7.   def new
  8.     @client = User.new
  9.   end
  10.  
  11.   def create
  12.     @client = User.new(params_client)
  13.     if @client.save
  14.       redirect_to backoffice_clients_path , notice: "O Cliente (#{@client.email}) foi salvo com sucesso!"
  15.     else
  16.       render :new
  17.     end
  18.   end
  19.  
  20.   def edit
  21.   end
  22.  
  23. def update
  24.     passwd = params[:client] [:password]
  25.     passwd_confirmation = params[:client] [:password_confirmation]
  26.  
  27.     if passwd.blank? && passwd_confirmation.blank?
  28.       params[:client].delete(:password)
  29.       params[:client].delete(:password_confirmation)  
  30.     end
  31.  
  32.     if @client.update(params_client)
  33.       redirect_to backoffice_clients_path , notice: "O Cliente foi atualizado com sucesso!"
  34.     else
  35.       render :edit
  36.     end
  37. end
  38.  
  39. def destroy
  40.     client_email = @client.email
  41.  
  42.      if @client.destroy
  43.       redirect_to backoffice_clients_path, notice: "O Cliente (#{client_email}) foi excluído com sucesso!"
  44.       else
  45.         render :index
  46.       end
  47.     end
  48.  
  49. private
  50.  
  51. def set_client
  52.   @client = User.find (params[:id])
  53. end
  54. def params_client
  55.   params.require(:user).permit(:email,:password,:password_confirmation)
  56. end
  57.  
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement