ActiveRecord :: RecordNotFound:无法找到带有' id' =全部的玩家

时间:2015-05-10 18:37:59

标签: ruby-on-rails ruby-on-rails-4

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

1 个答案:

答案 0 :(得分:1)

您在控制台中使用Player.find(:all) - Find expects an id, a list of ids, or an array of ids。您可能想要使用Player.all