Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## production.log
- Processing ProductsController#admin_update (for 72.128.34.48 at 2009-12-07 23:48:36) [POST]
- 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"}
- ActiveRecord::RecordInvalid (Validation failed: Category is not a number):
- app/controllers/products_controller.rb:86:in `admin_update'
- dispatch.fcgi:24
- Rendering /home/klutch/shop/public/422.html (422 Unprocessable Entity)
- ## products_controller.rb
- def admin_update
- @product = Product.find_by_id(params[:id])
- if(@product.update_attributes!(params[:product])) # <-- line 86
- @product.update_categories(params[:product][:category_id])
- redirect_to :action => 'admin_list'
- else
- render :xml => @product
- end
- end
- ## product.rb
- def update_categories(category_ids)
- bridges = CategoryProduct.find(:all, :conditions => {:product_id => id})
- bridge_category_ids = []
- bridges.each do |bridge|
- bridge_category_ids.push(bridge.category_id)
- end
- # Create bridges with ids from category_ids
- category_ids.each do |category_id|
- unless(bridge_category_ids.include?(category_id))
- bridge = CategoryProduct.new(:product_id => id, :category_id => category_id)
- bridge.save
- end
- end
- # Remove bridges whose ids aren't listed in category_ids
- bridge_category_ids.each do |bridge_category_id|
- unless(category_ids.include?(bridge_category_id))
- bridge = CategoryProduct.find( :first,
- :conditions => {
- :product_id => id,
- :category_id => bridge_category_id})
- bridge.destroy
- end
- end
- end
Add Comment
Please, Sign In to add comment