【问题标题】:Rails NoMethodError when calling a model method from a controller从控制器调用模型方法时 Rails NoMethodError
【发布时间】:2023-03-14 21:05:01
【问题描述】:

我想从我的控制器调用一个方法并收到 NoMethodError: undefined method `combine_table_lines' for Data:Class

我是 Rails 新手,如果这是非常基本的内容,我深表歉意。

控制器:data_controller.rb

class DataController < ApplicationController

  def abetReport
     @slos = Answer.joins(knowledge_topic: :student_learning_outcomes).select( 
             'student_learning_outcomes.title', :is_correct, "count(answers.id) AS  
              total_answers").group('student_learning_outcomes.id', :is_correct)
     @slos_combined = Data.combine_table_lines(@slos) 


  end
end

模型:data.rb

class Data

  def self.combine_table_lines(data)
     #body of method 
  end # end method

end

提前感谢您的帮助。

【问题讨论】:

    标签: ruby-on-rails nomethoderror


    【解决方案1】:

    Data是保留字:

    http://www.rubymagic.org/posts/ruby-and-rails-reserved-words

    您是否尝试过重命名课程?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多