Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6616067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:32:18+00:00 2026-05-25T20:32:18+00:00

When I run ajax POST delete on my follows controller, for a record that

  • 0

When I run ajax POST delete on my follows controller, for a record that has already been deleted, rails raises error “undefined method `destroy’ for nil:NilClass”. But why does it still say that when I tried to render the response in a find_follow method preceding the destory call? Shouldn’t the execution stop inside find_follow?

class FollowsController < ApplicationController


 def find_follow
   begin
     @follow = current_artist.follows.find(params[:id])
     raise "Record Not Found" if @follow.nil? 
   rescue => e
      respond_to do |format|
        format.html { redirect_to(artist_follows_path(current_artist),:notice => "#{e}") }
        format.js { render :text => "#{e}", :status => :not_found}
        format.json {render :json => "#{e}", :status => 400}
      end
      return false
    end
  end


  def destroy
    find_follow
    if (@follow.destroy)
       # respond_to html, js, json...

    end

  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:32:18+00:00Added an answer on May 25, 2026 at 8:32 pm

    Your find_follow returns nil which is fine but as you are calling destroy method you need to write return in destroy method only

    Try

    def destroy
        return find_follow
    

    You can also use before_filter something like following

    class FollowsController < ApplicationController
     before_filter :find_follow, :only=>[:destroy]
    
     def find_follow
         @follow = current_artist.follows.find_by_id(params[:id])
         if @follow.nil? 
            redirect_to(artist_follows_path(current_artist),:notice => "#{e}")
         else
          return true
        end
      end
    
    
      def destroy
        if (@follow.destroy)
           # respond_to html, js, json...
    
        end
    
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to run function inside web service (.asmx file) $.ajax({ type: POST, contentType:
I am doing a simple $.ajax request: $.ajax({ type: POST, url: /Run/ + param1
When I run an ajax request of type POST, the parameters are not included
I currently have a Rails website that has some Prototype scripting in it. My
Imagine I run this: $.ajax({ type: 'POST', url: '/ajax/watch.php', data: {'watch':'aukcia', 'id':aukciaID}, complete: function(responseText){
I'm trying to run .ajax and insert a data element from the onClick of
The Problem I am trying to run some ajax on one my pages for
I tried to run 2 JQuery-ajax at the same time, but it's seem always
On document ready I run this code: jQuery(document).ready(function(){ jQuery('#button').click(function() { jQuery('#contact_form').load(/Users/mge/Downloads/jquery-ajax-1/readme.txt); return false; });
Hey guys, I am trying to run a proccess by submitting an AJAX form:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.