Tag: attr accessible

在Rails中,如何限制哪些属性可以更新,而不会阻止它们被创建?

我有一种情况,可以通过JSON API创建属性。 但是一旦它被创建,我想阻止它被更新。 这种约束导致我的第一个使用attr_accessible解决方案不够用。 有没有一种很好的方法来处理rails中的这种情况,或者我是否必须在update方法中执行手动检查?

请使用新建议的params保护模型(strong_parameters)或将`protected_attributes`添加到gemfile中

当我在我的Relationship模型中添加attr_accessible时就发生了这种情况。 class Relationship < ActiveRecord::Base attr_accessible :followed_id end 不使用Devise或protected_attributes gem,这有什么办法? 我知道在控制器中你调用一个需要和允许字段的私有方法。 这也是你应该在模型中做的事吗? 这里的约定是什么? 谢谢!

在同一个字段上使用attr_accessor和attr_accessible

使用以下代码在后台会发生什么? class User < ActiveRecord::Base attr_accessor :name attr_accessible :name end 提示:实例化类时,是否会持久化到数据库? 为什么或者为什么不?

rails Active Record中的attr_accessible

当我使用attr_accessible指定我的模型I中的哪些字段将公开时,脚本/控制台也是如此? 我的意思是我没有指定的东西因为attr_accessible也不能通过控制台访问?