ruby1.9

Best practice for installing multiple versions of Ruby, apart from rvm?

I've been running both Ruby 1.8.7 and Ruby 1.9 for a few weeks now. I install Ruby 1.9 with the suffix 19, so that the interpreter, rake, gem, etc. commands are "ruby19", "irb19", "rake19", "gem19", etc. The 1.8.7 equivalents have no suffix and are thus defaults. I figure that's the simplest and most transparent way to manage two versi...

Ruby 1.9 enumeration changes

So, I don't quite get Ruby 1.9 's changes on enumerators, but what I'd like is a lazy filtering/mapping on a collection, so for example how can I create a lazy enumerator that would be the equivalent of this ... (1..100).find_all{|x| x % 2 == 1}.map{|x| x * 2}.find_all{|x| x % 3 == 0} I tried passing a lambda to #enum_for, but it does...

How is a LocalJumpError thrown from the following lambda ?

I've been reading the Ruby Programming Language book by Flanagan-Matz Context: Difference between Proc.new and lambda w.r.t return statements The book states that a return within a lambda should not raise a LocalJumpError (since lambdas are akin to method calls). A return in a lambda just exits the lambda - not the method enclosing the...

ruby: unknown encoding name: undecided

I've actually figured out what causes this error, but Googling for it was unsuccessful so I thought I'd write it down here to help out other people. This error pops up when you've got an # -*- coding: undecided -*- comment at the top of one of your files. Emacs added this automatically for me, but re-saving the file caused it to be chang...

How to use ruby fibers to avoid blocking IO

I need to upload a bunch of files in a directory to S3. Since more than 90% of the time required to upload is spent waiting for the http request to finish, I want to execute several of them at once somehow. Can Fibers help me with this at all? They are described as a way to solve this sort of problem, but I can't think of any way I can...

Properly handling unicode characters in Rails

By default Rails allows users of our application to input non-utf8 data, such as: ¶®«¼ However when we attempt to retrieve the data from our database and render it in a template Rails incorrectly assumes that it is in UTF-8 format and throws an error. ArgumentError: invalid byte sequence in UTF-8 What is the best way to handle this? ...

I get an Exception when trying to implement reset password with Authlogic

Hi, I'm using Ruby on Rails 2.3.5 and Ruby 1.9 and implmeneted Authlogic as my authentication engine. Authlogic works fine. But now I have been trying to implement password reset using the following tutorial: http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic/ But I'm getting the following exception when I ty...

_mask and Rails

So I am trying to get the cancan gem to work with my rails 3 app and I've hit a problem. I tried to copy the code that Ryan Bates (the creator of the gem) used in his screen cast, but I get an error saying that roles_mask is not a method. I figure that the _mask method was removed from Ruby/Rails at some point, and I'm now wondering wh...

Multiple Forms on the Same Page with Rails

So I'm building a rails app for high school students and I've hit a problem when it comes to creating users. I want the students to only be able to create accounts if they select their school and type in their school's password correctly. What is the correct / easiest way of doing this? Should I create a gatekeeper to the user#new acti...

Routing Users to single Models with Rails

I'm creating a Rails app for students and high schools and I'm having some trouble with my User.rb. I want to have a user model to be used for logging in, but having that user have many roles. The tricky part is that I want users that have a student role to have_one student page, and those that have a role of principal to have_one hi...

Paperclip and tempfile with Rails

I'm trying to write a rails application where users can upload images, but Paperclip doesn't seem to be working for me. I've gone through all the basic steps (added has_attached_file, the migration, making the form multipart) but I keep getting the same error whenever I try uploading an image: can't convert nil into Integer Lookin...

Template Error on Form_for in Rails

I have an nested model student that belongs to a high_school. The problem is that when I go to create a new student (/high_schools/1/students/new) I get this error: No route matches {:action=>"destroy", :controller=>"students", :high_school_id=> # <HighSchool id: 1, name: "cool place", ... } <%= form_for @student, :url => high_school_...

Ruby 1.9 and Rackspace's email api (SOAP)

Is anyone out there working with SOAP on Ruby 1.9? Rackspace has email addresses for $2/month and an api to programmatically create/destroy accounts which looks like the best I've found. Fusemail has $2 addresses too but you need a minimum of 80 to get access to the api. So, I either need to find a solution to working with Rackspace or ...

implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly. (ActionView::TemplateError)

Most of you should already know Pragmatic book's "Agile web dev with rails" (third edition). On 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 s...

Ruby: what is the pitfall in this simple code excerpt that tests variable existence

I'm starting with Ruby, and while making some test samples, I've stumbled against an error in the code that I don't understand why it happens. The code pretends to tests if a variable finn is defined?() and if it is defined, then it increments it. If it isn't defined, then it will define it with value 0 (zero). As the code threw an erro...

installing ruby/gnome2 on ruby1.9

My purpose is to install ruby/gnome2 and make it work with ruby1.9 on Ubuntu9.10. I already have ruby/gnome2 working with ruby1.8, but I need to make it work with ruby1.9. I also have ruby1.9 working. When I run within ruby-gnome2-all-0.19.3: ruby1.9 extconf.rb it eventually gives me: Target libraries: glib, gdkpixbuf, pango, atk, gt...

Ruby 1.9 Ramaze App Failing with "Illegal instruction"

I've got an app that I'm trying to get working again after wiping my system and installing Snow Leopard. I installed Ruby 1.9 from Macports (now a later version) and the dev server starts up just fine, but then dies on the first request, only telling me "Illegal instruction". I have no idea what's causing this or even how to go about deb...

What's discouraging you from writing ruby 1.9-specific code?

So far, I've been merely using YARV (ruby 1.9) as merely a faster implementation of ruby than ruby 1.8, and ensured that all of my code is backwards-compatible with ruby 1.8.6. What circumstances, if any, are stopping you from writing 1.9-specific code? One reason per answer. ...

Fix an external dependency of a ruby gem

I am currently trying to install the gem nfoiled, which provides a ruby interface to ncurses. I do this by using gem install elliottcable-nfoiled as suggest in the README. Downloading it manually from the github repository and then installing it with rake install doesn't work because of a problem with the echoe-gem, thus I am bound to us...

Problem with activesupport ruby 1.91 and rake

I have an installation of ruby 1.9.1 ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32] when I try and run a rake task I am getting an error: rake aborted! no such file to load -- ftools C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require' C:/Ruby/lib/ruby/gems/1.9.1/gems/act...