首页 \ 问答 \ Rails 4未经许可的参数:产品(Rails 4 Unpermitted parameters: products)

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
更新时间:2023-06-05 11:06

最满意答案

最强大的解决方案是从头开始重写整个文件。 大多数操作系统只会让你从文件中覆盖字节,而不是插入或删除它们,所以为了达到这个目的,你必须复制文件,在拷贝过程中替换目标字节。


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.

相关问答

更多
  • 最强大的解决方案是从头开始重写整个文件。 大多数操作系统只会让你从文件中覆盖字节,而不是插入或删除它们,所以为了达到这个目的,你必须复制文件,在拷贝过程中替换目标字节。 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 ...
  • 你正在使用-O (大写O)选项,它将所有内容连接到1个文件。 '-O file'' - output-document = file' 文档不会写入相应的文件,但所有文件将连接在一起并写入文件。 如果' - '用作文件,文档将打印到标准输出,禁用链接转换。 (使用'./-'打印到一个名为' - '的文件。)使用'-O'并不意味着简单地“使用名称文件而不是URL中的文件;”而是类似的shell重定向: wget -O file http://foo工作方式类似于wget -O - http://foo > f ...
  • 你决定在fopen 。 只需使用"w"或"w+"而不是"r+" 。 You decide that in fopen. Just use "w" or "w+" instead of "r+".
  • 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 ...
  • 这不可能。 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 ...
  • 您想检查文件是否存在并调整文件名(如果已经存在)。 像这样的东西应该工作: 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) ...
  • 回到顺序访问文件是棘手的,因为行可能会有所不同。 如果你改变了一行的长度,你就必须把所有的东西放在后面。 我推荐的是在计算行数时将输出写入临时文件。 然后,一旦完成,倒回暂存文件,将行数写入输出文件,然后将暂存文件的内容复制到该输出文件。 这是我做的: program var_file implicit none character(len=*), parameter :: filename = 'delme.dat' integer :: n, io_stat charac ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)