我对编码和 Mhartl 教程的第 8 章非常陌生,当我尝试 -bundle exec rspec spec/ 时遇到 34 个错误。不幸的是,我只能找出错误 19-34(1-18 不适合我的终端)。
Static pages About page it should behave like all static pages
<[31mFailure/Error:<-[0m <[31mbefore { visit root_path }<]0m
<[31mActionView:Template::Error<[0m:
<[31mSQLite3::SQLException: no such column: users.remember_token: SELECT
"users".* FROM "users" WHERE "users"."remember_token" = 'lotsofrandomcharacters' LIMIT 1<[0m
那是错误19。其他类似,参考:
Static pages Help page
Static pages Help page it should behave like all static pages
Static pages Help page it should behave like all static pages
Static pages Home page
Static pages Home page it should behave like all static pages
Static pages Home page it should behave like all static pages
Static pages Contact page
Static pages Contact page it should behave like all static pages
Static pages Contact page it should behave like all static pages
User
User remember token remember_token
User return value of authenticate method with valid password
User return value of authenticate method with valid password
User when email address is already taken
我是一个编程菜鸟,这让人难以接受。
这是我在本章中处理的几个文件
应用程序/视图/布局/_header.html.erb
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
<%= link_to "sample app", root_path, id: "logo" %>
<nav>
<ul class="nav pull-right">
<li><%= link_to "Home", root_path %></li>
<li><%= link_to "Help", help_path %></li>
<% if signed_in? %>
<li><%= link_to "Users", '#' %></li>
<li id="fat-menu" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", '#' %></li>
<li class="divider"></li>
<li>
<%= link_to "Sign out", signout_path, method: "delete" %>
</li>
</ul>
</li>
<% else %>
<li><%= link_to "Sign in", signin_path %></li>
<% end %>
</ul>
</nav>
</div>
</div>
</header>
应用程序/helpers/sessions_helper.rb
module SessionsHelper
def sign_in(user)
remember_token = User.new_remember_token
cookies.permanent[:remember_token] = remember_token
user.update_attribute(:remember_token, User.encrypt(remember_token))
self.current_user = user
end
def signed_in?
!current_user.nil?
end
def current_user=(user)
@current_user = user
end
def current_user
remember_token = User.encrypt(cookies[:remember_token])
@current_user ||= User.find_by(remember_token: remember_token)
end
def sign_out
self.current_user = nil
cookies.delete(:remember_token)
end
end
当我运行 rails 服务器并尝试在 localhost:3000 上查看它时,我得到:
sample_app/app/views/layouts/_header.html.erb 其中第 9 行提出:
SQLite3::SQLException: 没有这样的列:users.remember_token: SELECT "users".* FROM "users" WHERE "users"."remember_token" = 'lotsofcharacters' LIMIT 1
这一行指的是:<% if signed_in? %>
老实说,我不确定要在此处列出什么其他文件,因为我什至无法阅读完整的错误。我相信我的联系/关于/主页很好,因为它们在本章中保持不变,但如果有人认为我应该列出这些,我可以这样做。谢谢您的帮助!