【问题标题】:Naming conflict in rails with "Account" modelRails 中的命名冲突与“帐户”模型
【发布时间】:2014-11-19 20:02:07
【问题描述】:

我有一个模型Account 位于/app/models/account.rb 下:

class Account < ActiveRecord::Base
end

当我现在请求控制器时,我得到 undefined method all for Account:Module

class AccountsController < ApplicationController
  def index
    @accounts = Account.all
  end
end

我尝试将模型重命名为 Accounte,这确实有效。但是,我看到很多使用 Account 模型的 Rails 教程,而且真的很难找到其他名称。

如何找到并禁用帐户模块以清除此命名冲突?

我可以通过rails console 访问 Account

【问题讨论】:

  • 我假设你自己的代码库中没有一个名为 Account 的模块,你的 Gemfile 中有什么宝石
  • 您是否有任何可以添加Account 模块的宝石?
  • 另外,try this,它可能会帮助您找出另一个 Account 模块的定义位置。
  • @UriAgassi 我有rails~4.1.8mysql2~0.3.17spring
  • 啊,我刚刚发现我最初运行的是rails new account,所以config/application.rb 定义了module Account

标签: ruby-on-rails ruby


【解决方案1】:

问题是我使用了rails new account,它在config/application.rb 中创建了一个模块Account。这导致了命名问题。

【讨论】:

    猜你喜欢
    • 2012-09-10
    • 1970-01-01
    • 2015-05-03
    • 2017-05-21
    • 2010-12-16
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    相关资源
    最近更新 更多