Skip to content

Commit

Permalink
Handle 404 more responsibly
Browse files Browse the repository at this point in the history
  • Loading branch information
scaffeinate committed Apr 28, 2017
1 parent 1c85d7e commit a2af065
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_in, keys: [:email, :remember_me])
end

def render_404
respond_to do |format|
format.html { render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found }
end
end

include PublicActivity::StoreController
end
3 changes: 2 additions & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def event_params
end

def set_event
@event = Event.find(params[:id])
@event = Event.find_by(id: params[:id])
render_404 and return unless @event && User.find_by(id: @event.user_id)
end

def set_user
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def destroy

private
def set_post
@post = Post.find(params[:id])
@post = Post.find_by(id: params[:id])
render_404 and return unless @post && User.find_by(id: @post.user_id)
end

def post_params
Expand Down

0 comments on commit a2af065

Please sign in to comment.