很想听听有人对此的看法。我的 rails 应用程序已连接到开发数据库,我的所有模型都可以正常工作,除了一个。就应用程序而言,“消息”模型不存在,即使表已创建并且可以在 schema.rb 文件中看到。有没有人遇到过这个?我已经检查了我所有模型文件名的拼写,所以除非我完全没有注意到,否则我认为不是这样。该模型如下所示:
class Message < ActiveRecord::Base
has_paper_trail
attr_accessible :content, :prescription, :type, :to, :sent_at, :created_at, :updated_at
has_many :adherences
has_many :patients, :through => :adherences
validates :content, presence: true, length: { maximum: 160 }
accepts_nested_attributes_for :patients
end
Rails 控制台输出什么也不显示:
1.9.3-p194 :001 > Message.all
NoMethodError: undefined method `all' for Message:Class
from (irb):1
from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
1.9.3-p194 :004 > Message.inspect
"Message"
db 虽然创建了 Messages 表。schema.rb(缩写):
ActiveRecord::Schema.define(:version => 20130613020005) do
create_table "messages", :force => true do |t|
t.string "content"
t.string "type"
t.string "prescription"
t.string "to"
t.datetime "sent_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
我唯一能想到的是“消息”模型存在于我正在使用的其中一个 gem 或其依赖项中的某个位置。但它之前工作正常,然后突然之间,不是。
以下是最近安装的 gem:
group :development, :test do
gem 'sms-spec'
gem 'rb-fsevent', '0.9.1', :require => false
gem 'growl', '1.0.3'
gem 'better_errors'
gem 'meta_request'
gem 'binding_of_caller'
gem 'guard-spork', '1.2.0'
gem 'childprocess', '0.3.6'
gem 'spork', '0.9.2'
gem 'shoulda-matchers'
end
如果有人遇到过这个或类似的事情,我很想听听你的情况。关联可能还有其他问题等等,但据我所知,这似乎不是问题。