Player_controller
class PlayersController< ApplicationController中
def index
@players = Player.all
end
def show
@player = Player.find(params[:id])
end
def new
end
def create
@player = Player.new(player_params)
@player.save
redirect_to @player
end
private
def player_params
params.require(:player).permit(:name, :description)
end
端
我正在尝试显示存储在播放器模型中的数据,这是我的show.html
show.html
命名:
说明
实际播放器名称和说明不会显示在show动作上。尝试使用@players = Player.find(:all)
在控制台中进行调试时
,这是错误信息
SELECT "players".* FROM "players" WHERE "players"."id" = NULL LIMIT 1
ActiveRecord::RecordNotFound: Couldn't find Player with 'id'=all
答案 0 :(得分:1)
您在控制台中使用Player.find(:all)
- Find expects an id, a list of ids, or an array of ids。您可能想要使用Player.all
。