1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00
Maybe/app/controllers/concerns/entryable_resource.rb
Zach Gollwitzer e657c40d19
Account:: namespace simplifications and cleanup (#2110)
* Flatten Holding model

* Flatten balance model

* Entries domain renames

* Fix valuations reference

* Fix trades stream

* Fix brakeman warnings

* Fix tests

* Replace existing entryable type references in DB
2025-04-14 11:40:34 -04:00

47 lines
1 KiB
Ruby

module EntryableResource
extend ActiveSupport::Concern
included do
include StreamExtensions, ActionView::RecordIdentifier
before_action :set_entry, only: %i[show update destroy]
end
def show
end
def new
account = Current.family.accounts.find_by(id: params[:account_id])
@entry = Current.family.entries.new(
account: account,
currency: account ? account.currency : Current.family.currency,
entryable: entryable
)
end
def create
raise NotImplementedError, "Entryable resources must implement #create"
end
def update
raise NotImplementedError, "Entryable resources must implement #update"
end
def destroy
account = @entry.account
@entry.destroy!
@entry.sync_account_later
redirect_back_or_to account_path(account), notice: t("account.entries.destroy.success")
end
private
def entryable
controller_name.classify.constantize.new
end
def set_entry
@entry = Current.family.entries.find(params[:id])
end
end