Archive for 2010

Custom Ordered Error Messages in Rails

Friday, June 25, 2010 · Posted in

In rails 2, if you want custom messages in ordered style then,
you have to install plugin from

http://orderederrors.rubyforge.org/

and use below lines in views (it's an example)
error_messages_for(:user, :order=>[:name,:email])
error_messages_for(:user, :order=>{:user=>[:name,:email,:contact]})

It will give you messages in ordered but not customized
To customize message you have to change "patch_active_record.rb" file from "lib" directory from "ordered_error_messages_for" plugin by below code:
------------------------------------------------------------------------------------------------------
ActiveRecord::Errors.class_eval do
  def full_messages(ordered_keys=nil)
    full_messages = []
    ordered_keys = [] unless ordered_keys
    # First, take the intersection of ordered keys and actual errors.
    ordered_keys &= @errors.keys
    # Then, add whatever was not specified in the order array.
    ordered_keys += @errors.keys-ordered_keys
    ordered_keys.each do |attr|
      @errors[attr].each do |msg|
        next if msg.nil?
        if attr == "base"
          full_messages << msg
        elsif msg =~ /^\^/
          full_messages << msg[1..-1]
        elsif msg.is_a? Proc
          full_messages << msg.call(@base)
        else
          full_messages << @base.class.human_attribute_name(attr) + " " + msg
        end
      end
    end
    full_messages
  end
end
------------------------------------------------------------------------------------------------------

Now you have to restart the server

To customize message you can use below lines in model (It's an example)

validates_presence_of :name, :message => "^Hey, name can't be blank"

Now you will get error messages in ordered and customized.

unknown runtime error in prototype.js Line: 2457

Thursday, April 15, 2010 · Posted in

this statement in prototype.js (line 2457):
   else element.innerHTML = content.stripScripts();
gives an error : "unknown runtime error" in IE

To solve this problem, just make below changes in your code in all js

Change the statement from

this.month_year_label.update(Date.months[m]);
to
this.month_year_label.update().insert(Date.months[m]);


only change is:
instead of using method "update",  use "update().insert"

Powered by Blogger.