pwz*_*000 52 ruby-on-rails rails-models activemodel mailboxer
在我的应用程序; 当我提交表单时,我收到此错误:
LoadError at /questions
Unable to autoload constant Message, expected /app/models/message.rb to define it
Run Code Online (Sandbox Code Playgroud)
它指向控制器中的create动作Questions:
@message = current_user.messages.new(:subject => "You have a question from #{@question.sender_id}"`
Run Code Online (Sandbox Code Playgroud)
消息模型:
class Mailboxer::Message < ActiveRecord::Base
attr_accessible :notification_id, :receiver_id, :conversation_id
end
Run Code Online (Sandbox Code Playgroud)
kik*_*kik 100
按惯例,在rails中(这由自动加载器强制执行),文件路径应与命名空间匹配.
所以,如果你有一个Mailboxer::Message模型,它应该在app/models/mailboxer/message.rb.
此外,您可能在尝试加载Message类时启动了自动加载器(我的猜测是它发生在ActAsMessageable中).它message.rb在加载路径中查找文件,找到它app/model/并因此加载该文件以便它可以找到Message该类.
问题是,它没有Message在该文件中找到一个类,只有一个Mailboxer::Message类(它完全不同).这就是它抛出"无法自动加载常量消息,预期/app/models/message.rb来定义它"的原因.
要修复它,请创建目录app/models/mailboxer/并放入Mailboxer::Message其中.
| 归档时间: |
|
| 查看次数: |
57277 次 |
| 最近记录: |