Guest User

Untitled

a guest
Jul 19th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. ## production.log
  2. Processing ProductsController#admin_update (for 72.128.34.48 at 2009-12-07 23:48:36) [POST]
  3. Parameters: {"commit"=>"Update", "authenticity_token"=>"SYorMTYI6GiZm0MS/fRlR9GcfdKSJ6FLFb/zKpvgMGI=", "product"=>{"name"=>"Japanese Flag Buckle", "price"=>"11.99", "quantity"=>"3", "desc"=>"How much do we love Japan? Let us count the ways! Pay tribute to the country that brings us Anime, Ninjas, and Robots! Need we say more? How about the Earthquake Bed and the Cat Booty Dusters? OK, lets stick to the first three... Measures 3 ", "category_id"=>["27"], "item_number"=>"BKL2"}, "id"=>"21-japanese-flag-buckle"}
  4.  
  5. ActiveRecord::RecordInvalid (Validation failed: Category is not a number):
  6. app/controllers/products_controller.rb:86:in `admin_update'
  7. dispatch.fcgi:24
  8.  
  9. Rendering /home/klutch/shop/public/422.html (422 Unprocessable Entity)
  10.  
  11. ## products_controller.rb
  12. def admin_update
  13. @product = Product.find_by_id(params[:id])
  14. if(@product.update_attributes!(params[:product])) # <-- line 86
  15. @product.update_categories(params[:product][:category_id])
  16. redirect_to :action => 'admin_list'
  17. else
  18. render :xml => @product
  19. end
  20. end
  21.  
  22. ## product.rb
  23. def update_categories(category_ids)
  24. bridges = CategoryProduct.find(:all, :conditions => {:product_id => id})
  25. bridge_category_ids = []
  26. bridges.each do |bridge|
  27. bridge_category_ids.push(bridge.category_id)
  28. end
  29.  
  30. # Create bridges with ids from category_ids
  31. category_ids.each do |category_id|
  32. unless(bridge_category_ids.include?(category_id))
  33. bridge = CategoryProduct.new(:product_id => id, :category_id => category_id)
  34. bridge.save
  35. end
  36. end
  37.  
  38. # Remove bridges whose ids aren't listed in category_ids
  39. bridge_category_ids.each do |bridge_category_id|
  40. unless(category_ids.include?(bridge_category_id))
  41. bridge = CategoryProduct.find( :first,
  42. :conditions => {
  43. :product_id => id,
  44. :category_id => bridge_category_id})
  45. bridge.destroy
  46. end
  47. end
  48. end
Add Comment
Please, Sign In to add comment