'redirect_to' taking infinite loop.

Hi,

The following controller method taking me into infinite loop. Once the
update action completes I want to reload the 'index' page. May I know
why it is going into infinite loop?

def update
        Device.find_by_id( params[:device_id] ).driver = (
params[:driver_id] == 0 ) ? nil : Driver.find_by_id( params[:driver_id]
)

     redirect_to :action => :index, :tab => 'limo'
  end

Thanks,
Ajit

Hello, Ajit,

First of all params incoming with the requests are strings. You expect it to be Fixnum (0), rather than a String (‘0’). params[:anything] cannot be == 0, because if it is “zero”, it will be received as “0” in the controller. Just use this in the conditional and report with whether it succeeded or is still failing, in which case I’d ask you to provide INDEX action of the same controller, and before filters that affect Devices#index action (replaced 0 with ‘0’):

def update
Device.find_by_id( params[:device_id] ).driver = (
params[:driver_id] == ‘0’ ) ? nil : Driver.find_by_id( params[:driver_id]
)

Hi,

The following controller method taking me into infinite loop. Once the
update action completes I want to reload the 'index' page. May I know
why it is going into infinite loop?

def update
        Device.find_by_id( params[:device_id] ).driver = (
params[:driver_id] == 0 ) ? nil : Driver.find_by_id( params[:driver_id]
)

     redirect_to :action => :index, :tab => 'limo'
  end

Not an answer to the problem but you do not seem to be saving anything
in the update action, which is a bit unusual.

Colin