我有一篇文章
class CreateArticles < ActiveRecord::Migration[5.1]
def change
create_table :articles do |t|
t.string :title
t.text :body
t.timestamps
end
end结束
遵循friendly_id自述文件
1)。rails generate friendly_id
2.)向Article模型添加扩展
class Article < ApplicationRecord
extend FriendlyId
friendly_id :title, use: :slugged'
end3)。添加slug field to article table
class AddSlugToArticle < ActiveRecord::Migration[5.1]
def change
add_column :articles, :slug, :string
add_index :articles, :slug, unique: true
end
end打开web浏览器http://localhost:3000/article/new可以看到rails terminal

这是文章控制器中的问题所在:
def show
@article = Article.friendly.find(params[:id])
@comments = @article.comments.order("created_at desc").paginate(:page => params[:page], per_page: 4)
respond_to do |format|
format.html
format.json { render json: [@article, @comments], except: [:created_at, :updated_at] }
end
end此终端错误报告:

https://stackoverflow.com/questions/47608480
复制相似问题