[英]Trouble in Chapter 8 of Michael Hartl's Rails Tutorial - CSS Expects
[英]On Chapter 7, Excercise 2, of Michael Hartl's (excellent) Rails Tutorial
練習2:他建議的用於檢查與表單注冊相關的錯誤消息的模板是下面的最后兩個assert_selects:
require 'test_helper'
class UsersSignupTest < ActionDispatch::IntegrationTest
test "invalid signup information" do
get signup_path
assert_no_difference 'User.count' do
post users_path, user: { name: "",
email: "user@invalid",
password: "foo",
password_confirmation: "bar" }
end
assert_template 'users/new'
assert_select 'div#<CSS id for error explanation>'
assert_select 'div.<CSS class for field with error>'
end
我無法弄清楚需要用什么來代替他在括號內的內容。 自定義CSS的表單部分如下所示:
#error_explanation {
color: red;
ul {
color: red;
margin: 0 0 30px 0;
}
}
.field_with_errors {
@extend .has-error;
.form-control {
color: $state-danger-text;
}
}
按照他的指示添加它們
assert_select 'div#<CSS id for error explanation>'
assert_select 'div.<CSS class for field with error>'
將會
assert_select 'div#error_explanation'
assert_select 'div.field_with_errors'
assert_select 'div#error_explanation'
assert_select 'div.field_with_errors'
本教程希望我用上述代碼替換示例。 我不明白,但終於找到了答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.