Hi,

I have tried 1.5 but I'm still seeing the issue.

Let me firstly say that I am a beginner at (J)Ruby / Rails /
Datamapper so quite possibly this is my own fault. :-)

What I'm trying to do is get a sample app to run on Google App Engine.
 When I try and add a new cartitem, the error appears in the console
and the product is always null.

I have models like this:

#cart.rb
class Cart
  include DataMapper::Resource

  property :id, Serial
  timestamps :at

  has n, :cartItems

  def add_product(product)
#      @cartItems = CartItem.all(:cart => self)
#    if current_item.nil?
#       self.cartItems.create(:product => product, :quantity => 1)
#       self.save
#    else
      #current_item.increment_quantity
      #current_item.save
      self.cartItems.create(:product => product, :quantity => 1)
#      self.save
#    end
  end

end

#cart_item.rb
class CartItem
  include DataMapper::Resource

  property :id, Serial
  property :quantity, Integer
  has 1, :product
  belongs_to :cart
  timestamps :at

end

#product.rb
class Product
  include DataMapper::Resource

  property :id,          Serial
  property :title,       String,        :required => true, :length => 500
  property :description, Text,          :required => true, :lazy => false
  property :image_url,   String,        :required => true, :length => 500
  property :price, BigDecimal, :scale => 2, :precision => 8
  timestamps :at

  belongs_to :cartItem

  validates_is_unique :title
  validates_with_method :price, :method => :price_must_be_at_least_a_cent
  validates_format :image_url,
    :with => %r{\.(gif|jpg|png)$}i,
    :message => 'must be a URL for GIF, JPG ' +   'or PNG image.'

  protected
    def price_must_be_at_least_a_cent
        if (is_a_number?(price) && price < BigDecimal.new("0.01"))
             [false, "Price must be at least 0.01" ]
        else
            return true
        end
    end

    def is_a_number?(s)
        s.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
    end

    def self.find_products_for_sale
        all(:order => [:title])
    end

end

And a controller that tries to add a new item to the cart like this:

  def add_to_cart
      product = Product.find(params[:id])
      @cart = find_cart
      @cart.add_product(product)
      @cart.save
  end

Sorry about all the commented out sections, but I've tried a lot of
combinations of things trying to get it working.

Can you or anyone else see anything obvious I'm doing wrong?

Many thanks for your help.

Regards,
Andrew.


On 3 May 2010 08:22, Andrew Myers <[email protected]> wrote:
> Hi Charles,
>
> Thanks - I was using 1.4.0 so I'll try upgrading.
>
> Regards,
> Andrew.
>
> On 3 May 2010 03:14, Charles Oliver Nutter <[email protected]> wrote:
>> This error should no longer happen in JRuby 1.5. The "bug" isn't
>> *gone* per se, but every case of this in the wild appeared to be
>> unaffected.
>>

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to