Rails 5 如何从模型中检索强参数列表(以前是accessible_attributes)?
Rails 5 how to retrieve strong parameters list (formerly accessible_attributes) from Model?
我实现了#396 Importing CSV and Excel中描述的方法
在 Rails 4.
中运行良好
现在我想在 Rails 5 应用程序中执行相同的操作。但是,看起来 accessible_attributes 已被弃用,因为我在尝试使用它时得到 Undefined method accessible_attributes for ...
。
现在如何智能获取强参数列表?
谢谢。
你得用控制器来白名单。
def create
@post = Post.new(post_params)
....
end
private
post_params
params.require(:post).permit(:body, :title)
end
我实现了#396 Importing CSV and Excel中描述的方法 在 Rails 4.
中运行良好现在我想在 Rails 5 应用程序中执行相同的操作。但是,看起来 accessible_attributes 已被弃用,因为我在尝试使用它时得到 Undefined method accessible_attributes for ...
。
现在如何智能获取强参数列表?
谢谢。
你得用控制器来白名单。
def create
@post = Post.new(post_params)
....
end
private
post_params
params.require(:post).permit(:body, :title)
end