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

Validate multiple contexts on valid? and invalid? at once #21535

Merged

Conversation

dmitry
Copy link
Contributor

@dmitry dmitry commented Sep 7, 2015

Fixed #21069

Example:

class Person
  include ActiveModel::Validations

  attr_reader :name, :title
  validates_presence_of :name, on: :create
  validates_presence_of :title, on: :update
end

person = Person.new
person.valid?([:create, :update])    # => true
person.errors.messages               # => {:name=>["can't be blank"], :title=>["can't be blank"]}

Example:

```ruby
class Person
  include ActiveModel::Validations

  attr_reader :name, :title
  validates_presence_of :name, on: :create
  validates_presence_of :title, on: :update
end

person = Person.new
person.valid?([:create, :update])    # => true
person.errors.messages               # => {:name=>["can't be blank"], :title=>["can't be blank"]}
```
@rails-bot
Copy link

r? @kaspth

(@rails-bot has picked a reviewer for you, use r? to override)

@kaspth
Copy link
Contributor

kaspth commented Sep 8, 2015

r? @rafaelfranca

Den 07/09/2015 kl. 23.44 skrev Ruby on Rails Bot notifications@github.com:

r? @kaspth https://github.com/kaspth
(@rails-bot https://github.com/rails-bot has picked a reviewer for you, use r? to override)


Reply to this email directly or view it on GitHub #21535 (comment).

Kasper

rafaelfranca added a commit that referenced this pull request Sep 8, 2015
Validate multiple contexts on `valid?` and `invalid?` at once
@rafaelfranca rafaelfranca merged commit ff83868 into rails:master Sep 8, 2015
@dmitry dmitry deleted the feature/validate-multiple-contexts branch September 8, 2015 21:02
notapatch added a commit to notapatch/rails that referenced this pull request Apr 6, 2023
The PR documents this change:
  rails#21535
Which allows multiple contexts to be validated:
  person.valid?([:create, :update])    # => true

The change isn't visible in the API documentation which this PR
fixes.
danielvdao pushed a commit to danielvdao/rails that referenced this pull request May 1, 2023
The PR documents this change:
  rails#21535
Which allows multiple contexts to be validated:
  person.valid?([:create, :update])    # => true

The change isn't visible in the API documentation which this PR
fixes.
danielvdao pushed a commit to danielvdao/rails that referenced this pull request May 1, 2023
The PR documents this change:
  rails#21535
Which allows multiple contexts to be validated:
  person.valid?([:create, :update])    # => true

The change isn't visible in the API documentation which this PR
fixes.
danielvdao pushed a commit to danielvdao/rails that referenced this pull request May 1, 2023
The PR documents this change:
  rails#21535
Which allows multiple contexts to be validated:
  person.valid?([:create, :update])    # => true

The change isn't visible in the API documentation which this PR
fixes.
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.

None yet

4 participants