导轨5中attr_protected的替代物是什么?

问题描述 投票:0回答:1
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升级中的替代品应该是什么?

ruby-on-rails-5
1个回答
0
投票
Rails 5不允许进行大规模分配

不要在模型中使用attr_protected:person_id,而应使用强参数。您将在OreganosController中执行此操作:

def oregano_params params.require(:oregano).permit(:person_id) end

© www.soinside.com 2019 - 2024. All rights reserved.