Avoid error when accessing final votes stats before balloting phase
When accessing the URL `/admin/stats/budget_balloting?budget_id=X' for a budget in a phase prior to the balloting phase, the following error was raised due to the stats where not calculated yet. Instead, we'll now show a flash message. NoMethodError: undefined method `[]' for nil:NilClass ./app/controllers/admin/stats_controller.rb:82
This commit is contained in:
@@ -74,6 +74,9 @@ class Admin::StatsController < Admin::BaseController
|
||||
|
||||
def budget_balloting
|
||||
@budget = Budget.find(params[:budget_id])
|
||||
|
||||
authorize! :read_admin_stats, @budget, message: t("admin.stats.budgets.no_data_before_balloting_phase")
|
||||
|
||||
@user_count = @budget.ballots.select {|ballot| ballot.lines.any? }.count
|
||||
|
||||
@vote_count = @budget.lines.count
|
||||
|
||||
Reference in New Issue
Block a user