Ruby on rails 未定义的方法“报告”配置文件&x27;对于#<;类别:0x0000109953940>;
正在重构一些我塞进控制器的代码,将其拉到模型中……但它不起作用,我不太明白为什么( 模型Ruby on rails 未定义的方法“报告”配置文件&x27;对于#<;类别:0x0000109953940>;,ruby-on-rails,ruby-on-rails-4,refactoring,Ruby On Rails,Ruby On Rails 4,Refactoring,正在重构一些我塞进控制器的代码,将其拉到模型中……但它不起作用,我不太明白为什么( 模型 您应该将该方法定义为类方法,而不是实例方法: def self.report_profile(reported_by, reported, reason) report = Reported.new report.reported = reported report.reported_by = reported_by report.reason = reason report.save
您应该将该方法定义为
类方法
,而不是实例方法
:
def self.report_profile(reported_by, reported, reason)
report = Reported.new
report.reported = reported
report.reported_by = reported_by
report.reason = reason
report.save
end
您应该将该方法定义为
类方法
,而不是实例方法
:
def self.report_profile(reported_by, reported, reason)
report = Reported.new
report.reported = reported
report.reported_by = reported_by
report.reason = reason
report.save
end
类方法需要使用
self
这应该行得通
def self.report_profile(reported_by, reported, reason)
report = Reported.new
report.reported = reported
report.reported_by = reported_by
report.reason = reason
report.save
end
类方法需要使用
self
这应该行得通
def self.report_profile(reported_by, reported, reason)
report = Reported.new
report.reported = reported
report.reported_by = reported_by
report.reason = reason
report.save
end
尝试
def self.report\u profile(报告人,报告人,原因)
Trydef self.report\u profile(报告人,报告人,原因)
Ahh…我应该知道得更好>。Ahh…我应该知道得更好>。
def self.report_profile(reported_by, reported, reason)
report = Reported.new
report.reported = reported
report.reported_by = reported_by
report.reason = reason
report.save
end