ruby-1.9

Ruby 1.9.1-p234, Passenger 2.2.5, Rails 2.3-stable closed stream on POST request

放肆的年华 提交于 2019-12-04 04:40:42
I've setup Ruby 1.9.1 (p234) on a Ubuntu server. I'm trying to deploy a Rails app which vendors Rails 2.3-stable on Apache 2.2/Passenger 2.2.5. GET requests work fine, POST requests break immediately with the following log entry: Processing UsersController#new (for 80.203.77.44 at 2009-10-24 20:54:55) [GET] Parameters: {"controller"=>"users", "action"=>"new"} Rendering template within layouts/application Rendering users/new Completed in 23ms (View: 20, DB: 0) | 200 OK [ http://myapp/user/new] /!\ FAILSAFE /!\ 2009-10-24 20:55:01 +0200 Status: 500 Internal Server Error closed stream /usr/local

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

帅比萌擦擦* 提交于 2019-12-04 03:27:30
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? 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 Ruby 2.4 has an Integer#digits method, which return an Array containing the digits. num = 123456 num.digits # => [6, 5, 4, 3, 2, 1] num.digits.count # => 6 EDIT: To handle negative numbers (thanks @MatzFan), use the absolute value.

Globbing using braces on Ruby 1.9.3

烂漫一生 提交于 2019-12-04 03:22:06
Recent versions of Ruby support the use of braces in globbing, if you use the File::FNM_EXTGLOB option From the 2.2.0 documentation File.fnmatch('c{at,ub}s', 'cats', File::FNM_EXTGLOB) #=> true # { } is supported on FNM_EXTGLOB However, the 1.9.3 documentation says it isn't supported in 1.9.3: File.fnmatch('c{at,ub}s', 'cats') #=> false # { } isn't supported (also, trying to use File::FNM_EXTGLOB gave a name error) Is there any way to glob using braces in Ruby 1.9.3, such as a third-party gem? The strings I want to match against are from S3, not a local file system, so I can't just ask the

Implicit argument passing of super from method defined by define_method() is not supported

情到浓时终转凉″ 提交于 2019-12-04 00:41:36
In " Agile Web Development with Rails " (third edition) page 537 - 541 it has "Custom Form Builders" code as follows: class TaggedBuilder < ActionView::Helpers::FormBuilder # <p> # <label for="product_description">Description</label><br/> # <%= form.text_area 'description' %> #</p> def self.create_tagged_field(method_name) define_method(method_name) do |label, *args| @template.content_tag("p" , @template.content_tag("label" , label.to_s.humanize, :for => "#{@object_name}_#{label}") + "<br/>" + super) end end field_helpers.each do |name| create_tagged_field(name) end end This code doesn't work

Why isn't the Ruby 1.9 lambda call possible without the dot in front of the parentheses ?

百般思念 提交于 2019-12-03 22:30:55
I checked out the latest Ruby version, to play a bit with the latest changes. The first thing I tried to do was call a Ruby lambda/block/proc just like you'd do with a Python callable. a = lambda {|x| puts x} a.call(4) # works, and prints 4 a[4] # works and prints 4 a.(4) # same a(4) # undefined method 'a' for main:Object Why isn't the last call possible? Will it ever be? AFAIK it's because ruby doesn't let you define the () method for an object. The reason it doesn't let you define the () method is probably due to the fact that parentheses are optional in method calls. And for what it's worth

Ruby - UTF-8 file encoding

一世执手 提交于 2019-12-03 18:30:05
问题 We all know the "magical" # encoding: utf-8 line. But I've seen several other alternative notations, some of them pretty wild. Do you know or use any of those? Is there some more general rule of what is acceptable? Edit: Ok, apparently there are exactly 3 ways: # encoding: UTF-8 # coding: UTF-8 # -*- coding: UTF-8 -*- (more at http://blog.grayproductions.net/articles/ruby_19s_three_default_encodings) 回答1: No, there are not "exactly 3 ways" to specify the 'magic comment' -- there are an

Paper Clip failing to save attachment

微笑、不失礼 提交于 2019-12-03 13:36:57
I'm using Ruby 1.9 and Rails 2.3.4 with Paperclip gem to save attachments. and I followed tutorial by adding the proper migration, adding (has_attached_file :video) to the model, making the form (multipart) and adding <%= f.file_field :video %> to it... When I try to upload a file I look in the log and I see: [paperclip] Saving attachments. But the file isn't really uploaded and the extra fields that have been added by paperclip are all NULLs!! The fact that it's not throwing any error making me confused where to start looking for possible issues. I'm using MAC OSX Leopard, is it possible that

Rails not using correct version of Ruby

╄→гoц情女王★ 提交于 2019-12-03 11:54:23
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 - RUBY VERSION: 1.8.7 (2011-06-30 patchlevel 352) [i686-linux] - INSTALLATION DIRECTORY: /home/nick/

gem install mongrel fails with ruby 1.9.1

不打扰是莪最后的温柔 提交于 2019-12-03 11:53:02
问题 I initiated myself into rails development yesterday. I installed ruby 1.9.1, rubygems and rails. Running gem install mongrel worked fine and ostensibly installed mongrel too. I am slightly puzzled because: script/server starts webrick by default which mongrel returns nothing locate mongrel returns lots of entries like /Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1 /Developer/SDKs/MacOSX10.5.sdk/System/Library

What is the use or effect of freezing Symbols and Numbers in Ruby?

廉价感情. 提交于 2019-12-03 11:21:51
问题 In Ruby 1.9 you can have Fixnum , Float , and Symbol values that are unfrozen or frozen: irb(main):001:0> a = [ 17, 42.0, :foo ]; a.map(&:frozen?) => [false, false, false] irb(main):002:0> a.each(&:freeze); a.map(&:frozen?) => [true, true, true] I understand the utility of freezing strings, arrays, or other mutable data types. As far as I know, however, Fixnum , Symbol , and Float instances are immutable from the start. Is there any reason to freeze them (or any reason that Ruby wouldn't