Skip to content

Instantly share code, notes, and snippets.

@MittalPatel-BTC
Created May 6, 2019 11:08
Show Gist options
  • Save MittalPatel-BTC/fbba3910a31e7494d909fd9ca4b0fcab to your computer and use it in GitHub Desktop.
Save MittalPatel-BTC/fbba3910a31e7494d909fd9ca4b0fcab to your computer and use it in GitHub Desktop.
Rails 6 added changes for slice! method to ActiveModel::Errors
# Rails 6
> user = User.new
=> #<User id: nil, name: nil, email: nil, rating: 0, password: nil, created_at: nil, updated_at: nil>
> user.valid?
=> false
> user.errors
=> #<ActiveModel::Errors:0x00007fc46700df10 @base=##<User id: nil, name: nil, email: nil, rating: 0, password: nil, created_at: nil, updated_at: nil>, @messages={:email=>["can't be blank"], :password=>["can't be blank"]}, @details={:email=>[{:error=>:blank}], :password=>[{:error=>:blank}]}>
> user.errors.slice!(:email)
=> {:password=>["can't be blank"]}
> user.errors
=> #<ActiveModel::Errors:0x00007fc46700df10 @base=##<User id: nil, name: nil, email: nil, rating: 0, password: nil, created_at: nil, updated_at: nil>, @messages={:email=>["can't be blank"]}, @details={:email=>[{:error=>:blank}]}>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment