I have created a grid with the wice_grid gem and I am trying to add a delete button on every entry.
My html is the following:
<%= grid(@business_grid) do |g|
g.column name: 'ID' do |business|
business.id
end
g.column name: 'Title' do |business|
business.title
end
g.column name: 'Description' do |business|
business.description
end
g.column name: 'PlayStore URL' do |business|
business.playstore_url
end
g.column name: 'AppStore URL' do |business|
business.appstore_url
end
g.column do |business|
link_to "Delete", {:controller=>"businesses", :action=>"delete_business",:business=>business.id}
end
end -%>
Any in my controller:
class BusinessesController < ApplicationController
def create
@business = Business.new(:title => params[:title], :description => params[:description],
:playstore_url => params[:playstore_url], :appstore_url => params[:appstore_url])
if @business.save
render json: { status: 'success' }
else
render json: { status: 'error', errors: @business.errors.full_messages }
end
end
def destroy
@business = Business.find(params[:id])
@business.destroy
respond_to do |format|
format.html { render :partial => 'businessPartial'}
format.xml { head :ok }
end
end
end
The delete function actually works, it does indeed delete the item, but then I get an ActionController Exception saying that the object can't be found
It seems to me like I delete it and then search for it again, but I don't understand why. Here's a screenshot of what I get when I click on the Delete link. When I refresh the item is gone, which means that the delete function works.
I tried searching but I found nothing so specific. Any help appreciated.
Edit My development.log file after only pressing the delete button:
Started DELETE "/businesses/44" for 127.0.0.1 at 2016-04-15 11:33:34 +0300 [1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT
schema_migrations
.* FROMschema_migrations
[0m Processing by BusinessesController#destroy as JS Parameters: {"id"=>"44"} [1m[35mBusiness Load (0.4ms)[0m SELECTbusinesses
.* FROMbusinesses
WHEREbusinesses
.id
= 44 LIMIT 1 [1m[36m (0.1ms)[0m [1mBEGIN[0m [1m[35mSQL (0.5ms)[0m DELETE FROMbusinesses
WHEREbusinesses
.id
= 44 [1m[36m (10.1ms)[0m [1mCOMMIT[0m Redirected to http://localhost:3000admin_users/dashboard Completed 302 Found in 49ms (ActiveRecord: 12.6ms)Started DELETE "/businesses/44" for 127.0.0.1 at 2016-04-15 11:33:34 +0300 Processing by BusinessesController#destroy as JS Parameters: {"id"=>"44"} [1m[35mBusiness Load (0.3ms)[0m SELECT
businesses
.* FROMbusinesses
WHEREbusinesses
.id
= 44 LIMIT 1 Completed 404 Not Found in 16ms (ActiveRecord: 0.3ms)ActiveRecord::RecordNotFound (Couldn't find Business with 'id'=44):
app/controllers/businesses_controller.rb:19:in `destroy'Rendered /var/lib/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_source.erb (3.9ms) Rendered /var/lib/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb (0.7ms) Rendered /var/lib/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb (0.9ms) Rendered /var/lib/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb (19.1ms)
I initalize the @business_gird in the controller of my view (called dashboard)
def dashboard
@substore_grid = initialize_grid(Substore)
@business_grid = initialize_grid(Business)
@user_grid = initialize_grid(User)
end
rake routes screenshot:
My guess is that your 'businessPartial' partial is trying to use your @business
variable which got deleted
format.html { render :partial => 'businessPartial'}
Do you get the error when you remove this line?