Skip to content

Deprecate ActiveModel::Errors add_on_empty and add_on_blank methods#18996

Merged
senny merged 1 commit into
rails:masterfrom
morgoth:deprecate-more-errors-methods
Feb 19, 2015
Merged

Deprecate ActiveModel::Errors add_on_empty and add_on_blank methods#18996
senny merged 1 commit into
rails:masterfrom
morgoth:deprecate-more-errors-methods

Conversation

@morgoth

@morgoth morgoth commented Feb 18, 2015

Copy link
Copy Markdown
Member

Follow up to #18634 (comment)

@morgoth

morgoth commented Feb 18, 2015

Copy link
Copy Markdown
Member Author

I'm not sure if we should delete this test https://github.com/rails/rails/pull/18996/files#diff-399b5cddc709ef96edf30de2328934deR56 as it doesn't have any equivalent in regular validations and :empty symbol is used only in deprecated add_on_empty method

@senny

senny commented Feb 19, 2015

Copy link
Copy Markdown
Member

@morgoth let's remove that test when we remove the deprecated methods and keep it around for now.

@senny

senny commented Feb 19, 2015

Copy link
Copy Markdown
Member

Even though we do not provide a direct replacement the deprecation message should give a hint where to look for similar behavior. It should be trivial to figure out what to change or where to look for more details.

@morgoth morgoth force-pushed the deprecate-more-errors-methods branch from f5ce031 to 401b86f Compare February 19, 2015 08:04
@morgoth

morgoth commented Feb 19, 2015

Copy link
Copy Markdown
Member Author

@senny I added tip to use PresenceValidator. In add_on_empty it's almost true ;-), as I'm not sure if we should describing implementation details here.

@senny

senny commented Feb 19, 2015

Copy link
Copy Markdown
Member

The thing is that PresenceValidator is # :nodoc:. Don't think we should encourage it's use.

@morgoth

morgoth commented Feb 19, 2015

Copy link
Copy Markdown
Member Author

What about "To achieve the same use validates_presence_of with :empty message"?

@senny

senny commented Feb 19, 2015

Copy link
Copy Markdown
Member

If you have used add_on_empty its likely in a custom validation method with logic attached to it. That's probably why they didn't choose to use a validates_presence_of. Maybe combined with an :if option?

/cc @rafaelfranca

@rafaelfranca

Copy link
Copy Markdown
Member

Yeah, it is more a kind of internal method to be used in custom validations. I think it is better to suggest people to write the actual code:

errors.add(attribute, :empty, options) if value.nil? || value.empty?

@morgoth morgoth force-pushed the deprecate-more-errors-methods branch from 401b86f to dbcfd70 Compare February 19, 2015 11:46
@morgoth

morgoth commented Feb 19, 2015

Copy link
Copy Markdown
Member Author

@rafaelfranca I changed it to your suggestion

@morgoth morgoth force-pushed the deprecate-more-errors-methods branch from dbcfd70 to 126b05c Compare February 19, 2015 11:47
Comment thread activemodel/lib/active_model/errors.rb Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here but using blank?

@morgoth morgoth force-pushed the deprecate-more-errors-methods branch from 126b05c to fd38838 Compare February 19, 2015 13:11
@morgoth

morgoth commented Feb 19, 2015

Copy link
Copy Markdown
Member Author

done

@senny

senny commented Feb 19, 2015

Copy link
Copy Markdown
Member

@morgoth thank you 💛

@senny senny merged commit fd38838 into rails:master Feb 19, 2015
senny added a commit that referenced this pull request Feb 19, 2015
Deprecate `ActiveModel::Errors` `add_on_empty` and `add_on_blank` methods
@morgoth morgoth deleted the deprecate-more-errors-methods branch March 31, 2015 19:26
ledermann added a commit to ledermann/rails that referenced this pull request Aug 27, 2016
This fixes a copy-and-paste-issue slipped in by rails#18996
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants