我目前正在学习Rails教程。当我在第10章进行了Rails测试时,出现了此错误。 我可以用ruby gem'faker'造很多假用户。 但是,似乎db没有users.yml的提示。 我认为这就是在进行Rails测试时发生错误的原因。
UsersControllerTest#test_should_get_new:
ActiveRecord::Fixture::FixtureError: table "users" has no column named "lana".
我命令
rails db:reset
rails db:seed
michael:
name: Michael Example
email: michael@example.com
password_digest: <%= User.digest('password') %>
admin: true
activated: true
activated_at: <%= Time.zone.now %>
archer:
name: Sterling Archer
email: duchess@example.gov
password_digest: <%= User.digest('password') %>
activated: true
activated_at: <%= Time.zone.now %>
lana:
name: Lana Kane
email: hands@example.gov
password_digest: <%= User.digest('password') %>
activated: true
activated_at: <%= Time.zone.now %>
malory:
name: Malory Archer
email: boss@example.gov
password_digest: <%= User.digest('password') %>
activated: true
activated_at: <%= Time.zone.now %>
<% 30.times do |n| %>
user_<%= n %>:
name: <%= "User #{n}" %>
email: <%= "user-#{n}@example.com" %>
password_digest: <%= User.digest('password') %>
activated: true
activated_at: <%= Time.zone.now %>
<% end %>
1) Error:
UsersEditTest#test_successful_edit_with_friendly_forwarding:
ActiveRecord::Fixture::FixtureError: table "users" has no column named "lana".
Error:
UsersEditTest#test_successful_edit_with_friendly_forwarding:
NoMethodError: undefined method `each' for nil:NilClass
2) Error:
UsersEditTest#test_unsuccessful_edit:
ActiveRecord::Fixture::FixtureError: table "users" has no column named "lana".
Error:
UsersEditTest#test_unsuccessful_edit:
NoMethodError: undefined method `each' for nil:NilClass
请给我建议以解决此问题?
答案 0 :(得分:0)
您的缩进是错误的,为此请更改lana部分:
{{1}}