Skip to content

Commit dc4b257

Browse files
committed
Refactor allocation retrieval to use slug in show and export methods; add uniqueness validation for slug in Allocation model
1 parent 5cd7616 commit dc4b257

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

app/controllers/allocations_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class AllocationsController < ApplicationController
44
def show
55
@fund = Fund.find_by(slug: params[:fund_id])
6-
@allocation = @fund.allocations.find(params[:id])
6+
@allocation = @fund.allocations.find_by(slug: params[:id])
77
@project_allocations = @allocation.project_allocations.includes(:project, :funding_source).order('amount_cents desc').where('amount_cents >= 1')
88
end
99

@@ -35,7 +35,7 @@ def export
3535

3636
def export_github_sponsors
3737
@fund = Fund.find_by(slug: params[:fund_id])
38-
@allocation = @fund.allocations.find(params[:id])
38+
@allocation = @fund.allocations.find_by(slug: params[:id])
3939

4040
csv_data = @allocation.github_sponsors_csv_export
4141

app/models/allocation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class Allocation < ApplicationRecord
77
scope :displayable, -> { where('funded_projects_count > 0') }
88
scope :completed, -> { where.not(completed_at: nil) }
99

10+
validates_uniqueness_of :slug, scope: :fund_id
11+
1012
before_create :set_slug
1113

1214
def to_s

0 commit comments

Comments
 (0)