簡體   English   中英

Ruby on rails LoadError

[英]Ruby on rails LoadError

我正在嘗試使用以下行調試我的日志:

<%= debug $pvp_user.pvp_death_logs %>

我收到的錯誤:

無法自動加載常量PvpDeathLog,預期/var/www/rails/ourapp/app/models/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

您的類命名與Ruby標准不一致。 類和模塊名稱應該在CamelCase中:

class PvpUser
  # (...)
end

class PvpDeathLog
  # (...)
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM