diff options
| author | Alban Peignier | 2017-03-21 09:40:10 +0100 |
|---|---|---|
| committer | Alban Peignier | 2017-03-21 11:16:04 +0100 |
| commit | adff72c7c3f257d315e55208df97868c0a1db898 (patch) | |
| tree | b2dcd0114d5b214e1a16b9a060a3727d35d2e975 | |
| parent | e4401a05faa153f202b407718757316ae23c397b (diff) | |
| download | chouette-core-adff72c7c3f257d315e55208df97868c0a1db898.tar.bz2 | |
Find Referential in Organisation#find_referential. Use it in ReferentialSupport and ReferentialsController. Refs #2900
| -rw-r--r-- | app/controllers/concerns/referential_support.rb | 14 | ||||
| -rw-r--r-- | app/controllers/referentials_controller.rb | 2 | ||||
| -rw-r--r-- | app/models/organisation.rb | 13 |
3 files changed, 16 insertions, 13 deletions
diff --git a/app/controllers/concerns/referential_support.rb b/app/controllers/concerns/referential_support.rb index 34080d991..fe75e3579 100644 --- a/app/controllers/concerns/referential_support.rb +++ b/app/controllers/concerns/referential_support.rb @@ -16,17 +16,7 @@ module ReferentialSupport end def find_referential - organisation_referential = current_organisation.referentials.find_by id: params[:referential_id] - return organisation_referential if organisation_referential - - current_organisation.workbenches.each do |workbench| - workbench_referential = workbench.all_referentials.find_by id: params[:referential_id] - return workbench_referential if workbench_referential - end - - raise ActiveRecord::RecordNotFound + current_organisation.find_referential params[:referential_id] end -end - - +end diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index 9a9e9b151..ed20a6d17 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -73,7 +73,7 @@ class ReferentialsController < BreadcrumbController def resource - @referential ||= current_organisation.referentials.find_by_id(params[:id]) + @referential ||= current_organisation.find_referential(params[:id]) end def collection diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 8547ce5e1..d0742bda6 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -63,4 +63,17 @@ class Organisation < ActiveRecord::Base puts "✓ Organisation #{org.name} has been updated" unless Rails.env.test? end end + + def find_referential(referential_id) + organisation_referential = referentials.find_by id: referential_id + return organisation_referential if organisation_referential + + workbenches.each do |workbench| + workbench_referential = workbench.all_referentials.find_by id: referential_id + return workbench_referential if workbench_referential + end + + raise ActiveRecord::RecordNotFound + end + end |
