自定义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: "帖子"