精華區beta Ruby 關於我們 聯絡資訊
在下的 Blog http://blog.yam.com/thegiive/archives/2064413.html 利用Ruby 可輕易 override 已經定義好的 class 的特性 在 app 底下新增一個程式 module ActiveRecord class Errors begin @@default_error_messages.update( { :inclusion => "中文", :exclusion => "中文", :invalid => "中文", :confirmation => "中文", :accepted => "中文", :empty => "中文", :blank => "中文", :too_long => "中文", :too_short => "中文", :wrong_length => "中文", :taken => "中文", :not_a_number => "中文", }) end end end module ActionView #nodoc module Helpers module ActiveRecordHelper def error_messages_for(object_name, options = {}) options = options.symbolize_keys object = instance_variable_get("@#{object_name}") unless object.errors.empty? content_tag("div", content_tag( options[:header_tag] || "h2", "一共有 #{pluralize(object.errors.count, "error")} 問>題 " ) + content_tag("p", "請更正:") + content_tag("ul", object.errors.full_messages.collect { |msg| content_tag("li", msg) }), "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation" ) end end end end 然後將 config/enviorment.rb 加入 require "#{RAILS_ROOT}/app/你的filename" 如此就有可愛的中文 Valid Error Message -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.174.209.17