我在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课程,但我无法弄清楚它与结果的关系。我已经对项目目录中的所有文件进行了搜索,搜索“OutcomeAnalyAsis”和“analyasis”,区分大小写和非区分大小写。它出现的唯一地方是来自这些错误的日志文件。
我知道这可能是在我的项目代码中的某个地方,但是有没有人对可能导致这种情况或我应该看的地方有任何建议?我正在尝试销毁所选的@outcome对象。使用params [:id]正确设置了@outcome对象的id。
如果有帮助,我可以发布更多代码段。提前谢谢!
答案 0 :(得分:2)
Dude看着你的代码似乎首先需要使用的是
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}