Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 更新Rails 4中的属性_Ruby On Rails_Ruby_Ruby On Rails 4_Strong Parameters - Fatal编程技术网

Ruby on rails 更新Rails 4中的属性

Ruby on rails 更新Rails 4中的属性,ruby-on-rails,ruby,ruby-on-rails-4,strong-parameters,Ruby On Rails,Ruby,Ruby On Rails 4,Strong Parameters,我正在寻找一些关于允许参数的澄清和更新记录 我知道白名单属性现在是在控制器中完成的,例如,我在控制器底部创建了一个provate方法 private def gallery_params params.require(:gallery).permit(:id, :title, :overview, :category_id, gallery_images_attributes: [:id, :gallery_id, :gallery_category_id, :photo, :_destro

我正在寻找一些关于允许参数的澄清和更新记录

我知道白名单属性现在是在控制器中完成的,例如,我在控制器底部创建了一个provate方法

private
def gallery_params
  params.require(:gallery).permit(:id, :title, :overview, :category_id, gallery_images_attributes: [:id, :gallery_id, :gallery_category_id, :photo, :_destroy])
end
如果我想在我的创建操作中访问这些属性,我可以这样传递它们

@gallery = Gallery.new(gallery_params)
然而,我有点纠结于如何通过我的更新方法允许相同的参数

def update
@gallery = Gallery.find(params[:id])
if @gallery.update_attributes(params[:gallery])
  redirect_to root_path, notice: 'Successfully updated Gallery'
else
  render action: 'edit'
end
end
我试过了

@gallery.update_attributes(params[:gallery].permit(gallery_params))
但这不起作用

谢谢你的帮助


谢谢

您只需使用您的
库参数
方法:

if @gallery.update(gallery_params)

您只需使用
gallery\u params
方法即可:

if @gallery.update(gallery_params)

单个属性不需要单独的权限,只需使用
gallery\u params

单个属性不需要单独的权限,只需使用
gallery\u params

谢谢,这很有效。。也很简单,我真傻,没有意识到谢谢,这很有效。。也很简单,愚蠢的我没有意识到