Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 rails 3销毁对象时发生未初始化常量名称错误_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 3 rails 3销毁对象时发生未初始化常量名称错误

Ruby on rails 3 rails 3销毁对象时发生未初始化常量名称错误,ruby-on-rails-3,Ruby On Rails 3,我在我的Rails 3应用程序中遇到一个错误,我无法确定错误的来源。。。当我试图销毁一个对象时,我会得到以下结果: 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_d

我在我的Rails 3应用程序中遇到一个错误,我无法确定错误的来源。。。当我试图销毁一个对象时,我会得到以下结果:

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)
这是我的销毁功能。该错误是由于显示@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
有一门结果分析课,但我不知道它和结果有什么关系。我已经在我的项目目录中的所有文件中搜索了“outcomeanalysis”和“analysis”,区分大小写和非大小写。它发生的唯一位置是这些错误的日志文件中

我知道这可能在我的项目代码中的某个地方,但是有人对造成这种情况的原因有什么建议吗,或者我应该去哪里寻找?我正在尝试销毁选定的@output对象。正在使用params[:id]正确设置@outcome对象的id


如果有帮助的话,我可以发布更多的代码段。提前谢谢

伙计,看看你的代码,你首先要做的就是

has_many :outcome_tps, :dependent => :destroy
has_many :outcome_subs, :dependent => :destroy
等等。。。。 一旦你知道这件事,然后让我们知道是什么问题

它将删除您的这些代码行

@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}

尝试删除中间代码以进行调试..我们在您发布此消息时找到了正确答案。。。结果是OutcomeAnalysis设置为:dependent=>:destroy,但没有创建OutcomeAnalysis对象(这些记录是手动创建的)。你说得对,销毁函数中的所有代码都是无关的-哎呀!打字错误是另一个悬而未决的谜,但错误已经修复。非常感谢。