rails 3 uninitialized constant NameError when destroying an object

I'm getting an error in my Rails 3 app that I can't pinpoint the source of... When I try to destroy an object, I get the following:

NameError (uninitialized constant Outcome::OutcomeAnalyAsis): app/controllers/outcomes_controller.rb:141:in `destroy'
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.0ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (15.6ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (15.6ms)

This is the destroy function I have. The error is because of the line that says @outcome.destroy.

 def destroy
    @outcome = Outcome.find(params[:id])

    @outcome_tps = OutcomeTimepoint.where(:outcome_id => @outcome.id).all
    @outcome_subs = OutcomeSubgroup.where(:outcome_id => @outcome.id).all
    @outcome_columns = OutcomeColumn.where(:outcome_id => @outcome.id).all
    @outcome_column_vals = OutcomeColumnValue.where(:outcome_id => @outcome.id).all
    @outcome_results = OutcomeResult.where(:outcome_id => @outcome.id).all

    @outcome_tps.each {|i| i.destroy}
    @outcome_subs.each {|i| i.destroy}
    @outcome_columns.each {|i| i.destroy}
    @outcome_column_vals.each {|i| i.destroy}
    @outcome_results.each {|i| i.destroy}
    @outcome.destroy  #error happens on this line

    respond_to do |format|
        @outcomes = Outcome.find(:all, :conditions => {:study_id => session[:study_id]})
        @study_arms = Arm.find(:all, :conditions => {:study_id => session[:study_id]})    
        format.js {
          render :update do |page|
                page.replace_html 'outcomes_table', :partial => 'outcomes/table'
          end
        }
    end
  end

There is an OutcomeAnalysis class, but I can't figure out where it's tied to Outcome. I've done a search over all files in my project directory for "OutcomeAnalyAsis" and "analyasis" both case-sensitive and non. The only place it occurs is in the log file from these errors.

I know this is likely to be somewhere within my project code, but does anyone have any suggestions on what could be causing this, or where I should look? I'm trying to destroy the selected @outcome object. The id of the @outcome object is being set correctly with params[:id].

I can post more code segments if it would help. Thanks in advance!

Answers


Dude looking at your code seems that very first thing you need to use is

has_many :outcome_tps, :dependent => :destroy
has_many :outcome_subs, :dependent => :destroy

etc.... Once you this thing then let us know whats the problem.

it will remove your these lines of code

@outcome_tps = OutcomeTimepoint.where(:outcome_id => @outcome.id).all
@outcome_subs = OutcomeSubgroup.where(:outcome_id => @outcome.id).all
@outcome_columns = OutcomeColumn.where(:outcome_id => @outcome.id).all
@outcome_column_vals = OutcomeColumnValue.where(:outcome_id => @outcome.id).all
@outcome_results = OutcomeResult.where(:outcome_id => @outcome.id).all

@outcome_tps.each {|i| i.destroy}
@outcome_subs.each {|i| i.destroy}
@outcome_columns.each {|i| i.destroy}
@outcome_column_vals.each {|i| i.destroy}
@outcome_results.each {|i| i.destroy}

Need Your Help

Convert div data to a float and present it

javascript casting int

So what I tried to do is to get all my divs with class "value" that are in betreturns in my html document, these divs looks like this:

wrap divs within 2x2 table jquery

jquery wrap

I have four divs like below.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.