我目前正在尝试自学 Ruby on Rails。我设置了一个新应用程序并启动并运行它,然后我创建了一个新类 -Player
并将其保存在app > models
目录中(根据我所阅读的内容,它是从这里自动加载的):
播放器.rb
class Player
@@players = {}
def initialise(name, rating=50)
@name = name
@rating = rating
@@players[name] = rating
end
def getName()
return @name
end
end
index_controller_rb
class IndexController < ApplicationController
def index
player1 = Player.new("Martin", 90)
end
end
index.html.erb
<h1>Test</h1>
<%= player1.getName() %>
我得到的错误是
wrong number of arguments(2 for 0)