正在处理失败的注册表单时出现错误,当前该表单在视觉上显示为“关闭”,如下图所示:
错误部分周围有一个红色框,不应该存在,每个列表错误旁边都有星号,它们不应该存在,并且由于某种原因没有密码确认错误。此外,所有输入字段都缩小了,并被过度突出显示为红色。
(请注意,为了好玩,我将用户资源更改为狗资源)

这是我的自定义css.scss
@import "bootstrap";
/* mixins, variables, etc. */
$grayMediumLight: #eaeaea;
@mixin box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
/* universal */
html {
overflow-y: scroll;
}
body {
padding-top: 60px;
}
section {
overflow: auto;
}
textarea {
resize: vertical;
}
.center {
text-align: center;
h1 {
margin-bottom: 10px;
}
}
/* typography */
h1, h2, h3, h4, h5, h6 {
line-height: 1;
}
h1 {
font-size: 3em;
letter-spacing: -2px;
margin-bottom: 30px;
text-align: center;
}
h2 {
font-size: 1.2em;
letter-spacing: -1px;
margin-bottom: 30px;
text-align: center;
font-weight: normal;
color: $grayLight;
}
p {
font-size: 1.1em;
line-height: 1.7em;
}
/* header */
#logo {
float: left;
margin-right: 10px;
font-size: 1.7em;
color: white;
text-transform: uppercase;
letter-spacing: -1px;
padding-top: 9px;
font-weight: bold;
line-height: 1;
&:hover {
color: white;
text-decoration: none;
}
}
/* footer */
footer {
margin-top: 45px;
padding-top: 5px;
border-top: 1px solid $grayMediumLight;
color: $grayLight;
a {
color: $gray;
&:hover {
color: $grayDarker;
}
}
small {
float: left;
}
ul {
float: right;
list-style: none;
li {
float: left;
margin-left: 10px;
}
}
}
/* sidebar */
aside {
section {
padding: 10px 0;
border-top: 1px solid $grayLighter;
&:first-child {
border: 0;
padding-top: 0;
}
span {
display: block;
margin-bottom: 3px;
line-height: 1;
}
h1 {
font-size: 1.4em;
text-align: left;
letter-spacing: -1px;
margin-bottom: 3px;
margin-top: 0px;
}
}
}
.gravatar {
float: left;
margin-right: 10px;
}
/* miscellaneous */
.debug_dump {
clear: both;
float: left;
width: 100%;
margin-top: 45px;
@include box_sizing;
}
/* forms */
input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
margin-bottom: 15px;
@include box_sizing;
}
input {
height: auto !important;
}
#error_explanation {
color: #f00;
ul {
list-style: none;
margin: 0 0 18px 0;
}
}
.field_with_errors {
@extend .control-group;
@extend .error;
}这是new.html.erb
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<div class="row">
<div class="span6 offset3">
<%= form_for(@dog) do |f| %>
<%= render 'shared/error_messages' %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Password Confirmation" %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
<% end %>
</div>
最后,共享/_error_messages.html.erb
<% if @dog.errors.any? %>
<div id="error_explanation">
<div class="alert alert-error">
The form contains <%= pluralize(@dog.errors.count, "error") %>.
</div>
<ul>
<% @dog.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>啊和我的DogsController中的帮助(有趣的注意,创建操作有一个呈现‘新’,但如果我点击提交按钮与无效的信息,它被重定向到索引url (/dogs),但仍然有形式错误?在本教程中,它看起来也是这样的,但只是发现这一点很有趣。)
class DogsController < ApplicationController
def new
@dog = Dog.new
end
def show
@dog = Dog.find(params[:id])
end
def create
@dog = Dog.new(dog_params)
if @dog.save
redirect_to @dog
else
render 'new'
end
end
private
def dog_params
params.require(:dog).permit(:name, :email, :password,
:password_confirmation)
end
end任何帮助都是非常感谢的!
发布于 2013-12-06 22:11:00
好的,我通过删除scaffolds.css.scss中的所有内容来修正它。不知道这个文件是什么,也不知道代码是怎么进来的。
发布于 2017-01-28 00:40:18
检查是否存在此文件:
app/assets/stylesheets/scaffolds.css.scss如果您有这个文件,您可能使用了一个脚手架生成器。
看起来它优先于其他样式表,例如app/assets/stylesheets/custom.css.scss
您应该能够重命名或删除该文件以修复您的问题。
发布于 2013-12-06 11:47:43
您可以尝试以下方法
将list-style: none;更改为list-style-type:none;并从<li>* <%= msg %></li>中删除*
https://stackoverflow.com/questions/20422624
复制相似问题