【问题标题】:Rails 5 how to retrieve strong parameters list (formerly accessible_attributes) from Model?Rails 5如何从模型中检索强参数列表(以前是accessible_attributes)?
【发布时间】:2016-09-05 19:46:05
【问题描述】:

我实现了#396 Importing CSV and Excel中描述的方法 在 Rails 4 中运行良好。

现在我想在 Rails 5 应用程序中做同样的事情。但是,看起来accessible_attributes 已被弃用,因为我在尝试使用它时收到Undefined method accessible_attributes for ...

现在如何智能检索强参数列表?

谢谢。

【问题讨论】:

    标签: ruby-on-rails activerecord strong-parameters


    【解决方案1】:

    您必须使用控制器进行白名单。

    def create
      @post = Post.new(post_params)
      ....
    end
    
    private
    
      post_params
        params.require(:post).permit(:body, :title)
      end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-05
      • 2016-04-29
      • 2011-10-21
      • 2017-05-11
      • 2017-03-29
      • 1970-01-01
      相关资源
      最近更新 更多