请参阅没有设计的相同应用程序示例:链接
我试过 git clone 它,当导入 excel 文件成功时。
我正在尝试设计注册从 excel 文件中获取电子邮件和密码,
这是imports_controller.rb
class ImportsController < Devise::RegistrationsController
before_filter :resource_name
def resource_name
:user
end
def import
end
def create
get_file = params[:excelfile]
file = ImportUploader.new
file.store!(get_file)
book = Spreadsheet.open "#{file.store_path}"
sheet = book.worksheet 0
@user = []
sheet.each 1 do |row|
u = User.new
u.email = row[0]
u.password = row[1]
u.save
@user << u
end
redirect_to root_path
end
import.html.erb
<%= form_tag import_path, multipart: true do %>
<%= file_field_tag :excelfile %>
<%= submit_tag "Import" %>
<% end %>
当我尝试导入 excel 文件时
Started POST "/import" for 127.0.0.1 at 2013-03-30 16:23:55 +0700
Processing by ImportsController#create as HTML
Parameters: {"utf8"=>"Γ£ô", "authenticity_token"=>"RavRmOt838/dMJ4eg1Kx4DYnWYF
TUBdqHnQIhcfkeug=", "excelfile"=>#<ActionDispatch::Http::UploadedFile:0x4e28980
@original_filename="kkryrk.xls", @content_type="application/vnd.ms-excel", @hea
ders="Content-Disposition: form-data; name=\"excelfile\"; filename=\"kkryrk.xls
\"\r\nContent-Type: application/vnd.ms-excel\r\n", @tempfile=#<File:C:/Users/mycomp/AppData/Local/Temp/RackMultipart20130330-5724-18krlm5>>, "commit"=>"Import"}
(1.0ms) BEGIN
Users Exists (2.0ms) SELECT 1 AS one FROM `users` WHERE `users`.`emai
l` = BINARY 'email@domain.com' LIMIT 1
(1.0ms) ROLLBACK
Completed 500 Internal Server Error in 441ms
我很困惑,因为我的应用程序没有错误,我不知道错误的位置以便回滚。
任何的想法?
谢谢。