我是一名 Rails 初学者,并试图在模型中添加一些代码。下面的代码是一个插图。
看法:
Player_stats: <%= @player.player_pass_completion_ratio %>
模型:
class Player < ActiveRecord::Base
has_many :lefthandstats
has_many :righthandstats
def player_pass_completion_ratio
Hands = [ lefthandstats, righthandstats] #These are objects & calling @player.lefthandstats.find_with_passes directly generally works
if self.category == "Hands"
total_usual_passes = 500
Hands.each do |cmethod|
if self.cmethod.find_with_passes(:passes, :first, {:conditions => 'passes>200' }) then accuratestats += 1 end
end
end
accuracy = (accuratestats/total_usual_passes)*100
end
当我尝试从视图调用代码时,我得到一个未定义的方法“cmethod”。任何意见是极大的赞赏。