首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

自定义form揭示

2012-12-21 
自定义form提示自定义form错误提示application_controller.rb中添加:ActionView::Base.field_error_proc

自定义form提示
自定义form错误提示

application_controller.rb中添加:

ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|  case html_tag  when /<(label)/    %(<div name="code"><% if target.errors.any? %>  <div id="error">  <p><%= I18n.t('activerecord.errors.template.header', :count => target.errors.count, :model => target.class.model_name.human.downcase) %></p>  </div><% end %>

调用:
<%= render "shared/error_messages", :target => @post %>

语言文件:
activerecord:models:post: "帖子"

热点排行