Skip to content

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

Merged
rafaelfranca merged 1 commit into
rails:masterfrom
dmitry:feature/validate-multiple-contexts
Sep 8, 2015
Merged

rafaelfranca merged 1 commit into
rails:masterfrom
dmitry:feature/validate-multiple-contexts

Conversation

@dmitry

@dmitry dmitry commented Sep 7, 2015

Copy link
Copy Markdown
Contributor

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
Copy Markdown

r? @kaspth

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

@kaspth

kaspth commented Sep 8, 2015

Copy link
Copy Markdown
Contributor

r? @rafaelfranca

Den 07/09/2015 kl. 23.44 skrev Ruby on Rails Bot [email protected]:

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.

4 participants