【发布时间】:2013-07-08 03:05:06
【问题描述】:
以下代码适用于 Rails-2 应用程序,但不适用于 Rails-3 升级:
在 user.rb 模型中:
has_many :auction_lots, :class_name => "Auction::Lot", :order => "position"
在 lot.rb 模型中:
class Auction::Lot < ActiveRecord::Base
include ActionController::UrlWriter
belongs_to :user
scope :unplanned, :conditions => "status < #{STATUS[:in_stock]}"
end
ActionView::Template::Error(未初始化常量 User::AuctionLot):
150: <% unless current_user.auction_lots.unplanned.empty? %>
activerecord (3.2.13) lib/active_record/inheritance.rb:111:in `compute_type'
activerecord (3.2.13) lib/active_record/reflection.rb:172:in `klass'
activerecord (3.2.13) lib/active_record/associations/association.rb:117:in `klass'
activerecord (3.2.13) lib/active_record/associations/collection_proxy.rb:86:in `method_missing'
请解释一下。 rails-2 和 rails-3 有什么问题
【问题讨论】:
-
您确定在您的
User模型中指定了:class_name => "Auction::Lot"吗?如果 Rails 试图“自动”找出关联类名称,您报告的错误正是您所看到的。 -
Urlwriter 不包含在 Rails-3 中。正确的方法是包含“include Rails.application.routes.url_helpers”..它对我有用...感谢所有贡献...
标签: ruby activerecord ruby-on-rails-3.2