【发布时间】:2013-12-16 02:05:24
【问题描述】:
我最近在我的 Rails 4 应用程序上安装了friendly_id 5。我遵循了快速入门指南,并设置了这样的模型:
class Official::Master < Official
extend FriendlyId
friendly_id :name, use: [:slugged, :history]
end
但是,当我尝试保存 Official::Master 时,出现此错误:
undefined method `friendly' for #<ActiveRecord::Relation []>
这发生在create 控制器操作中:
def create
official = Official::Master.new(official_params)
official.save # error occurs on this line
end
不幸的是,Rails 没有生成堆栈跟踪,而它通常会这样做。我不知道如何解决此错误。
更新:
移除了回溯消音器并得到了这个:
activerecord (4.0.1) lib/active_record/relation/delegation.rb:121:in
method_missing' activerecord (4.0.1) lib/active_record/relation/delegation.rb:68:inmethod_missing' friendly_id (5.0.1) lib/friendly_id/slugged.rb:302:inscope_for_slug_generator' friendly_id (5.0.1) lib/friendly_id/history.rb:104:inscope_for_slug_generator' friendly_id (5.0.1) lib/friendly_id/slugged.rb:313:inslug_generator' friendly_id (5.0.1) lib/friendly_id/slugged.rb:294:inset_slug'
看起来错误出现在 slugged.rb 的第 302 行:
scope = scope.friendly unless friendly_id_config.uses? :finders
【问题讨论】: