Merge pull request #3580 from consul/use_find_instead_of_find_by_id
Use find instead of find by
This commit is contained in:
@@ -46,11 +46,11 @@ class Admin::BudgetGroupsController < Admin::BaseController
|
||||
private
|
||||
|
||||
def load_budget
|
||||
@budget = Budget.includes(:groups).find(params[:budget_id])
|
||||
@budget = Budget.find_by_slug_or_id! params[:budget_id]
|
||||
end
|
||||
|
||||
def load_group
|
||||
@group = @budget.groups.find(params[:id])
|
||||
@group = @budget.groups.find_by_slug_or_id! params[:id]
|
||||
end
|
||||
|
||||
def groups_index
|
||||
|
||||
@@ -47,15 +47,15 @@ class Admin::BudgetHeadingsController < Admin::BaseController
|
||||
private
|
||||
|
||||
def load_budget
|
||||
@budget = Budget.includes(:groups).find(params[:budget_id])
|
||||
@budget = Budget.find_by_slug_or_id! params[:budget_id]
|
||||
end
|
||||
|
||||
def load_group
|
||||
@group = @budget.groups.find(params[:group_id])
|
||||
@group = @budget.groups.find_by_slug_or_id! params[:group_id]
|
||||
end
|
||||
|
||||
def load_heading
|
||||
@heading = @group.headings.find(params[:id])
|
||||
@heading = @group.headings.find_by_slug_or_id! params[:id]
|
||||
end
|
||||
|
||||
def headings_index
|
||||
|
||||
@@ -87,7 +87,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def load_budget
|
||||
@budget = Budget.includes(:groups).find(params[:budget_id])
|
||||
@budget = Budget.find_by_slug_or_id! params[:budget_id]
|
||||
end
|
||||
|
||||
def load_investment
|
||||
|
||||
@@ -6,6 +6,7 @@ class Admin::BudgetsController < Admin::BaseController
|
||||
|
||||
has_filters %w{open finished}, only: :index
|
||||
|
||||
before_action :load_budget, except: [:index, :new, :create]
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
@@ -66,4 +67,8 @@ class Admin::BudgetsController < Admin::BaseController
|
||||
params.require(:budget).permit(*valid_attributes, *report_attributes, translation_params(Budget))
|
||||
end
|
||||
|
||||
def load_budget
|
||||
@budget = Budget.find_by_slug_or_id! params[:id]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -37,7 +37,7 @@ module Budgets
|
||||
end
|
||||
|
||||
def load_budget
|
||||
@budget = Budget.find(params[:budget_id])
|
||||
@budget = Budget.find_by_slug_or_id! params[:budget_id]
|
||||
end
|
||||
|
||||
def load_ballot
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module Budgets
|
||||
class BallotsController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :load_budget
|
||||
load_and_authorize_resource :budget
|
||||
before_action :load_ballot
|
||||
after_action :store_referer, only: [:show]
|
||||
@@ -13,6 +14,10 @@ module Budgets
|
||||
|
||||
private
|
||||
|
||||
def load_budget
|
||||
@budget = Budget.find_by_slug_or_id! params[:budget_id]
|
||||
end
|
||||
|
||||
def load_ballot
|
||||
query = Budget::Ballot.where(user: current_user, budget: @budget)
|
||||
@ballot = @budget.balloting? ? query.first_or_create : query.first_or_initialize
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
module Budgets
|
||||
class GroupsController < ApplicationController
|
||||
before_action :load_budget
|
||||
before_action :load_group
|
||||
load_and_authorize_resource :budget
|
||||
load_and_authorize_resource :group, class: "Budget::Group"
|
||||
|
||||
@@ -9,5 +11,14 @@ module Budgets
|
||||
def show
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_budget
|
||||
@budget = Budget.find_by_slug_or_id! params[:budget_id]
|
||||
end
|
||||
|
||||
def load_group
|
||||
@group = @budget.groups.find_by_slug_or_id! params[:id]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -10,6 +10,7 @@ module Budgets
|
||||
PER_PAGE = 10
|
||||
|
||||
before_action :authenticate_user!, except: [:index, :show, :json_data]
|
||||
before_action :load_budget, except: :json_data
|
||||
|
||||
load_and_authorize_resource :budget, except: :json_data
|
||||
load_and_authorize_resource :investment, through: :budget, class: "Budget::Investment",
|
||||
@@ -136,7 +137,7 @@ module Budgets
|
||||
|
||||
def load_heading
|
||||
if params[:heading_id].present?
|
||||
@heading = @budget.headings.find(params[:heading_id])
|
||||
@heading = @budget.headings.find_by_slug_or_id! params[:heading_id]
|
||||
@assigned_heading = @ballot.try(:heading_for_group, @heading.try(:group))
|
||||
load_map
|
||||
end
|
||||
@@ -154,6 +155,10 @@ module Budgets
|
||||
TagCloud.new(Budget::Investment, params[:search])
|
||||
end
|
||||
|
||||
def load_budget
|
||||
@budget = Budget.find_by_slug_or_id! params[:budget_id]
|
||||
end
|
||||
|
||||
def set_view
|
||||
@view = (params[:view] == "minimal") ? "minimal" : "default"
|
||||
end
|
||||
|
||||
@@ -14,15 +14,14 @@ module Budgets
|
||||
private
|
||||
|
||||
def load_budget
|
||||
@budget = Budget.find_by(id: params[:budget_id])
|
||||
@budget = Budget.find_by_slug_or_id(params[:budget_id]) || Budget.first
|
||||
end
|
||||
|
||||
def load_heading
|
||||
@heading = if params[:heading_id].present?
|
||||
@budget.headings.find(params[:heading_id])
|
||||
else
|
||||
@budget.headings.first
|
||||
end
|
||||
if @budget.present?
|
||||
headings = @budget.headings
|
||||
@heading = headings.find_by_slug_or_id(params[:heading_id]) || headings.first
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ module Budgets
|
||||
private
|
||||
|
||||
def load_budget
|
||||
@budget = Budget.find_by(slug: params[:budget_id]) || Budget.find_by(id: params[:budget_id])
|
||||
@budget = Budget.find_by_slug_or_id! params[:budget_id]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@ class BudgetsController < ApplicationController
|
||||
include BudgetsHelper
|
||||
feature_flag :budgets
|
||||
|
||||
before_action :load_budget, only: :show
|
||||
load_and_authorize_resource
|
||||
before_action :set_default_budget_filter, only: :show
|
||||
has_filters %w[not_unfeasible feasible unfeasible unselected selected winners], only: :show
|
||||
@@ -19,4 +20,10 @@ class BudgetsController < ApplicationController
|
||||
@banners = Banner.in_section("budgets").with_active
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_budget
|
||||
@budget = Budget.find_by_slug_or_id! params[:id]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class Management::Budgets::InvestmentsController < Management::BaseController
|
||||
before_action :load_budget
|
||||
|
||||
load_resource :budget
|
||||
load_resource :investment, through: :budget, class: "Budget::Investment"
|
||||
@@ -60,6 +61,10 @@ class Management::Budgets::InvestmentsController < Management::BaseController
|
||||
check_verified_user t("management.budget_investments.alert.unverified_user")
|
||||
end
|
||||
|
||||
def load_budget
|
||||
@budget = Budget.find_by_slug_or_id! params[:budget_id]
|
||||
end
|
||||
|
||||
def load_categories
|
||||
@categories = ActsAsTaggableOn::Tag.category.order(:name)
|
||||
end
|
||||
|
||||
@@ -65,7 +65,7 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController
|
||||
end
|
||||
|
||||
def load_budget
|
||||
@budget = Budget.find(params[:budget_id])
|
||||
@budget = Budget.find_by_slug_or_id! params[:budget_id]
|
||||
end
|
||||
|
||||
def load_investment
|
||||
|
||||
Reference in New Issue
Block a user