2024-07-01 10:49:43 -04:00
|
|
|
class Account::EntriesController < ApplicationController
|
2024-07-26 18:00:41 +02:00
|
|
|
layout :with_sidebar
|
2024-07-01 10:49:43 -04:00
|
|
|
|
|
|
|
before_action :set_account
|
|
|
|
|
2024-11-04 20:27:31 -05:00
|
|
|
def index
|
|
|
|
@q = search_params
|
2024-11-27 16:01:50 -05:00
|
|
|
@pagy, @entries = pagy(entries_scope.search(@q).reverse_chronological, limit: params[:per_page] || "10")
|
2024-07-01 10:49:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def set_account
|
|
|
|
@account = Current.family.accounts.find(params[:account_id])
|
|
|
|
end
|
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
def entries_scope
|
|
|
|
scope = Current.family.entries
|
|
|
|
scope = scope.where(account: @account) if @account
|
|
|
|
scope
|
2024-11-04 20:27:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def search_params
|
|
|
|
params.fetch(:q, {})
|
|
|
|
.permit(:search)
|
2024-07-01 10:49:43 -04:00
|
|
|
end
|
|
|
|
end
|