Displaying articles with tag fieldwitherrors

Modifying fieldWithErrors

Posted by PunNeng, Sat Jul 05 20:33:00 UTC 2008

fieldWithErrors เนี่ย บางทีมันก็มีประโยชน์ดีนะ แต่บางทีก็อยากจะเอาออก หรืออยากจะแก้ไข

เอาแบบนี้ดีกว่า

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|          
  if html_tag =~ /<label.*>.*<\/label>/
    "<div class=\"labelWithErrors\">#{html_tag}</div>" 
  elsif html_tag =~ /terms_and_conditions/   
    "<div class=\"tickWithErrors\">#{html_tag}</div>"
  elsif html_tag =~ /radio/
    "<div class=\"radioWithErrors\">#{html_tag}</div>"     
  else
    "<div class=\"fieldWithErrors\">#{html_tag}</div>"      
  end                            
end

ใส่ไปใน environment.rb
ใครมีความคิดอะไรก็ใส่ไปให้หมด สำหรับผมการ filter ง่ายๆ ก็ใช้ RegExp ครับ

ไม่มีกะจิตกะใจจะเขียนเท่าไหร่ กำลังทะเลาะกับ Merb อยู่ ทำไมมันติดตั้งยากเยี่ยงนี้ !!

0 comments | Filed Under: Ruby on Rails | Tags: fieldwitherrors

codegent: we're hiring