Skip to content

Commit 97bf9c1

Browse files
committed
don't throw 500s when trying to find() nonexistent pages
1 parent 7924a75 commit 97bf9c1

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

app/controllers/content_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def index
4040
def show
4141
content_type = content_type_from_controller(self.class)
4242
return redirect_to root_path unless valid_content_types.map(&:name).include?(content_type.name)
43-
@content = content_type.find(params[:id])
43+
@content = content_type.find_by(id: params[:id])
44+
return redirect_to(root_path, notice: "You don't have permission to view that content.") if @content.nil?
4445
@serialized_content = ContentSerializer.new(@content)
4546

4647
return redirect_to(root_path) if @content.user.nil? # deleted user's content

app/controllers/users_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ def index
44
end
55

66
def show
7-
@user = User.find(params[:id])
7+
@user = User.find_by(id: params[:id])
8+
return redirect_to(root_path, notice: 'That user does not exist.') if @user.nil?
9+
810
@content = @user.public_content.select { |type, list| list.any? }
911
@tabs = @content.keys
1012
@stream = @user.content_change_events.order('updated_at desc').limit(100).group_by do |cce|

0 commit comments

Comments
 (0)