mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +02:00
Scaffold out basic transactions model and UI (#478)
* Transaction scaffold * Rough in transaction views * Fix sort order * Fix mass assignment issue * Fix test * Simplify CI workflow * Don't seed db before test
This commit is contained in:
parent
e767aca37f
commit
87b97b3c41
26 changed files with 430 additions and 44 deletions
64
app/controllers/transactions_controller.rb
Normal file
64
app/controllers/transactions_controller.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
class TransactionsController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :set_transaction, only: %i[ show edit update destroy ]
|
||||
|
||||
def index
|
||||
@transactions = Current.family.transactions
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def new
|
||||
@transaction = Transaction.new
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def create
|
||||
@transaction = Transaction.new(transaction_params)
|
||||
account = Current.family.accounts.find(params[:transaction][:account_id])
|
||||
|
||||
raise ActiveRecord::RecordNotFound, "Account not found or not accessible" if account.nil?
|
||||
|
||||
@transaction.account = account
|
||||
|
||||
respond_to do |format|
|
||||
if @transaction.save
|
||||
format.html { redirect_to transaction_url(@transaction), notice: "Transaction was successfully created." }
|
||||
else
|
||||
format.html { render :new, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @transaction.update(transaction_params)
|
||||
format.html { redirect_to transaction_url(@transaction), notice: "Transaction was successfully updated." }
|
||||
else
|
||||
format.html { render :edit, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@transaction.destroy!
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to transactions_url, notice: "Transaction was successfully destroyed." }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_transaction
|
||||
@transaction = Transaction.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def transaction_params
|
||||
params.require(:transaction).permit(:name, :date, :amount, :currency)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue