diff --git a/app/controllers/admin/enterprise_groups_controller.rb b/app/controllers/admin/enterprise_groups_controller.rb index cb3ac80935..022b2f7d61 100644 --- a/app/controllers/admin/enterprise_groups_controller.rb +++ b/app/controllers/admin/enterprise_groups_controller.rb @@ -9,7 +9,7 @@ module Admin def move_up EnterpriseGroup.with_isolation_level_serializable do - @enterprise_group = EnterpriseGroup.find_by_permalink params[:enterprise_group_id] + @enterprise_group = find_resource @enterprise_group.move_higher end redirect_to main_app.admin_enterprise_groups_path @@ -17,7 +17,7 @@ module Admin def move_down EnterpriseGroup.with_isolation_level_serializable do - @enterprise_group = EnterpriseGroup.find_by_permalink params[:enterprise_group_id] + @enterprise_group = find_resource @enterprise_group.move_lower end redirect_to main_app.admin_enterprise_groups_path @@ -34,9 +34,11 @@ module Admin alias_method_chain :build_resource, :address # Overriding method on Spree's resource controller, - # so that resources are found using permalink + # so that resources are found using permalink. + # The ! version is important to raise a RecordNotFound error. def find_resource - EnterpriseGroup.find_by_permalink(params[:id]) + permalink = params[:id] || params[:enterprise_group_id] + EnterpriseGroup.find_by_permalink!(permalink) end private diff --git a/app/controllers/admin/producer_properties_controller.rb b/app/controllers/admin/producer_properties_controller.rb index 66656d9aa0..aca3e3f418 100644 --- a/app/controllers/admin/producer_properties_controller.rb +++ b/app/controllers/admin/producer_properties_controller.rb @@ -12,7 +12,7 @@ module Admin end def load_enterprise - @enterprise = Enterprise.find_by_permalink params[:enterprise_id] + @enterprise = Enterprise.find_by_permalink! params[:enterprise_id] end def load_properties