58 lines
1.1 KiB
Ruby
58 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
class AccountsController < ApplicationController
|
|
before_action :set_account, only: [:show, :edit, :reveal, :update, :destroy]
|
|
|
|
def index
|
|
@accounts = Account.all
|
|
end
|
|
|
|
def show
|
|
end
|
|
|
|
def new
|
|
@account = Account.new
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def reveal
|
|
render json: { hash: @account.password }.to_json
|
|
end
|
|
|
|
def create
|
|
@account = Account.new(account_params)
|
|
|
|
if @account.save
|
|
redirect_to @account, notice: 'Account was successfully created.'
|
|
else
|
|
flash[:error] = 'Failed to create account'
|
|
render :new
|
|
end
|
|
end
|
|
|
|
def update
|
|
if @account.update(account_params)
|
|
redirect_to @account, notice: 'Account was successfully updated.'
|
|
else
|
|
flash[:error] = 'Failed to update account'
|
|
render :edit
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@account.destroy
|
|
redirect_to accounts_url, notice: 'Account was successfully destroyed.'
|
|
end
|
|
|
|
private
|
|
|
|
def set_account
|
|
@account = Account.find(params[:id])
|
|
end
|
|
|
|
def account_params
|
|
params.require(:account).permit(:username, :password, :home, :site)
|
|
end
|
|
end
|