Skip to content

Fix error for habit deletion#1

Open
CasJam wants to merge 1 commit intomainfrom
cursor/fix-error-for-habit-deletion-246f
Open

Fix error for habit deletion#1
CasJam wants to merge 1 commit intomainfrom
cursor/fix-error-for-habit-deletion-246f

Conversation

@CasJam
Copy link
Owner

@CasJam CasJam commented Jun 11, 2025

A return statement was added to the set_habit method in app/controllers/habits_controller.rb.

Previously, when ActiveRecord::RecordNotFound was rescued, head :not_found was called, but the method continued execution. This resulted in @habit being nil, leading to a NoMethodError when subsequent actions attempted to operate on @habit.

The addition of return after head :not_found ensures that the method execution stops immediately when a habit is not found. This prevents the controller action from proceeding with a nil @habit object.

The change resolves the NoMethodError during habit deletion attempts for non-existent habits, ensuring a proper 404 Not Found response instead of a 500 Internal Server Error. Existing habits can now be deleted successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants