`

[转载]AJAX error: ActionView::TemplateError (undefined method `[]'..

阅读更多
Hi!
I got an error in my app, when Im adding a produt to my cart Im using some AJAX to first show the cart and then lighten up the new added product in the cart.
But when i add a new product to cart; I have to refresh my page so I can see the new product, because the AJAX doesnt work... It works on my development computer but not in the production server, maybe its something with the new Ruby version: 1.8.7.
Is this code correct?!
My add_to_cart.rjs:
page.select("div#notice").each { |div| div.hide }   <--- If cart is empty it doesnt show the cart
page.replace_html("cart", :partial => "cart",bject => @cart)
page[:cart].visual_effect :blind_down if @cart.total_items == 1
page[:current_item].visual_effect :highlight,
                                  :startcolor => "#8a9546",
                                  :endcolor => "#efeab0"

From the production.LOG
[code=]Processing StoreController#add_to_cart (for 83.254.103.73 at 2009-02-17 22:00:11) [POST]
  Session ID: BAh7CDoMY3NyZl9pZCIlYjY4Mzk0M2JlM2YyZTg3OWRlMzc4ZWU5ZDc5ZmUx%0AYmQ6CWNhcnRvOglDYXJ0BjoLQGl0ZW1zWwAiCmZsYXNoSUM6J0FjdGlvbkNv%0AbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA%3D--eb9fcfaa057def84ec7387692c8ff4084cfd8f7d
  Parameters: {"commit"=>"K
Last edited by depe86 (2009-02-18 14:03:38)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

At last I got the error fixed. I think I was trying for 24h
The problem is with the AJAX function "page.select"  when using Ruby 1.8.7...
Copy this code to the environment.rb.
  unless '1.9'.respond_to?(:force_encoding)
    String.class_eval do
      begin
        remove_method :chars
      rescue NameError
        # OK
      end
    end
  end
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics