Skip to content

Fix nil crash on unsubscribe page with invalid token#66

Open
bellisabell wants to merge 1 commit intomainfrom
bell/fix-nil-unsubscribe-token
Open

Fix nil crash on unsubscribe page with invalid token#66
bellisabell wants to merge 1 commit intomainfrom
bell/fix-nil-unsubscribe-token

Conversation

@bellisabell
Copy link
Copy Markdown
Contributor

Problem

When a user visits the unsubscribe page with an invalid or missing token, the app crashes with a nil reference error because set_email_message uses find_by which returns nil, and the view tries to access @email_message.subscription.

Solution

  • Added require_email_message before_action that checks if @email_message is present
  • When token is invalid, renders a friendly error page with 404 status instead of crashing
  • Created invalid_token.html.erb view with helpful message explaining the link may have expired

Testing

Visit /unsubscribe?token=invalid - should now show friendly error page instead of crashing.

Closes #27

Add require_email_message before_action to check if the unsubscribe token
is valid. When an invalid token is provided, render a friendly error page
instead of crashing with a nil reference.

Closes #27
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.

Bug: Nil crash on unsubscribe page with invalid token

2 participants