2017-07-11 32 views
0

如何在强参数中添加参数?如何在强参数中添加参数?

当对象被实例化时,我可以选择“类型”。 但我无法更新此“类型”。

我可以用参数做两种方法吗?例如: :

def custom_field_params 
    params.require(:custom_field).permit(:name, :required, :type_id, options_attributes: [:id, :name, :position, :_destroy]) 
end 

def update_custom_field_params 
    params.require(:custom_field).permit(:name, :required, options_attributes: [:id, :name, :position, :_destroy]) 
end 

我可以将这两种方法合并为一种方法吗?

回答

1

你可以使用custom_field_params原样,并在您update方法,这样做:

MyModel.update(custom_field_params.select { |k, _v| k != :type_id })