Tag: ruby on rails 4

从excel链接到rails服务器运行devise不能正常工作

(轨4,ruby2.0,为OSX 14.5 excel,但在Windows Excel中检测到相同的问题)我有一个链接在Excel中,看起来像: https://www.example.com/reports/download_frame/1481 当用户点击excel时,他们会被路由到默认主页。 当他们剪切和粘贴到浏览器相同的url,它工作正常,他们直接进入页面。 在Apache上,这是日志的样子: – – – [14/Jun/2015:15:41:44 -0400] "OPTIONS /reports/download_frame/ HTTP/1.1" 404 1564 "-" "Microsoft Office Protocol Discovery" – – – – [14/Jun/2015:15:41:45 -0400] "GET /reports/download_frame/1481 HTTP/1.1" 302 106 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X) Excel/14.50.0" – – – – [14/Jun/2015:15:41:45 -0400] "GET /users/sign_in HTTP/1.1" 200 4148 "-" "Mozilla/5.0 […]

OpenDocument电子表格在Microsoft Excel中损坏

我正在使用一个gem写入一个OpenDocument电子表格( RSpreadsheet )一旦数据写入,我让用户下载它。 电子表格在Mac版OpenOffice Calc和Numbers中正常工作。 但是,当我尝试在Microsoft Excel中打开电子表格时,它告诉我电子表格已损坏。 这只发生在我写数据的时候。 我可以通过Ruby打开它,保存它,它会正常工作。 一旦我写入数据,它就会变坏。 我已经尝试了另一个gem( Rubiod ),并能够在Excel中打开电子表格,但只有在Excel必须“恢复”电子表格后才能打开。 这样做,它删除了公式和一些格式。 OpenOffice和Numbers更糟,尽pipe它保留了公式。 我需要用户能够下载这个电子表格,他们select哪个程序。 我不知道为什么Excel说这张纸是腐败的,而且试图把我的头包裹好几个小时。 电子表格保存为ODS扩展名,并使用MIMEtypes的application/x-vnd.oasis.opendocument.spreadsheet和一个字符集utf-8 例子: original = Rspreadsheet.open 'blank.ods' sheet = original.worksheets 1 sheet.A1 = 'FooBar' # Without this, Excel can open the spreadsheet fine original.save 'new.ods' respond_to do |format| format.all do send_data File.read('new.ods'), type: 'application/x-vnd.oasis.opendocument.spreadsheet; charset=utf-8; header=present' disposition: 'attachment; filename=new.ods' […]

回形针xls和xlsx的内容types

用回形针内容types挣扎,需要上传xls / xlsx文件。 has_attached_file :sheet validates_attachment_content_type :sheet, content_type: [ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel', 'application/xls', 'application/xlsx', 'application/octet-stream' ], message: ' Only EXCEL files are allowed.' 注:从谷歌驱动器创build一个工作表。 以上内容types我尝试过,但每次都有同样的错误 产量 Command :: file -b –mime '/var/folders/zy/khy_wsfn7jbd40bsdps7qwqc0000gt/T/5a76e813d6a0a40548b91acc11557bd220160328-13642-1meqjap.xlsx' (0.2ms) BEGIN Command :: file -b –mime '/var/folders/zy/khy_wsfn7jbd40bsdps7qwqc0000gt/T/5a76e813d6a0a40548b91acc11557bd220160328-13642-114d8t6.xlsx' (0.3ms) ROLLBACK {:sheet_content_type=>[" Only EXCEL files are allowed."], :sheet=>[" Only EXCEL files are allowed."]}

无法获得唯一性validation工作在我正在上传的Excel文件

我的客户端模式有两个属性:: :name和:address (这是我们客户网站的url)。 这个应用程序的重点在于查看一个公司是否在呼叫列表或客户端上,然后拨打电话进行查找,以便用户可以input他们的url,看他们是否可以打电话。 我正在使用Ruby 2.3.1和Rails 4.2.6 我有一个唯一性validation以及:addressvalidation设置:address ,但是当我导入一个xlxs文件时,客户端地址已经在数据库中,它仍然上传它们,只是覆盖原来的条目。 同时,如果我不包含地址,则在线validation确实起作用。 如果我以标准Client#newforms逐一添加公司,那么唯一性validation确实起作用。 只是没有与卓越。 我使用这里find的方法: http : //railscasts.com/episodes/396-importing-csv-and-excel?autoplay= true和在这里: https : //github.com/railscasts/396-importing-csv -and-的Excel /树/主/存储与-validation 我正在使用client_import模型和控制器来尝试做这个工作。 这是我的客户端模型:client.rb class Client < ActiveRecord::Base #attr_accessible :name, :address validates :address, uniqueness: { case_sensitive: false}, presence: true def self.search(q) where("name LIKE ?", "%#{q}%") where("address LIKE ?", "%#{q}%") end def self.import(file) spreadsheet = open_spreadsheet(file) […]

如何在ruby / rails中编辑.xslm文件而不丢失VBAmacros?

我在我的项目中有一些.xslm文件,我必须编辑。 我的应用程序是用Rails编写的。 我知道macros启用的文件不能用rubyXL或roo gem编辑,不知何故,我必须使用Ruby / Rails的gem或任何可以合并到Rails应用程序中的工具来编辑它们。 该应用程序托pipe在AWS上,是否有任何工具可以做同样的事情? 另外要求是保留macros。

从应用程序导轨下载xls文件4

我正在使用rails 4应用程序,在我的应用程序公用文件夹中有一个xls文件,并且在点击该链接后,xls文件应该下载到system.no中,并且在视图页面中有一个链接,不需要在该文件中写入任何内容,默认模板。 我用: 视图: <%= link_to "Dowload Template", admin_job_templates_path, :file_name => 'Job_Upload_Template.xlsx' %> 控制器: def index require 'open-uri' file_path = "#{Rails.root}/public/Job_Upload_Template.xlsx" send_file file_path, :filename => "Job_Upload_Template.xlsx", :disposition => 'attachment' end 也尝试了send_data方法 def index require 'open-uri' url = "#{Rails.root}/public/Job_Upload_Template.xlsx" data = open(url).read send_data data, :filename =>'Job Template' end 我得到以下错误。 没有这样的文件或目录@ rb_sysopen – /home/amp/workspace/LA_Tracker/public/Job_Upload_Template.xlsx 我无法下载文件,Plese帮助。

用excel文件内容初始化对象并保存到数据库

我觉得我正在服用疯狂的药丸,但是我刚刚撞到了一堵砖墙,不能再对此进行破解了。 答案似乎很简单,但我的头脑麻木,我无法突破这堵墙。 我正在使用Roo gem来导入excel文档(xls格式)并将其推送到数组中。 我结束了arrays的数组。 很简单,这工作正常。 所以然后我尝试并采取该数组的值,并将其分配给对象的属性。 这个技巧似乎是对行进行迭代,将数组赋值给适当的对象属性,保存,然后移动到下一行。 我确定我正在做的是各种各样的垃圾,但是我被卡住了,想不到一个解决办法。 这是我的控制器: class PlanesController < ApplicationController def new @plane = Plane.new @plane.upload end end 这是我的模特: require 'roo' class Plane < ActiveRecord::Base attr_accessor :id, :name, :version def upload arr = [] sheet1 = Roo::Spreadsheet.open('lib/assets/test.xls') sheet1.each { |hash| arr<<hash} i = 0 while i < arr.length do @id = […]

未定义的方法send_data

在电子表格中创build多个选项卡时,我得到了未定义的方法send_data 。 我无法理解使用send_Data方法发送的数据。 这是我的错误: NoMethodError (undefined method `send_data' for #<Class:0x007f911933cc58>): book = Spreadsheet::Workbook.new sheet1 = book.create_worksheet :name => 'Sheet1' sheet2 = book.create_worksheet :name => 'Sheet2' sheet1.row(0).push "some content in Column1" spreadsheet = StringIO.new book.write spreadsheet file = "#{Rails.root}/public/brand_store/Excelsheet" send_data spreadsheet.string, :filename => "#{file}", :type => "application/vnd.ms-excel"

Ruby on Rails:validationCSV文件

关于导入CSV( http://railscasts.com/episodes/396-importing-csv-and-excel )的RailsCast,我试图validation上传的文件是一个CSV文件。 我已经使用了gem csv_validator来做到这一点,正如这里所logging的那样https://github.com/mattfordham/csv_validator 所以我的模型看起来像这样: class Contact < ActiveRecord::Base belongs_to :user attr_accessor :my_csv_file validates :my_csv_file, :csv => true def self.to_csv(options = {}) CSV.generate(options) do |csv| csv << column_names all.each do |contact| csv << contact.attributes.values_at(*column_names) end end end def self.import(file, user) allowed_attributes = ["firstname","surname","email","user_id","created_at","updated_at", "title"] CSV.foreach(file.path, headers: true) do |row| contact = find_by_email_and_user_id(row["email"], user) || […]

如何在电子表格中使用自定义颜色?

我需要使用自定义color和pattern_fg_color( HEX :0x00adb1, RGB :0,173,177)。 我从这里得到的build议,但它没有为我工作(我在另一个基于电子表格gem的库中使用它): Spreadsheet::Excel::Internals::SEDOC_ROLOC.update(enterprise: 0x00adb1) Spreadsheet::Column.singleton_class::COLORS << :enterprise testing例子: Spreadsheet::Format.new(pattern_fg_color: :enterprise) 我得到以下错误: 未知颜色“企业” 任何build议,将不胜感激。