Rails 4未经许可的参数:产品(Rails 4 Unpermitted parameters: products)
我需要将一个数组保存到我的
order.rb
模型中。数组是:
params[:products]
数组给我这样的东西:
[{"'name'"=>"31 DVIE33N - Traditional ", "'id'"=>"2", "'quantity'"=>"1", "'accessory'"=>{"'id'"=>"7", "'name'"=>"31-SK4BLANKD-2"}}]
创建动作:
def create @order = Order.new(order_params) respond_to do |format| if @order.save format.html { redirect_to admin_orders_path(@order), notice: 'Order was successfully created.' } format.json { render :show, status: :created, location: @order } else format.html { render :new } format.json { render json: @order.errors, status: :unprocessable_entity } end end end
我的订单有限。
private def order_params params.permit({:products=>[], products:[]) end
我正在尝试两种不同的方式来产品,这就是为什么你会看到上面的两个数组
请看一下,我没有使用像这样的东西:
params.require(:order).permit(:products => []}, :products=>[])
因为如果我使用它我得到错误:
ActionController::ParameterMissing - param is missing or the value is empty: order:
谢谢。
I need to save an array into my
order.rb
model.The array is:
params[:products]
The array is giving me something like this:
[{"'name'"=>"31 DVIE33N - Traditional ", "'id'"=>"2", "'quantity'"=>"1", "'accessory'"=>{"'id'"=>"7", "'name'"=>"31-SK4BLANKD-2"}}]
Create action:
def create @order = Order.new(order_params) respond_to do |format| if @order.save format.html { redirect_to admin_orders_path(@order), notice: 'Order was successfully created.' } format.json { render :show, status: :created, location: @order } else format.html { render :new } format.json { render json: @order.errors, status: :unprocessable_entity } end end end
My orders params.
private def order_params params.permit({:products=>[], products:[]) end
I'm trying two different ways to permite products, that why you will see two arrays above
Please take a look, I'm not using somethig like:
params.require(:order).permit(:products => []}, :products=>[])
because if I use that I get the error:
ActionController::ParameterMissing - param is missing or the value is empty: order:
Thank you.
原文:https://stackoverflow.com/questions/37714476
最满意答案
最强大的解决方案是从头开始重写整个文件。 大多数操作系统只会让你从文件中覆盖字节,而不是插入或删除它们,所以为了达到这个目的,你必须复制文件,在拷贝过程中替换目标字节。
The most robust solution is to re-write the whole file, from scratch. Most operating systems will only let you overwrite bytes, not insert or remove them, from a file, so to accomplish that, you have to essentially copy the file, replacing the target bytes during the copy.
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
覆盖在文件的中间(overwrite in the middle of a File)[2023-03-11]
最强大的解决方案是从头开始重写整个文件。 大多数操作系统只会让你从文件中覆盖字节,而不是插入或删除它们,所以为了达到这个目的,你必须复制文件,在拷贝过程中替换目标字节。 The most robust solution is to re-write the whole file, from scratch. Most operating systems will only let you overwrite bytes, not insert or remove them, from a file, so ... -
文件覆盖在python中(file overwrite in python)[2023-10-19]
你正在使用-O (大写O)选项,它将所有内容连接到1个文件。 '-O file'' - output-document = file' 文档不会写入相应的文件,但所有文件将连接在一起并写入文件。 如果' - '用作文件,文档将打印到标准输出,禁用链接转换。 (使用'./-'打印到一个名为' - '的文件。)使用'-O'并不意味着简单地“使用名称文件而不是URL中的文件;”而是类似的shell重定向: wget -O file http://foo工作方式类似于wget -O - http://foo > f ... -
如何覆盖C文件?(How to overwrite a file in C?)[2022-03-29]
你决定在fopen 。 只需使用"w"或"w+"而不是"r+" 。 You decide that in fopen. Just use "w" or "w+" instead of "r+". -
覆盖文件内容。(Overwrite file contents. Batch File)[2024-01-02]
Would suggest to use either xcopy or robocopy for Overwriting folders Xcopy /E /Y会覆盖文件夹, 请找更多选项Xcopy /? 请注意,我提到这个选项只是为了覆盖而不是移动文件夹。 Would suggest to use either xcopy or robocopy for Overwriting folders Xcopy /E /Y would Overwrite folder , please find More ... -
强制覆盖文件(Force overwrite file)[2021-09-13]
这不可能。 Yeoman将在覆盖文件之前始终要求用户进行确认。 这是该工具与其用户签订的合同:它不会在没有确认的情况下覆盖文件。 作为用户,如果您信任您的生成器,则可以使用--force标志运行它以自动覆盖冲突的文件。 This is not possible. Yeoman will always ask the user for confirmation before overwriting a file. This is a contract the tool takes with its users ... -
覆盖文件或附加(Overwrite File or Append)[2022-07-11]
您想检查文件是否存在并调整文件名(如果已经存在)。 像这样的东西应该工作: import os from datetime import datetime datestring = datetime.strftime(datetime.now(), '%Y_%m_%d') filename = 'filediff_' + datestring + '.txt' filenb = 1 while os.path.exists(filename): filenb += 1 filename = ... -
一种方法是将整个文件读入单个字符串,创建一个新的字符串,替换前30个字符并重写整个文件。 这可以这样做: with open("text.txt", "r") as f: data = f.read() new_thirty_characters = '
' new_data = new_thirty_characters + data[30:] with open("text.txt", "w") as f: f.write(new_data) ... -
用fortran覆盖文件(overwrite a file using fortran)[2023-03-29]
回到顺序访问文件是棘手的,因为行可能会有所不同。 如果你改变了一行的长度,你就必须把所有的东西放在后面。 我推荐的是在计算行数时将输出写入临时文件。 然后,一旦完成,倒回暂存文件,将行数写入输出文件,然后将暂存文件的内容复制到该输出文件。 这是我做的: program var_file implicit none character(len=*), parameter :: filename = 'delme.dat' integer :: n, io_stat charac ...