1
很想聽到別人對此的看法。我的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/[email protected]/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from /usr/local/rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from /usr/local/rvm/gems/[email protected]/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"
數據庫創建的信息表,雖然。在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
我能想到的唯一的事情就是「消息」模式在我使用的寶石或它們的依賴性的一個地方存在。但是,突然之間,它工作的很好,但事實並非如此。
下面是最近安裝的寶石:
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
如果有人碰到過這樣的或類似的東西我很想聽到你的情況是什麼。這些協會可能還有其他問題,但是這似乎不是我能說的問題。
'Message.class'和'Message.superclass'可能會幫助你找出它是否被另一部分Rails – muttonlamb
'Message.is_a?(ActiveRecord :: Base)'和'Message.class.methods.sort '也許會有幫助 – EnabrenTane
創建遷移後你運行了rake任務'migrate'嗎? (我知道不太可能,但如果) –