ftp-manager/app/controllers/accounts_controller.rb

58 lines
1.1 KiB
Ruby
Raw Normal View History

2016-09-18 09:41:51 -05:00
# frozen_string_literal: true
2016-08-27 21:40:21 -05:00
class AccountsController < ApplicationController
before_action :set_account, only: [:show, :edit, :reveal, :update, :destroy]
2016-08-27 21:40:21 -05:00
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
2016-08-27 21:40:21 -05:00
def create
@account = Account.new(account_params)
2016-09-18 11:16:35 -05:00
if @account.save
redirect_to @account, notice: 'Account was successfully created.'
else
flash[:error] = 'Failed to create account'
render :new
2016-08-27 21:40:21 -05:00
end
end
def update
2016-09-18 11:16:35 -05:00
if @account.update(account_params)
redirect_to @account, notice: 'Account was successfully updated.'
else
flash[:error] = 'Failed to update account'
render :edit
2016-08-27 21:40:21 -05:00
end
end
def destroy
@account.destroy
2016-09-18 11:16:35 -05:00
redirect_to accounts_url, notice: 'Account was successfully destroyed.'
2016-08-27 21:40:21 -05:00
end
private
def set_account
@account = Account.find(params[:id])
end
def account_params
params.require(:account).permit(:username, :password, :home, :site)
end
end