简体   繁体   English

Rails Simple_form-如何在div中包装error_notification

[英]Rails Simple_form - How can I wrap error_notification in a div

I'm using the simple_form gem in Rails to create a form. 我在Rails中使用simple_form gem创建表单。 To handle the server side errors I'm using: 为了处理服务器端错误,我正在使用:

<%= f.error_notification %>

And when the form is submitted and server-side errors are generated, they're generated in ap tag like so: 提交表单并生成服务器端错误时,它们会在ap标签中生成,如下所示:

<p class="error_notification">Here are all the errors....</p>

I want wrap a div around the p element, because I'd like to create a red background for the message container via CSS, and I don't want to style the P element directly. 我想将div包裹在p元素周围,因为我想通过CSS为消息容器创建红色背景,并且我不想直接设置P元素的样式。 Is there some way to do this inside of Rails with simple_form? 有没有什么办法可以在Rails中使用simple_form做到这一点?

I've seen this here: https://github.com/plataformatec/simple_form/blob/master/lib/generators/simple_form/templates/config/initializers/simple_form.rb , line 65 我在这里看到了这一点: https : //github.com/plataformatec/simple_form/blob/master/lib/generators/simple_form/templates/config/initializers/simple_form.rb ,第65行

# Default tag used for error notification helper.
  config.error_notification_tag = :div

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM