how to beautify validations in rails

后端 未结 3 2058
长情又很酷
长情又很酷 2021-02-11 09:19

I have a simple scaffold rails application that is doing validataes_presence_of.

The validation is making each textfield bordered. I just want the error messages to b

相关标签:
3条回答
  • 2021-02-11 09:54

    I would suggest having a look at Formtastic. Easy to setup, works great with scaffold-type apps and has some nice clean HTML and CSS.

    0 讨论(0)
  • 2021-02-11 09:56

    Rails applications store their CSS in [application_root]/public/stylesheets. A new rails app will have a file called default.css in this directory. This file contains the following:

    #errorExplanation {
      width: 400px;
      border: 2px solid red;
      padding: 7px;
      padding-bottom: 12px;
      margin-bottom: 20px;
      background-color: #f0f0f0;
    }
    
    #errorExplanation h2 {
      text-align: left;
      font-weight: bold;
      padding: 5px 5px 5px 15px;
      font-size: 12px;
      margin: -7px;
      background-color: #c00;
      color: #fff;
    }
    
    #errorExplanation p {
      color: #333;
      margin-bottom: 0;
      padding: 5px;
    }
    
    #errorExplanation ul li {
      font-size: 12px;
      list-style: square;
    }
    

    If you play about with the values of some of the parameters here - in particular border - you might find something that looks more to your taste.

    0 讨论(0)
  • 2021-02-11 10:03

    Have you checked rails guide about validation errors?

    0 讨论(0)
提交回复
热议问题