2013-10-23 75 views
0

我试图调试我的日志与以下行轨道:的Ruby on LoadError

<%= debug $pvp_user.pvp_death_logs %> 

我收到的错误:

无法自动加载不断PvpDeathLog,预计在/ var/WWW /导轨/ ourapp /应用/模型/ pvp_death_log.rb来定义它

型号/ pvp_user.rb

class Pvp_user < ActiveRecord::Base 
    has_many :pvp_death_logs 
end 

型号/ pvp_death_log.rb

class Pvp_death_log < ActiveRecord::Base 
    belongs_to :pvp_user 
end 

控制器/ player_controller.rb

class PlayerController < ApplicationController 
    def index 
    end 

    def show 
    user = Mc_user.find_by username: params[:id] 
    if !user 
     flash[:status] = FALSE 
     flash[:alert] = 'we couldn\'t find that user.' 
    else 
     pvp_user = Pvp_user.find_by username: params[:id] 
     if !pvp_user 
      flash[:status_pvp] = FALSE 
      flash[:alert_pvp] = 'No player vs player profile found.' 
     else 
      flash[:status_pvp] = TRUE 
      $pvp_user = pvp_user 
     end 

     flash[:status] = TRUE 
     $user = user 
    end 
    end 
end 

的意见/播放/ show.html.erb

<%= debug $pvp_user.pvp_death_logs %> 

Mysql数据库:pvp_users http://i.imgur.com/9LViwVG.png

Mysql数据库:pvp_death_log http://i.imgur.com/A9WfPu4.png

+2

我看到一些可能导致问题的非styleguide/convention事物。首先,模型是camelCase,没有强调。秒,你滥用'闪光'一点。第三,使用全局变量'$ user'而不是实例变量('@ user')的原因是什么? – pduersteler

+1

谢谢,我改变了你说的话。我还必须在表名的末尾添加's'。现在它可以工作。 – Mike

+0

Rails有很多“魔术发生在这里”的技巧,你只需要习惯。但是,一旦你了解了它们,使用起来非常简单。 – Kevin

回答

2

你的班的命名是用Ruby标准不一致。类和模块名称应该在CamelCase中:

class PvpUser 
    # (...) 
end 

class PvpDeathLog 
    # (...) 
end 
+0

我已经改变了这一点。 – Mike