我和Nokogiri有点麻烦。
我是这个xml解析的新手,我似乎没有错误。我得到订单导入警报。
这意味着可以允许周界。如果我是对的,我可以创建一个允许所有允许的周长的模型。所以请看一下,谢谢你的时间,这是我的代码:
的routes.rb
resources :orders do
collection { post :import }
get "/confirm" => "confirmations#show"
get 'dconfirmation' => 'orders#confirmation'
end
模型
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"