2012-12-21 80 views
0

我使用的是RailsAdmin,这是我在RailsAdmin中点击我的模型CategoryProduct时得到的错误Heroku --ActionView :: Template :: Error(PG :: Error:错误:列category_products.desc不存在

这是错误的样子:

Started GET "/admin/category_product" for 67.230.41.62 at 2012-12-21 23:20:07 +0000 
2012-12-21T23:20:07+00:00 app[web.1]: 
2012-12-21T23:20:07+00:00 app[web.1]: ActionView::Template::Error (PG::Error: ERROR: column category_products.desc does not exist 
2012-12-21T23:20:07+00:00 app[web.1]: LINE 1: ...ry_products".* FROM "category_products" ORDER BY category_p... 
2012-12-21T23:20:07+00:00 app[web.1]:               ^
2012-12-21T23:20:07+00:00 app[web.1]: : SELECT "category_products".* FROM "category_products" ORDER BY category_products. desc LIMIT 20 OFFSET 0): 
2012-12-21T23:20:07+00:00 app[web.1]:  120:  %tbody 
2012-12-21T23:20:07+00:00 app[web.1]:  121:   - @objects.each do |object| 
2012-12-21T23:20:07+00:00 app[web.1]:  122:   %tr 
2012-12-21T23:20:07+00:00 app[web.1]:  123:    %td 
2012-12-21T23:20:07+00:00 app[web.1]:  124:    = check_box_tag "bulk_ids[]", object.id, false 
2012-12-21T23:20:07+00:00 app[web.1]:  125:    - if @other_left_link ||= other_left && index_path(params.except('set').merge(params[:set].to_i != 1 ? {:set => (params[:set].to_i - 1)} : {})) 
2012-12-21T23:20:07+00:00 app[web.1]:  126:    %td.other.left= link_to "...", @other_left_link, :class => 'pjax'^ 

这些都是我categoryproduct & category_product型号:

Category.rb

# == Schema Information 
# 
# Table name: categories 
# 
# id   :integer   not null, primary key 
# name  :string(255) 
# created_at :datetime   not null 
# updated_at :datetime   not null 
# 

class Category < ActiveRecord::Base 
    attr_accessible :name 
    has_many :category_products do 
     def with_products 
      includes(:product) 
     end 
     end 

    has_many :products, :through => :category_products 

    def top_products(number) 
    category_products.with_products.order("purchases_count DESC").limit(number).map {|c| c.product} # product included 
    end 

end 

Product.rb

# == Schema Information 
# 
# Table name: products 
# 
# id   :integer   not null, primary key 
# name  :string(255) 
# description :string(255) 
# price  :float 
# vendor_id :integer 
# created_at :datetime   not null 
# updated_at :datetime   not null 
# image  :string(255) 
# 

class Product < ActiveRecord::Base 
    attr_accessible :name, :description, :price, :vendor_id, :image, :category_ids 
    mount_uploader :image, ImageUploader 

    belongs_to :vendor 
    has_many :category_products do 
      def with_categories 
      includes(:category) 
      end 
    end 

    has_many :categories, :through => :category_products 

    def top_categories(number) 
    category_products.with_categories.order("purchases_count DESC").limit(number).map {|c| c.category} # category included 
    end 

end 

Category_Product

# == Schema Information 
# 
# Table name: category_products 
# 
# id    :integer   not null, primary key 
# product_id  :integer 
# category_id  :integer 
# purchases_count :integer   default(0) 
# created_at  :datetime   not null 
# updated_at  :datetime   not null 
# 

class CategoryProduct < ActiveRecord::Base 
    attr_accessible :product_id, :category_id, :purchases_count 

    belongs_to :product 
    belongs_to :category 

    validates_uniqueness_of :product_id, :scope => :category_id 
end 

任何想法可能会导致什么呢?

谢谢。

+0

你确定用category_product主键迁移了heroku db吗? RailsAdmin再次怀念id:“ORDER BY category_products。desc”必须是“ORDER BY category_products.id desc” –

+0

是的......我确实。当我检查Heroku控制台中的CategoryProduct模型时,我看到:CategoryProduct => CategoryProduct(id:integer,product_id:integer,category_id:integer,purchases_count:integer,created_at:datetime,updated_at:datetime) ' – marcamillion

+0

顺便说一句,我该如何解决该查询?不太确定如何更改该查询....或者如果我应该。 – marcamillion

回答

0

原来问题出在Heroku身边(我假设)。

我对代码库做了另一次不同的更新,这个问题似乎消失了。

+0

我知道它,我知道它,我知道它) –

+4

以及那不是在heroku方面的问题...我有什么经验是数据库获取更新,但应用程序仍然不知道数据库更改所以应该使用heroku重新启动后运行迁移。 – Gull

+0

Hrmm .....伟大的建议。下次我会尽力记住这一点。 – marcamillion

相关问题