ruby-1.9

write csv in ruby 1.9 and CSV::Writer

核能气质少年 提交于 2019-11-27 12:20:00
问题 i have a code that works fine with ruby 1.87 but dont works with ruby 1.9. It says that CSV::Writer is undeclared but it still part of the rdoc. Does the csv api changed, after the fastercsv merge, or not? my code: require 'csv' def self.export_csv file_name = File.join(RAILS_ROOT, 'public','csv',"#{start_date_f}_#{end_date_f}.csv") return file_name if File.exist?(file_name) @results = find(:all) header_row = [] outfile = File.open(file_name, 'wb') CSV::Writer.generate(outfile) do |csv|

Can I set the default string encoding on Ruby 1.9?

为君一笑 提交于 2019-11-27 11:18:33
问题 This might sound minor, but it's been driving me nuts. Since releasing an application to production last Friday on Ruby 1.9, I've been having lots of minor exceptions related to character encodings. Almost all of it is some variation on: Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8 We have an international user base so plenty of names contain umlauts, etc. If I fix the templates to use force_encoding in a bunch of places, it pops up in the flash message

Rails 3 invalid multibyte char (US-ASCII)

*爱你&永不变心* 提交于 2019-11-27 11:07:48
I found a similar post here but I can't solve the problem anyway. I got this /home/fra/siti/Pensiero/db/seeds.rb:32: invalid multibyte char (US-ASCII) /home/fra/siti/Pensiero/db/seeds.rb:32: invalid multibyte char (US-ASCII) /home/fra/siti/Pensiero/db/seeds.rb:32: syntax error, unexpected $end, expecting ')' ... ed il valore della vita, si è malati", :user_id => 1, :cat... The problem is into this string :body => "Nel momento in cui ci si chiede il significato ed il valore della vita, si è malati" I got the problme with every "e" charachter with the accent like "è é " I tried to put magic

Set global default encoding for ruby 1.9

萝らか妹 提交于 2019-11-27 04:51:37
I want to tell ruby that everything is utf8, except when stated otherwise, so I dont have to place these # encoding: utf-8 comments everywhere. You can either: set your RUBYOPT environment variable to "-E utf-8" or use https://github.com/m-ryan/magic_encoding If you're using environment variables, the general way is to use LC_ALL / LANG Neither is set : fallback to US-ASCII $ LC_ALL= LANG= ruby -e 'p Encoding.default_external' #<Encoding:US-ASCII> Either is set : that value is used $ LC_ALL=en_US.UTF-8 LANG= ruby -e 'p Encoding.default_external' #<Encoding:UTF-8> $ LC_ALL= LANG=en_US.UTF-8

Has anyone successfully deployed a Rails project with Ruby 1.9.1? [closed]

限于喜欢 提交于 2019-11-27 02:50:08
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Last week I successfully completed the transition of all our company applications from Ruby 1.8.6 to Ruby 1.8.7 including local and

HTML tidy/cleaning in Ruby 1.9

淺唱寂寞╮ 提交于 2019-11-27 02:03:33
问题 I'm currently using the RubyTidy Ruby bindings for HTML tidy to make sure HTML I receive is well-formed. Currently this library is the only thing holding me back from getting a Rails application on Ruby 1.9. Are there any alternative libraries out there that will tidy up chunks of HTML on Ruby 1.9? 回答1: http://github.com/libc/tidy_ffi/blob/master/README.rdoc works with ruby 1.9 (latest version) If you are working on windows, you need to set the library_path eg require 'tidy_ffi' TidyFFI

Why does Ruby 1.9.2 blow up with a JSON gem dependency?

我的未来我决定 提交于 2019-11-27 01:54:43
问题 I am having issues with the JSON gem and Ruby 1.9.2. I am upgrading to Rails 3.0.3 and whenever I try to boot the environment it blows up. This is from a empty test project with only JSON gem 1.4.6 as a dependency. /Users/lee/.rvm/gems/ruby-1.9.2-p0/gems/json-1.4.6/lib/json/common.rb:66: [BUG] unknown type 0x22 (0xc given) ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0] -- control frame ---------- c:0032 p:---- s:0096 b:0096 l:000095 d:000095 CFUNC :initialize c:0031 p:---- s

What's the difference between Object and BasicObject in Ruby?

只谈情不闲聊 提交于 2019-11-26 23:00:17
问题 What's the difference between these classes? What's the difference between their purposes? 回答1: BasicObject was introduced in Ruby 1.9 and it is a parent of Object (thus BasicObject is the parent class of all classes in Ruby). BasicObject has almost no methods on itself: ::new #! #!= #== #__id__ #__send__ #equal? #instance_eval #instance_exec BasicObject can be used for creating object hierarchies independent of Ruby's object hierarchy, proxy objects like the Delegator class, or other uses

String#encode not fixing “invalid byte sequence in UTF-8” error

橙三吉。 提交于 2019-11-26 22:59:48
问题 I know there are multiple similar questions about this error, and I've tried many of them without luck. The problem I'm having involves the byte \xA1 and is throwing ArgumentError: invalid byte sequence in UTF-8 I've tried the following with no success: "\xA1".encode('UTF-8', :undef => :replace, :invalid => :replace, :replace => "").sub('', '') "\xA1".encode('UTF-8', :undef => :replace, :invalid => :replace, :replace => "").force_encoding('UTF-8').sub('', '') "\xA1".encode('UTF-8', :undef =>

Ruby 1.9 hash with a dash in a key

戏子无情 提交于 2019-11-26 22:56:41
问题 In ruby 1.9 is there a way to define this hash with the new syntax? irb> { a: 2 } => {:a=>2} irb> { a-b: 2 } SyntaxError: (irb):5: syntax error, unexpected tLABEL { a-b: 2 } ^ with the old one, it's working: irb> { :"a-b" => 2 } => {:"a-b"=>2} 回答1: You also can use next syntax {a: 1, b: 2, 'c-c': 3, d: 4} 回答2: There are some legitimate symbols that cannot be used with the new syntax. I cannot find a reference, but it appears that a symbol name matching /^[a-zA-Z_][a-zA-Z_0-9]*[!?]?$/ is