Repository navigation
Ability to specify multiple contexts when defining a validation. - #13754
Conversation
|
This was requested in #9659, but I think it was closed by mistake. |
There was a problem hiding this comment.
I think that context could be plural here now. Also, what do you think about :
Specifies the contexts where this validation is active. You can either pass a symbol or a collection of actions.
?
There was a problem hiding this comment.
Also, I think that the documentation of the #validate method should be updated as well.
|
👍 |
There was a problem hiding this comment.
let's also add the case where the validation does not run.
There was a problem hiding this comment.
Added another test case. Thanks for the feedback!
|
@vpuzzella : For future contributions, could you post a comment once your patch is updated please ? :-) GitHub does not create notifications when you push the commit. Thank you! This looks good to me so far! |
|
@robin850, will do. At this point I feel the patch is complete. Is there anything else required in order to have the PR accepted? |
|
@vpuzzella : Thanks! Everything seems fine to me but I'm not a merger, this decision is up to @senny. |
|
@vpuzzella the PR does no longer apply and needs a rebase. |
Example: validates_presence_of :name, on: [:update, :custom_validation_context]
|
@senny, rebased and CI build passing. |
Ability to specify multiple contexts when defining a validation.
|
Thanks. |
|
This feature is very useful thank you. I have the following suggestion: when someone specifies a validation with context :save, it should be called for :create and :update. For example, if you have two steps, the first step someone needs to enter his name, the second step his lastname, but it should only be able to save if name, surname and token is populated, you currently have to do it like this: validates :name, presence: true, on: [:create, :update, :step1] It would be much simpler if you could write it as: validates :name, presence: true, on: [:save, :step1] In fact, consider the how callbacks are specified (before_save, before_create, before_update) this actually seems like a bug. |
|
@vpuzzella Any comments on my suggestion above? |
|
@pierre-pretorius : Please post feature requests to the rails-core mailing list or send a patch (unless I'm wrong, this seems straightforward here) ; thank you! :-) |
Example:
validates_presence_of :name, on: [:update, :custom_validation_context]