I'm a rails beginner and trying to put some code in the model. The code below is an illustration.
View:
Player_stats: <%= @player.player_pass_completion_ratio %>
Model:
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
I get an undefined method "cmethod" when I try to call the code from the view. Any advice is greatly appreciated.
lefthandstatsandrighthandstatsin an array called Hands. But, since this is the first line in the method, these two variables havn't been defined so they are nil.