Guest User

Untitled

a guest
Jul 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. Error is:
  2. NoMethodError in CollectionsController#update
  3.  
  4. You have a nil object when you didn't expect it!
  5. You might have expected an instance of Array.
  6. The error occurred while evaluating nil.push
  7. Rails.root: /home/john/Rails/testapp
  8.  
  9. Application Trace | Framework Trace | Full Trace
  10. app/controllers/collections_controller.rb:59:in `block in update'
  11. app/controllers/collections_controller.rb:58:in `update'
  12.  
  13.  
  14. class Collection
  15. references_and_referenced_in_many :products
  16. end
  17.  
  18. class Products
  19. references_and_referenced_in_many :collections
  20. end
  21.  
  22. class CollectionsController < ApplicationController
  23. # PUT /collections/1
  24. # PUT /collections/1.xml
  25. def update
  26. @collection = Collection.find(params[:id])
  27. respond_to do |format|
  28. if @collection.update_attributes(params[:collection])
  29. format.html { redirect_to(@collection, :notice => 'Collection was successfully updated.') }
  30. format.xml { head :ok }
  31. else
  32. format.html { render :action => "edit" }
  33. format.xml { render :xml => @collection.errors, :status => :unprocessable_entity }
  34. end
  35. end
  36. end
  37. end
  38.  
  39.  
  40. then the form:
  41. = form_for @collection do |f|
  42. - for product in @store.products
  43. #product[product]
  44. = check_box_tag "collection[products][]", product._id, @collection.products.include?(product)
  45. = product.name
  46. = f.submit "Update products"
  47.  
  48. if you set the file field to "collection[product_ids][]" it generates the same error too.
Add Comment
Please, Sign In to add comment