【发布时间】:2013-06-16 17:36:24
【问题描述】:
- 生成的没有 Active Record 的 Rails 应用程序
- 为 Mongoid(Mongodb 和 Mongoid)添加了适当的宝石
- 在 config/ 中生成了 mongoid.yml 文件,支持 rails
- 使用典型的 CRUD 路由创建朋友模型和用户控制器
一切正常,除了当我尝试做大量作业时,我得到:
"undefined method `attr_accesible' for Friend:Class"
模特、朋友.rb:
class Friend
include Mongoid::Document
field :first_name, :type => String
field :last_name, :type => String
field :adjective, :type => String
attr_accessible :first_name, :last_name, :adjective
end
development:
sessions:
default:
database: first_development
hosts:
- localhost:27017
options:
options:
test:
sessions:
default:
database: first_test
hosts:
- localhost:27017
options:
consistency: :strong
max_retries: 1
retry_interval: 0
想法?
【问题讨论】:
-
链接“paul-wong-jr.blogspot.com/2012/03/…”表示要在 attr_accessible 行下方添加 attr_accessor :accessible。原因是“#:accessible 是一个变量,用于存储游戏特定的动态字段,以便可以通过 attr_accessible 批量赋值来设置它们。这允许动态设置 attr_accessible。”
-
我也遇到了同样的问题。 @user1455116 的建议无效。你用的是哪个版本的 rails 和 mongoid?
标签: ruby-on-rails mongodb mongoid