Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(users): remove blank params from user form #356

Merged
merged 4 commits into from
Nov 30, 2023

Conversation

wJoenn
Copy link
Collaborator

@wJoenn wJoenn commented Nov 23, 2023

Summary of changes and context

The favourite language input in the user form is as follow

<%= f.select :favourite_language, Snippet::LANGUAGES.invert.to_a, { prompt: "", selected: @user.favourite_language }, class: "input" %>

If a user has no language then @user.favourite_language is nil and when a form input is nil Rails converts it to an empty string.
This means that as long as a user hasn't selected a favourite language, any update he tries to make on his user model will fail because the front sends { favourite_language: "" } which does not pass the validation

  validates :favourite_language, inclusion: { in: Snippet::LANGUAGES.keys.map(&:to_s) }, allow_nil: true

This PR fixes this by appending #compact_blank to the params.require().permit in the UsersController which removes blank params

Sanity checks

  • Linters pass
  • Tests pass
  • Related GitHub issues are linked in the description

@wJoenn wJoenn force-pushed the fix/users/no-balnk-favourite-language branch from 76fe5f0 to 7cbf6db Compare November 23, 2023 20:49
Procfile.dev Outdated Show resolved Hide resolved
Copy link
Owner

@pil0u pil0u left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est mieux 🚀 (enfin je pense)

@pil0u pil0u merged commit 8ec5906 into main Nov 30, 2023
5 checks passed
@pil0u pil0u deleted the fix/users/no-balnk-favourite-language branch November 30, 2023 22:10
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.

3 participants