我正在从 jumpstartlab.com 编写 Blogger 教程。我有一个奇怪的问题。当我运行服务器时,它看起来相当不错。我在“/articles”下看到了一个文章列表。但是当我尝试查看其中一个时,我得到一个错误:
ActiveRecord::StatementInvalid in Articles#show
Showing /home/rails_projects/blogger/app/views/articles/show.html.erb where line
#6 raised:
SQLite3::SQLException: no such column: comments.article_id: SELECT COUNT(*) FROM
"comments" WHERE "comments"."article_id" = ?
Extracted source (around line #6):
3
4 <%= link_to "edit", edit_article_path(@article) %>
5
6 <h3>Comments(<%= @article.comments.count %>)</h3>
7
8 <%= render partial: 'articles/comment', collection: @article.comments %>
9 <%= render partial: 'comments/form' %>
显示.html.erb:
<%= link_to "edit", edit_article_path(@article) %>
<h3>Comments(<%= @article.comments.count %>)</h3>
<%= render partial: 'articles/comment', collection: @article.comments %>
<%= render partial: 'comments/form' %>
<%= link_to "<< Back to Articles List", articles_path%>
<%= link_to "edit", edit_article_path(@article) %>
<%= link_to "delete", article_path(@article),method: :delete, :confirm => "Really
delete the article?"
Articles_controller.rb
class ArticlesController < ApplicationController
def index
@articles = Article.all
end
def show
@article = Article.find(params[:id])
end
def edit
@article = Article.find(params[:id])
end
def create
@article = Article.new(params[:article])
@article.save
redirect_to article_path(@article)
end
def article_params
params.require(:article).permit(:title, :body)
end
def update
@article = Article.find(params[:id])
@article.update_attributes(params[:article])
flash.notice = "Article '#{@article.title}' Updated!"
redirect_to article_path(@article)
end
def change
create_table :articles do |t|
t.string :title
t.text :body
t.timestamps
end
end
def new
@article = Article.new
end
end
20130716025552_create_articles.rb
Class CreateArticles < ActiveRecord::Migration
def change
create_table :articles do |t|
t.integer :article_id
t.string :title
t.text :body
t.timestamps
end
end
end
20130717021354_create_comments.rb
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.string :author_name
t.integer :article_id
t.text :body
t.string :article
t.string :references
t.timestamps
end
end
end
我很困惑,真的不知道如何处理这个问题。