开发者

uninitialized constant ActiveRecord::RecordNotUnique

I am using rails 2.3.4, rubygems 1.3.6, activerecord 3.1.0, windows 7 home basic

Here's my code:

def items
    @products = ShopifyAPI::Product.find(:all)
    @products.each do |a| 
    开发者_如何学Cbegin
    @shop = Product.new(:title => a.title , :shop_id => a.id, :product_type => a.product_type)
    @shop.save
        rescue ActiveRecord::RecordNotUnique
            redirect_to :action => "display_items"
        end
    end
    @shop_items =Product.find(:all)
    if session[:user_id]
            @log = "Welcome Administrator!"
            @logout="logout"
        else
            @log = "Admin Log in"
            @logout=""
        end

end

I'm having the error "uninitialized constant ActiveRecord::RecordNotUnique" when trying to save the data fed by the API. Any help would be appreciated. thank you.


Any reason why you use ActiveRecord 3.1 with Rails 2.3.4. Though it's possible to use that, it is not recommended.

ActiveRecord::RecordNotUnique is only available with versions 3.0 or higher. I am not sure if activerecord modules are initialized correctly with your version of Rails.


That error is returned when ActiveRecord tries to save a duplicate when the index says values need to be unique. In your case, the value Baby Ruth-49696852 is a duplication, and violates the uni_products key, which is set to be unique.

Either make the column not unique, or stop trying to save duplicate records. Did you create your database indexes in your migrations? Is there a :unique => true on any of the columns in your migrations?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜