css - 关于 Michael Hartl 的(优秀的)Rails 教程的第 7 章练习 2

标签 css ruby-on-rails

练习 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'

关于css - 关于 Michael Hartl 的(优秀的)Rails 教程的第 7 章练习 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27054475/

相关文章:

html - 如何结合 :not Selector with > Selector?

css - 如何更改 Bootstrap 导航栏中选定下拉菜单的颜色?

javascript - Tailwind.min.css 在我的 Nuxt 应用程序中覆盖 tailwind.css

mysql - 如何在 Windows 8 中启动 Ruby on Rails?

ruby-on-rails - 哈希值中随机数的 Rspec 匹配器

html - 星级评定系统 : Works on only one instance

html - 边框半径在 IE9 中不起作用

ruby-on-rails - Rails - 保存 Ransack 查询以供以后使用

ruby-on-rails - 所有之前的 Rails rspec 与每个之前的 Rails rspec

css - 字体不会在 IE 中呈现