Skip to content

Commit

Permalink
Add a graceful fallback when homepages are not found
Browse files Browse the repository at this point in the history
  • Loading branch information
camillevilla committed Sep 4, 2024
1 parent ba94fff commit 2a9fa1c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ def preview
@@dropdown_categories = nil
@dropdown_communities = nil
@homepage = nil
@homepage = Homepage.find(params[:id]) # <-- param is set by a member action in admin/homepages/ controller
# TODO: set a nicer error message & redirect for Homepages that don't exist
begin
@homepage = Homepage.find(params[:id])
rescue ActiveRecord::RecordNotFound
warning = "That homepage does not exist"
flash[:warning] = warning
redirect_to admin_homepages_path, warning: warning
return
end
current_features = @homepage&.homepage_features
if current_features
@section_one_features = current_features&.where(section_id: 1)&.first(3)
Expand Down

0 comments on commit 2a9fa1c

Please sign in to comment.