This repository was archived by the owner on Jul 27, 2025. It is now read-only.
Don't allow a subcategory to be assigned to another subcategory to ensure 1 level of nesting max#1730
Merged
zachgoll merged 12 commits intomaybe-finance:mainfrom Jan 30, 2025
Merged
Conversation
zachgoll
reviewed
Jan 28, 2025
Contributor
zachgoll
left a comment
There was a problem hiding this comment.
Overall, agree with the strategy here!
| <%= f.select :parent_id, categories.pluck(:name, :id), { include_blank: "(unassigned)", label: "Parent category (optional)" }, disabled: category.parent? %> | ||
| <% if category.parent? %> | ||
| <span class="text-xs italic pl-2 text-gray-500">This category couldn’t be assigned as a subcategory because it already has subcategories.</span> | ||
| <% end %> |
Contributor
There was a problem hiding this comment.
I think here, we can just have a conditional:
<% unless category.parent? %>
<%= f.select :parent_id ...
<% end %>That way, if the user is not allowed to assign a parent, we don't ever give them the option.
zachgoll
reviewed
Jan 29, 2025
zachgoll
reviewed
Jan 30, 2025
Contributor
zachgoll
left a comment
There was a problem hiding this comment.
Looks good now. Left one more comment to address, then I think we're good to merge!
app/views/categories/_form.html.erb
Outdated
| @@ -1,46 +1,49 @@ | |||
| <%# locals: (category:, categories:) %> | |||
| <%= turbo_frame_tag 'form' do %> | |||
Contributor
There was a problem hiding this comment.
Do we need this? What was the purpose of adding?
Contributor
Author
There was a problem hiding this comment.
ohhh, i forgot to remove this... it's done in 2c07cd6. ;-)
zachgoll
approved these changes
Jan 30, 2025
Contributor
zachgoll
left a comment
There was a problem hiding this comment.
Looking good! Nice work, thanks for the fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes issue #1677