redirect route after destroy doesn't work

Hi Ruby Community,

after destroying a record, ruby (2.2) don't use the registerd redirect in the controller:

             format.html { redirect_to(tbl_akte_tbl_beteiligtes_url) }

Everytime after deleting ruby uses the show-action, and because the record is now deleted ruby couldn't find it again and throws an error message:

  app/controllers/tbl_beteiligtes_controller.rb:23:in `show'

I checked via rake routes the routing, and normaly the route "tbl_akte_tbl_beteiligtes_url" should use the index-action.

Everthing else like edit, create etc. works fine.

Do somebody knows a solution?

Thanks ahead for every recommendation.



Can you post the entire controller so we have some context of the surrounding code? Might be easier to debug what is going on. Do you have a functional test for it?

Cheers, Nicholas

Hi Nicholas,

thanks for your answer.

Unfortunately i have no functional test, but here is my entire controller:

class TblBeteiligtesController < ApplicationController

   before_filter :find_people

  # GET /tbl_beteiligtes   # GET /tbl_beteiligtes.xml   def index

    tbl_akte = TblAkte.find(params[:tbl_akte_id])     @tbl_beteiligtes = tbl_akte.tbl_beteiligtes.find(:all)

    respond_to do |format|       format.html # index.html.erb       format.xml { render :xml => @tbl_beteiligtes }     end   end

  # GET /tbl_beteiligtes/1   # GET /tbl_beteiligtes/1.xml   def show     @tbl_beteiligte = TblBeteiligte.find(params[:id])

    respond_to do |format|       format.html # show.html.erb       format.xml { render :xml => @tbl_beteiligte }     end   end

  # GET /tbl_beteiligtes/new   # GET /tbl_beteiligtes/new.xml   def new     @tbl_beteiligte =

    respond_to do |format|       format.html # new.html.erb       format.xml { render :xml => @tbl_beteiligte }     end   end

  # GET /tbl_beteiligtes/1/edit   def edit     @tbl_beteiligte = TblBeteiligte.find(params[:id])   end

  # POST /tbl_beteiligtes   # POST /tbl_beteiligtes.xml   def create     @tbl_beteiligte =[:tbl_beteiligte])

    @tbl_beteiligte.tbl_akte = TblAkte.find(params[:tbl_akte_id])

    respond_to do |format|       if         flash[:notice] = 'TblBeteiligte was successfully created.'

        format.html { redirect_to(tbl_akte_tbl_beteiligte_url(@tbl_akte, @tbl_beteiligte)) }         format.xml { render :xml => @tbl_beteiligte, :status => :created, :location => @tbl_beteiligte }       else         format.html { render :action => "new" }         format.xml { render :xml => @tbl_beteiligte.errors, :status => :unprocessable_entity }       end     end   end

  # PUT /tbl_beteiligtes/1   # PUT /tbl_beteiligtes/1.xml   def update     @tbl_beteiligte = TblBeteiligte.find(params[:i d])

    respond_to do |format|       if @tbl_beteiligte.update_attributes(params[:tbl_beteiligte])         flash[:notice] = 'TblBeteiligte was successfully updated.'

        #format.html { redirect_to(@tbl_beteiligte) }

        format.html { redirect_to(tbl_akte_tbl_beteiligtes_url) }         format.xml { head :ok }       else         format.html { render :action => "edit" }         format.xml { render :xml => @tbl_beteiligte.errors, :status => :unprocessable_entity }       end     end   end

  # DELETE /tbl_beteiligtes/1   # DELETE /tbl_beteiligtes/1.xml   def destroy     @tbl_beteiligte = TblBeteiligte.find(params[:id])     @tbl_beteiligte.destroy

    respond_to do |format|

      #format.html { redirect_to(tbl_beteiligtes_url) }

      format.html { redirect_to(tbl_akte_tbl_beteiligtes_url) }       format.xml { head :ok }     end   end

  protected   def find_people

    @tbl_akte = TblAkte.find_by_id(params[:tbl_akte_id])     @navigation = 'Akten'   end end

Nothing that stands out here (to me), would you mind posting your routes file.

Cheers, Nicholas

It seems like you are confusing singular and plural names here. I tried using german model names, too. Believe me, sooner or later rails will come and get you :confused: just stick to english names. You can use inflections, but it really is a pain especially when singular and plural are the same. Greetings

Hi Nicholas, Hi Mike,

it wasn't a ROR-Issue it was a damned javascript-Problem which triggered the show-action after the deletion.

Maybe I will find something that will stop the javascript show request after deletion.

Thank you very mutch!!