Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Backoffice::ClientsController < ApplicationController
- layout 'backoffice'
- before_action :set_client , only: [:edit , :update, :destroy]
- def index
- @clients = User.all
- end
- def new
- @client = User.new
- end
- def create
- @client = User.new(params_client)
- if @client.save
- redirect_to backoffice_clients_path , notice: "O Cliente (#{@client.email}) foi salvo com sucesso!"
- else
- render :new
- end
- end
- def edit
- end
- def update
- passwd = params[:client] [:password]
- passwd_confirmation = params[:client] [:password_confirmation]
- if passwd.blank? && passwd_confirmation.blank?
- params[:client].delete(:password)
- params[:client].delete(:password_confirmation)
- end
- if @client.update(params_client)
- redirect_to backoffice_clients_path , notice: "O Cliente foi atualizado com sucesso!"
- else
- render :edit
- end
- end
- def destroy
- client_email = @client.email
- if @client.destroy
- redirect_to backoffice_clients_path, notice: "O Cliente (#{client_email}) foi excluído com sucesso!"
- else
- render :index
- end
- end
- private
- def set_client
- @client = User.find (params[:id])
- end
- def params_client
- params.require(:user).permit(:email,:password,:password_confirmation)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement