[英]Why won't rails recognize my model?
很想聽聽某人對此的看法。 我的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"
數據庫雖然創建了消息表。 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之一或其依賴項中的某處。 但是突然之間,它運轉良好,不是。
這是最近安裝的寶石:
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
如果有人遇到過這種情況或類似情況,我很想聽聽您的情況。 關聯可能還有其他問題,但據我所知,這似乎並不是問題。
據我所知, growl
寶石中有一個相互矛盾的“消息”方法。 我將需要找到解決方法或刪除該gem。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.