Created
September 29, 2019 16:06
-
-
Save elyosemite/362b48490de4c1a35e0b0bb94e09e51b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| require 'byebug' | |
| class AdminController < ApplicationController | |
| helper_method :showMessageAdmin | |
| before_action :load_data_from_db, except: [:index, :destroy] | |
| def index | |
| verifyLogin(params[:login], params[:password]) | |
| end | |
| def show | |
| @clients = Cliente.all | |
| end | |
| def destroy | |
| @clients = Cliente.find(params[:id]) | |
| @clients.destroy | |
| redirect_to action: "show" | |
| end | |
| def update | |
| debugger | |
| clts = Cliente.find(params[:id]) | |
| clts.name = params[:name] | |
| clts.cpf = params[:cpf] | |
| clts.password = params[:password] | |
| clts.save | |
| redirect_to action: :show | |
| end | |
| def edit | |
| @clts = Cliente.find(params[:id]) | |
| end | |
| protected | |
| def showMessageAdmin | |
| return "Welcome to BankSys Admin Page" | |
| end | |
| private | |
| def verifyLogin(login, password) | |
| if params[:login] == 'admin' && params[:password] == 'admin' | |
| # We can define what kind of render type we'd like to render. | |
| # Specifying with following format : | |
| # | |
| # => render json: @clients, status: 200 | |
| # => render xml: @clients, status: 200 | |
| # Other render type is specifying by means of argument, like this: | |
| # respond_to do |format| | |
| # format.html { render show: @clients, status: 200 } | |
| # format.json { render json: @clients, status: 200 } | |
| # format.xml { render xml: @clients, status: 200 } | |
| # end | |
| redirect_to action: "show" | |
| else | |
| render :index | |
| end | |
| end | |
| #Carrega todos os dados do DB | |
| def load_data_from_db | |
| @clients = Cliente.all | |
| @clients | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment