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.
Set default index.html page in NGINX
-
Recently I setup Jekyll-Blog on nginx server which is pure html code. When
I tried to call url without index.html (http://domain.com/blog/) in path,
it wa...
8 years ago