ruby-1.9

Rails not using correct version of Ruby

喜你入骨 提交于 2019-12-09 09:15:22
问题 New information This is what happens with rails console : Loading development environment (Rails 3.1.1) ruby-1.9.2-p290 :001 > RUBY_VERSION => "1.8.7" There's something really weird going on here - the prompt says 1.9.2 but RUBY_VERSION shows 1.8.7 . I'm using RVM, but I'm having problems with Rails on Ubuntu. $ which ruby /home/nick/.rvm/rubies/ruby-1.9.2-p290/bin/ruby $rvm list rvm rubies => ruby-1.9.2-p290 [ i686 ] But if I do gem env I get RubyGems Environment: - RUBYGEMS VERSION: 1.8.11

Append row to csv file Ruby 1.9 CSV lib

我只是一个虾纸丫 提交于 2019-12-09 07:41:18
问题 Using Ruby 1.9 and CSV lib, I can't seem to append a row. The example in the documentation opens the file, and overwrites the row. What is the correct way to append rows to the document? Example from documentation: require 'csv' CSV.open("path/to/file.csv", "wb") do |csv| csv << ["row", "of", "CSV", "data"] csv << ["another", "row"] # ... end 回答1: I think you can change the open to use ab : CSV.open("t.csv", "ab") do |csv| 回答2: I will usually use the following to write to a csv file (Or any

incompatible character encodings: ASCII-8BIT and UTF-8 in Ruby 1.9

蓝咒 提交于 2019-12-07 01:03:01
问题 I'm getting the following error with my Ruby 1.9 & Rails 2.3.4. This happens when user submits a non-ASCII standard character. I read a lot of online resources but none seems to have a solution that worked. I tried using (as some resources suggested) string.force_encoding('utf-8') but it didn't help. Any ideas how to resolve this? Is there a way to eliminate such characters before saving to the DB? Or, is a there a way to make them show? 回答1: I don't know much about Ruby (or Rails), but I

Ensure orphaned processes are killed when the parent process dies

橙三吉。 提交于 2019-12-06 12:05:34
问题 In Ruby, how do I ensure that child processes spawned from my program don't keep running when my main process exits or is killed? Initially I thought I could just use at_exit in the main process, but that won't work if my main process gets kill -9 ed or calls Kernel.exec . I need a solution that is (basically) foolproof, and cross-platform. 回答1: If you have to handle kill -9 termination for your parent app, then you have only a couple of choices that I can see: Create a work queue manager and

Access STDIN of child process without capturing STDOUT or STDERR

孤者浪人 提交于 2019-12-06 07:39:09
问题 In Ruby, is it possible to prevent the standard input of a spawned child process from being attached to the terminal without having to capture the STDOUT or STDERR of that same process? Backticks and x-strings ( `...` , %x{...} ) don't work because they capture STDIN. Kernel#system doesn't work because it leaves STDIN attached to the terminal (which intercepts signals like ^C and prevents them from reaching my program, which is what I'm trying to avoid). Open3 doesn't work because its methods

Why do I get a Readline error when trying to start rails console?

﹥>﹥吖頭↗ 提交于 2019-12-06 07:25:38
问题 UPDATE: I probably messed up my system while trying solutions found somewhere else. I started from scratch and Ruby 1.9.3 installed without a hitch. Now to try to get ree-1.8.7 to play nice alongside... I'm trying to install Ruby 1.9.3 using RVM on Kubuntu (11.10 I believe). I've been having plenty of issues with Readline so far, but found the answer to all but this one. I installed Ruby 1.9.3 this way: rvm install 1.9.3 # Install of ruby-1.9.3-p0 - #complete cd ~/.rvm/src/ruby-1.9.3-p0/ext

Installing ruby-debug19 locally

被刻印的时光 ゝ 提交于 2019-12-06 06:36:13
问题 I'm currently running Ruby 1.9.2p0 on a Windows XP 32-bit machine. Ever since we've upgraded to Ruby 1.9, I cannot get any form of debugging to work at all. I've been told that you need the new ruby-debug19 gem in order to get things running. Problem is, my company's proxy prevents the gem dependency manager from connecting external repositories. That's ok, I'll just download the gem myself and install it locally. The results: ERROR: Error installing ruby-debug19-0.11.6.gem: ERROR: Failed to

How do I determine the length of a Fixnum in Ruby?

只谈情不闲聊 提交于 2019-12-05 22:15:07
问题 In the script I'm writing, I want find the length of a Fixnum in Ruby. I could do <num>.to_s.length , but is there any way to directly find the length of a Fixnum without converting it into a String? 回答1: puts Math.log10(1234).to_i + 1 # => 4 You could add it to Fixnum like this: class Fixnum def num_digits Math.log10(self).to_i + 1 end end puts 1234.num_digits # => 4 回答2: Ruby 2.4 has an Integer#digits method, which return an Array containing the digits. num = 123456 num.digits # => [6, 5, 4

Should I use Ruby 1.9.2 with my new web app?

一个人想着一个人 提交于 2019-12-05 18:12:26
问题 Starting a new web app with Rails 3. I'm still relatively new to web development and have really enjoyed all the internet resources available to me while working in Ruby 1.8.7 and Rails 2.3.5. Any advice against using Ruby 1.9.2 on my new project? 回答1: I have been successfully converting all my Rails projects (except one, but I'm working on it) from Ruby 1.8.7/Rails 2.3.5 to Rails 3.0.0 and Ruby 1.8.7/1.9.2 RC2 and both environments are pretty stable. Fortunately, things changed since I

Connection failed for google open_id using omniauth

北战南征 提交于 2019-12-05 13:09:53
I am trying to add open-id functionality to my app, I am using omniauth and omniauth-openid gems for same. I have done the installation steps added it to initializer as middleware, require 'omniauth-openid' require 'openid/store/filesystem' Rails.application.config.middleware.use OmniAuth::Builder do provider :open_id, :store => OpenID::Store::Filesystem.new('/tmp') end and a routes for andling callback match '/auth/:provider/callback' => 'callback#myauthentication' when I try to hit this url, to connect to google provider http://[mydomain]/auth/open_id?openid_url=https%3A%2F%2Fwww.google.com