control not entering format.html block

27 views Asked by At

My controller method is like:

def forcefully_logout
  process_license_pool_obj = Vendor::ProcessLicensePool.new(@user.vendor)
  @user.authentication_token = ''
  if @user.save
    if process_license_pool_obj.update_license_pool?(false, @user.id.to_s, @user.vendor_id.to_s)
      respond_to do |format|
        format.html do
          redirect_to license_management_vendor_url(@user.vendor_id), notice: 'User was successfully logged-out and license has been released.'
        end and return
      end
    end
  end
  respond_to do |format|
    format.html { redirect_to license_management_vendor_url(@user.vendor_id), warn: 'Unable to forcefully logout user, contact admin.' }
  end
end  

and the route for this method is as:-

resources :users, except: [:create] do
  member { delete 'forcefully_logout', to: 'users#forcefully_logout' }
end  

Although the method is working properly, but it gives error for "missing template" and the controll doesn't enters the 'format.html' block means instead of redirecting the method tries to render template. In server log the message for this request is something as "started delete and processing by this method as html" (since the request is also of html type) but redirect_to is not hit. What is the possible reason for this problem is this rails issue or am i missing some concept regarding request object. The request is of "delete" type. Thanks.

1

There are 1 answers

0
codemilan On

Actually the "and return" statement after "format.html" block was causing the flow not to enter 'format.html' block, the working code is as:

def forcefully_logout
  process_license_pool_obj = Vendor::ProcessLicensePool.new(@user.vendor)
  @user.authentication_token = ''
  if @user.save
    if process_license_pool_obj.update_license_pool?(false, @user.id.to_s, @user.vendor_id.to_s)
      respond_to do |format|
        format.html do
          redirect_to license_management_vendor_url(@user.vendor_id), notice: 'User was successfully logged-out and license has been released.' and return
        end
      end
    end
  end
  respond_to do |format|
    format.html { redirect_to license_management_vendor_url(@user.vendor_id), warn: 'Unable to forcefully logout user, contact admin.' }
  end
end