Every time i delete or destroy a Product it aways give me this error in my console:
ActiveRecord::RecordNotFound (Couldn't find Product with ID=4):
app/controllers/products_controller.rb:16:in `show'
and on the page it gives:
ActiveRecord::RecordNotFound in ProductsController#show
Couldn't find Product with ID=4
In my Products Controller i just have the regular scaffold:
def show
@product = Product.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @product }
end
end
def destroy
@product = current_user.products.find(params[:id]) #current user deletes own
@product.destroy
respond_to do |format|
format.html { redirect_to(products_url) }
format.xml { head :ok }
end
end
I am using Rails Jquery UJS and rails-jquery and have the csrf_meta_tagin my app layout. What i have noticed is when i click the destroy link and it pops up the window and says “Are you Sure”, i click the OK button and it flickers TWICE for some strange reason, it never did this until i installed Jquery. How do i fix this?
EDIT – ANSWER:
Reinstall rails jquery-ujs > https://github.com/rails/jquery-ujs
You have to keep both files jquery.min.js and jquery.js. I deleted the jquery.min.js because i thought it was a minimized version but apparently not, here are all of my files from jquery-ujs:
jquery.js
jquery.min.js
jquery_ujs.js
rails.js # i had to install this manually from the link (or zip file)
jquery-ui # i wanted the user interface too
Make sure you have the
rails.jsfile injavascripts? When you move from prototype to jquery, the standard restfulDELETEdoesn’t work properly anymore. rails.js fixes that so it works normally again. You can refer to Josh Huckabee’s article here: http://joshhuckabee.com/jquery-rails-3. Hopefully that helps.PS: Also make sure you include
rails.jsin your layout. Something like this: