Rails Error Messages Deprecated
Contents |
Sign in Pricing Blog Support Search GitHub This rails validation errors repository Watch 2,293 Star 33,153 Fork 13,503 rails/rails Code
Rails Validation Error Message
Issues 541 Pull requests 686 Projects 0 Pulse Graphs Deprecate `ActiveModel::Errors` `get`, `set` and rails error messages in view `[]=` methods. #18634 Merged rafaelfranca merged 1 commit into rails:master from morgoth:deprecate-some-errors-methods Feb 18, 2015 Conversation 11 Commits 1 Files changed 3
Rails Custom Error Messages
Changes from all commits Commits Show all changes 1 commit Select commit 6ec8ba1 Deprecate `ActiveModel::Errors` `get`, `set` and `[]=` methods. morgoth Jan 21, 2015 3 files Jump to file +5 −0 CHANGELOG.md activemodel/CHANGELOG.md +28 −9 errors.rb activemodel/lib/active_model/errors.rb +21 −15 errors_test.rb activemodel/test/cases/errors_test.rb +54 −24 Unified activerecord errors full messages Split Show comments View 5 activemodel/CHANGELOG.md @@ -1,3 +1,8 @@ +* Deprecate `ActiveModel::Errors#get`, `ActiveModel::Errors#set` and + `ActiveModel::Errors#[]=` methods that have inconsistent behaviour. + + *Wojciech Wnętrzak* + * Change the default error message from `can't be blank` to `must exist` for the presence validator of the `:required` option on `belongs_to`/`has_one` associations. Show comments View 37 activemodel/lib/active_model/errors.rb @@ -3,6 +3,7 @@ require 'active_support/core_ext/array/conversions' require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/object/deep_dup' +require 'active_support/deprecation' module ActiveModel # == Active \Model \Errors @@ -72,7 +73,7 @@ class Errors # end def initialize(base) @base = base - @messages = {} + @messages = Hash.new { |messages, attribute| messages[attribute] = [] } @details = Hash.new { |details, attribute| details[attribute] = [] } end @@ -110,8 +111,14 @@ def include?(attribute) # # person.errors.messages # => {:name=>["cannot be nil"]} # person.errors.get(:name) #
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings
Rails Form Errors
and policies of this site About Us Learn more about Stack Overflow
Rails Exceptions
the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags rails errors add custom message Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only https://github.com/rails/rails/pull/18634/files takes a minute: Sign up DEPRECATION WARNING: f.error_messages was removed from Rails and is now available as a plugin up vote 2 down vote favorite 1 DEPRECATION WARNING: f.error_messages was removed from Rails and is now available as a plugin. Please install it with rails plugin install git://... Seems a bit extreme to use a plugin for error messages like http://stackoverflow.com/questions/8070307/deprecation-warning-f-error-messages-was-removed-from-rails-and-is-now-availabl this. Am I not using the right standard names or something? The code (HAML) is: - simple_form_for(@link) do |f| = f.error_messages ruby-on-rails ruby share|improve this question asked Nov 9 '11 at 19:17 Michael Durrant 46.6k46188299 add a comment| 3 Answers 3 active oldest votes up vote 1 down vote There is no misspelling in your code, f.error_messages are deprecated in fact. There is a discussion on stackoverflow: f.error_messages in Rails 3.0. share|improve this answer answered Nov 9 '11 at 20:48 Michał Czapko 1,53911022 add a comment| up vote 1 down vote accepted Thanks Michal. I will give you an upvote. I found that the following was a good quick replacement for the upgrade: -if @link.errors.any? %div#error_explanation %h2 =pluralize(@link.errors.count, "error")+' ' prohibited this link from being saved: %ul -@link.errors.full_messages.each do |msg| %li =msg share|improve this answer edited Mar 25 '12 at 5:37 answered Nov 9 '11 at 21:00 Michael Durrant 46.6k46188299 add a comment| up vote 1 down vote You could install the dynamic_form gem which supports a few helpers for your Rails 3 models. One of this helpers is error
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings http://stackoverflow.com/questions/4648222/ruby-on-rails-treat-deprecation-warnings-as-errors-or-otherwise-find-deprecated and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs http://apidock.com/rails/ActiveModel/Validations/ClassMethods/validates_presence_of Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; error message it only takes a minute: Sign up Ruby on Rails: Treat deprecation warnings as errors or otherwise find deprecated code? up vote 10 down vote favorite 2 I recently upgraded from Rails 2 to Rails 3, and I'm trying to root out all the code I might have that is deprecated. The way I'm doing this is just surfing around rails error messages a copy of my site running on a development machine, and peering at the output from the console for warnings. Is there a way to cause Rails to treat deprecation warnings as errors or otherwise find deprecated code more efficiently? ruby-on-rails deprecated share|improve this question asked Jan 10 '11 at 15:10 William Jones 6,351124282 add a comment| 1 Answer 1 active oldest votes up vote 11 down vote accepted You can customise the behaviour of deprecated calls by setting ActiveSupport::Deprecation.behavior. This should be set to a Proc that accepts a message and a callstack e.g. you could do: ActiveSupport::Deprecation.behavior = Proc.new { |message, callstack| raise message + "\n" + callstack.join("\n ") } If you have automated tests for your app these are invaluable when upgrading the version of Rails being used. share|improve this answer answered Jan 10 '11 at 15:30 mikej 42.4k10108110 Where Proc has to be located? –Iván Cortés Romero Jun 13 at 16:01 1 @Iván you could put this in a file of its own in config/initializers e.g. deprecation.rb. Also note i
1.1.1 1.1.6 1.2.0 1.2.6 2.0.0 2.0.3 2.1.0 (0) 2.2.1 (0) 2.3.2 (0) 2.3.8 (0) 3.0.0 3.0.5 3.0.9 3.1.0 3.2.1 3.2.3 3.2.8 3.2.13 4.0.2 4.1.8 4.2.1 4.2.7 What's this? Related methods Instance methods (24) attribute_method? clear_validators! inherited _parse_validates_options validate validates validates! validates_acceptance_of (<= v2.3.8) validates_associated (<= v2.3.8) validates_confirmation_of (<= v2.3.8) _validates_default_keys validates_each validates_exclusion_of (<= v2.3.8) validates_format_of (<= v2.3.8) validates_inclusion_of (<= v2.3.8) validates_length_of (<= v2.3.8) validates_numericality_of (<= v2.3.8) validates_presence_of (<= v2.3.8) validates_size_of (<= v2.3.8) validates_uniqueness_of (<= v2.3.8) validates_with validation_method (<= v2.3.8) validators validators_on = private = protected Method deprecated or moved This method is deprecated or moved on the latest stable version. The last existing version (v2.3.8) is shown here. These similar methods exist in v4.2.7: ActiveRecord::Validations::ClassMethods#validates_presence_of ActiveModel::Validations::HelperMethods#validates_presence_of validates_presence_of(*attr_names) public Validates that the specified attributes are not blank (as defined by Object#blank?). Happens by default on save. Example: class Person < ActiveRecord::Base validates_presence_of :first_name end The first_name attribute must be in the object and it cannot be blank. If you want to validate the presence of a boolean field (where the real values are true and false), you will want to use validates_inclusion_of :field_name, :in => [true, false] This is due to the way Object#blank? handles boolean values: false.blank? # => true Configuration options: :message - A custom error message (default is: "can't be blank") :on - Specifies when this validation is active (default is :save, other options :create, :update) :if - Specifies a method, proc or string to call to determine if the validation should occur (e.g. :if => :allow_vali