ruby-on-rails-5 - rails 5 中 attr_protected 的替代品是什么?
问题描述
class Oregano < ApplicationRecord
attr_protected :person_id
end
这让我返回一个错误
/activerecord-5.0.5/lib/active_record/dynamic_matchers.rb:21:in `method_missing': undefined method `attr_protected' for #<Class:0x000055b38448bd58> (NoMethodError).
Rails 5升级中的替代品应该是什么?
解决方案
Rails 5 不允许质量分配
不要在模型中使用 attr_protected ,而是:person_id
使用强参数。您将在 OreganosController 中执行此操作:
def oregano_params
params.require(:oregano).permit(:person_id)
end
推荐阅读
- typescript - Typescript 界面和 Promise 返回问题
- android - 如何在 android 设备中录制内部音频 [root/no root]
- sql - 仅当值等于或大于 3,500 时求和?
- sql - 尝试在 VBA 中使用 ADODB 进行参数化查询时从错误消息中获取更多信息
- c# - 创建大于 150MB 的 ZIP 文件会引发 OutOfMemoryException C#
- flutter - Flutter:“bool”类型不是“double”类型的子类型
- flutter - 如何更改 Flutter 默认选项卡控制器中的选项卡?
- java - 数 N 年后的奶牛数量
- java - 有没有一种方法可以让我们使用嵌入式数据库来测试 Postgres Jsonb 查询以进行单元测试?
- scala - date_format 不处理带有“00:00:00”的时间戳