【发布时间】:2014-08-31 18:23:45
【问题描述】:
设置friendly_id gem 后,我遇到了activeadmin gem 的问题,
每当我尝试使用管理面板更新、删除或创建帖子时,它都会抛出RecordNotFound。
这是 app/controllers/post_controller.rb 中的代码:
class PostsController < ApplicationController
def index
@posts = Post.all
end
def show
@post = Post.friendly.find(params[:id])
end
end
并且来自 app/models/post.rb:
class Post < ActiveRecord::Base
belongs_to :category
attr_accessible :title, :slug, :blurb, :content, :category_id
scope :tarot, -> { where(category_id: 1) }
extend FriendlyId
friendly_id :title, use: :slugged
end
【问题讨论】:
-
错误堆栈跟踪?您可以从日志文件中获取它。
-
任何更多信息将不胜感激。您是否删除并迁移了数据库?桌子有蛞蝓柱吗?是在该列中创建的友好 ID。我认为
extend FriendlyId部分应该在类定义的第一行。 -
是的,该表有一个 slug 列。
标签: ruby-on-rails activeadmin friendly-id