Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.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 rubyonrails-Nokogiri-gem从xml导入订单并不完全有效。可能允许的周长_Ruby On Rails_Ruby_Xml_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails rubyonrails-Nokogiri-gem从xml导入订单并不完全有效。可能允许的周长

Ruby on rails rubyonrails-Nokogiri-gem从xml导入订单并不完全有效。可能允许的周长,ruby-on-rails,ruby,xml,ruby-on-rails-4,Ruby On Rails,Ruby,Xml,Ruby On Rails 4,我和Nokogiri有点麻烦 我不熟悉这种xml解析,似乎没有遇到任何错误。我收到订单了 这意味着它可能是允许的周长。如果我当时是对的,我可以创建一个模型,允许所有允许的周长。所以请看一看,谢谢您的时间,这是我的代码: Routes.rb resources :orders do collection { post :import } get "/confirm" => "confirmations#show" get 'dconfirmation' => 'orders

我和Nokogiri有点麻烦

我不熟悉这种xml解析,似乎没有遇到任何错误。我收到订单了

这意味着它可能是允许的周长。如果我当时是对的,我可以创建一个模型,允许所有允许的周长。所以请看一看,谢谢您的时间,这是我的代码:

Routes.rb

resources :orders do
  collection { post :import }
  get "/confirm" => "confirmations#show"
  get 'dconfirmation' => 'orders#confirmation'
end
模型


从你的问题中不清楚出了什么问题-你在模型中所做的只是创建一个nokogiri文档,还有一个注释。您希望发生什么?我正在尝试导入一个XML文档并对其进行词组化。理想情况下,我想在我的MSQL中保存字段。您的问题不清楚您是否无法打开文件,或者无法解析XML。我无法对文件进行短语分析。不过,正如我所说。它不会抛出控制台错误,因此很难回答您的问题。因为上面说文件导入了,我得到了nokogiri认证和文件翻译。你的问题不清楚出了什么问题-你在模型中所做的只是创建一个nokogiri文档,还有一个注释。您希望发生什么?我正在尝试导入一个XML文档并对其进行词组化。理想情况下,我想在我的MSQL中保存字段。您的问题不清楚您是否无法打开文件,或者无法解析XML。我无法对文件进行短语分析。不过,正如我所说。它不会抛出控制台错误,因此很难回答您的问题。因为上面说文件导入了,我得到了nokogiri认证和文件翻译。
class Order < ActiveRecord::Base
  belongs_to :user
  scope :not_completed_orders, -> {
    where(:complete => false)
  }
  require 'nokogiri'

 def self.import(file)
    doc = Nokogiri::XML.parse(file)
    #your processing code goes here
 end
end
class OrdersController < ApplicationController
  before_filter :authenticate_user!

  def new
    @order = Order.new
  end

  def create
    @order = current_user.orders.new(order_params)
    @order.email = current_user.email
    @order.name = current_user.name
    @order.address_line_1 = current_user.address_line_1
    @order.address_line_2 = current_user.address_line_2
    @order.postcode = current_user.postcode
    @order.city = current_user.city
    @order.country = current_user.country
    if @order.save
      redirect_to dconfirmation_path
    end
  end

  def order_params
    params.require(:order).
      permit(
        :email,
        :delivery_name,
        :company_name,
        :delivery_address1,
        :delivery_address2,
        :delivery_address3,
        :delivery_city,
        :delivery_postcode,
        :delivery_country,
        :phone,
        :package_contents,
        :description_content,
        :restricted_items,
        :terms_conditions,
        :insurance,
        :contents_value,
        :cf_reference,
        :reference_number,
        :service
        )
  end
  def show
    @user = User.find(params[:id])
  end

  def confirmation
  end

  def import
    Order.import(params[:file])
    redirect_to root_url, notice: "Order imported."
  end


end
  = form_tag import_orders_path, multipart: true do
    = file_field_tag :file
    = submit_tag "Import"