1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 21:29:38 +02:00
Maybe/app/controllers/concerns/entryable_resource.rb

48 lines
1 KiB
Ruby
Raw Normal View History

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