I have been charged with resurrecting a rails 2.3.5 app and was told
not to do any tool upgrades.

At the end of our environment.rb we load our products into our
ProductCatalog like so
ProductCatalog.load

This then populates the array in the ProductCatalog module which looks
like so
module ProductCatalog

@@products = []

def ProductCatalog.load_prod_cat
@@products = Product.find(:all, :order => "desc")
end

def ProductCatalog.get_product(prod_id, prod_vers_id)
@@products.find do |prod|
prod.prod_id.eql?(prod_id) and prod.prod_vers_id.eql?
(prod_vers_id)
end
end
end

calling get product works perfectly and finds the correct product
based on prod_id and prod_vers_id (composit_primary_keys is being used
for this on the model).

The problem arises in the template when we try to iterate over the
array of products we pass in (array is populated via individual calls
to ProductCatalog.get_product) and we try to traverse the
has_many :pricing_structures association.

At this point a method_missing error gets thrown.

This error only occurs in development mode and has me completely
dumbfounded. Our work around is to develop in production mode but
that's a pain because we have to restart the server everytime which is
a lengthy process due to setup that occurs via calls to a webservice.

Any help would be fantastic

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Matt Jones at Oct 2, 2011 at 2:19 pm

    On Sep 22, 4:27 pm, kwb wrote:
    I have been charged with resurrecting a rails 2.3.5 app and was told
    not to do any tool upgrades.

    At the end of our environment.rb we load our products into our
    ProductCatalog like so
    ProductCatalog.load

    This then populates the array in the ProductCatalog module which looks
    like so
    module ProductCatalog

    @@products = []

    def ProductCatalog.load_prod_cat
    @@products = Product.find(:all, :order => "desc")
    end

    def ProductCatalog.get_product(prod_id, prod_vers_id)
    @@products.find do |prod|
    prod.prod_id.eql?(prod_id) and prod.prod_vers_id.eql?
    (prod_vers_id)
    F**king databases, how do they work?
    end
    end
    end

    calling get product works perfectly and finds the correct product
    based on prod_id and prod_vers_id (composit_primary_keys is being used
    for this on the model).

    The problem arises in the template when we try to iterate over the
    array of products we pass in (array is populated via individual calls
    to ProductCatalog.get_product) and we try to traverse the
    has_many :pricing_structures association.

    At this point a method_missing error gets thrown.

    This error only occurs in development mode and has me completely
    dumbfounded. Our work around is to develop in production mode but
    that's a pain because we have to restart the server everytime which is
    a lengthy process due to setup that occurs via calls to a webservice.

    Any help would be fantastic
    Quit? Seriously - this is unbelievably bad code, and I have to believe
    that it's only the tip of the proverbial iceberg.

    If *that's* not an option, the least you could do is replace the code
    with a real database lookup:

    def ProductCatalog.load_prod_cat
    end

    def ProductCatalog.get_product(prod_id, prod_vers_id)
    Product.find(prod_id, prod_vers_id)
    end

    which should (if you've got composite_primary_keys set up correctly)
    do exactly the same thing without causing problems in development mode
    AND without pulling the entire database of products into memory...

    The underlying issue (I suspect) is that the array gets cached with
    the initial version of the Product class, but subsequent reloads in
    development mode redefine the Product constant but the "cached"
    version doesn't change. This tends to cause weird stuff to happen.

    --Matt Jones

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedOct 1, '11 at 2:32p
activeOct 2, '11 at 2:19p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Kwb: 1 post Matt Jones: 1 post

People

Translate

site design / logo © 2021 Grokbase