Navigation Menu

Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

new :zero option to help with web forms that don't like creating empty arrays #15

Merged
merged 3 commits into from Apr 17, 2012

Conversation

spemmons
Copy link
Collaborator

includes full tests and docs...

bonus: adjusted class-level "bitmask_for_attribute(*values)" method to discard blank? values like the setter

spemmons added a commit that referenced this pull request Apr 17, 2012
new :zero option to help with web forms that don't like creating empty arrays
@spemmons spemmons merged commit 894ae54 into joelmoss:master Apr 17, 2012
@joelmoss
Copy link
Owner

I am not convinced that this is needed. It is actually simpler to use in the controller action:

params[:some_attribute] ||= []

And it's actually more obvious about what it is doing.

@spemmons
Copy link
Collaborator Author

sorry, if i jumped the gun

actually, that's the default behavior

this turns out to be useful in a few other ways, such as explicitly setting all bits to zero from the form without explicit handling in the controller for the condition

in my case i have a web form that has a simple vs. advanced view -- the bitmask checkboxes are in the advanced view -- if they are not present in the post, that means i don't want to set them, not that i want them to be reset to zero -- this techniques allows me to control whether or not i want the attributes included in the update very easily

@joelmoss
Copy link
Owner

No you haven't jumped the gun. This is exactly how pull requests should be submitted - well tested, documented code. Good job!

I actually see what you mean about your last example. I think the :zero option needs to be more descriptive though. :zero doesn't tell me anything about what the option does.

@spemmons
Copy link
Collaborator Author

we could change that pretty easily...

some other ideas i had were: zero_value or zero_symbol...

based on my description, do another name come to mind?

@joelmoss
Copy link
Owner

zero_value sounds good

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants