ruby

Ruby: intelligent patch/update

Hi, After being blown away by the greatness of irb and rails console, I am loving the dynamical parts of the language more and more. Now, I wonder if it would be possible for a Ruby application to update itself on-the-fly (if the write permission allows it). Can a Ruby application fetch an update and refresh itself? I have seen this fun...

Request for one particular image ends in 502 bad gateway and proxy error

I have the Ruby on Rails-based application Redmine (based on the BitNami redmine package) running on a Windows virtual server. It runs Apache, Mongrel, Ruby, and rails. When, in a HTML page I am building a template for, I request a static image resource named /templates/mytemplate/images/bkg.jpg - around 15 kilobytes big - I get a 502 B...

How to tell a connect timeout error from a read timeout error in Ruby's Net::HTTP

My question is related to http://stackoverflow.com/questions/2370140/how-to-rescue-timeout-issues-ruby-rails. Here's the common way to rescue from a timeout: def action # Post using Net::HTTP rescue Timeout::Error => e # Do something end I'd like to determine if the exception was raised while trying to connect to the host, or if ...

Format Authlogic "last_login_at" string

Using Authlogic, the time format for @user.last_login_at" looks like this: Mon Apr 12 16:52:56 -0400 2010 How can I mangle that into a more user friendly string? ...

Why ruby object has two to_s and inspect methods that do the same thing? Or, so it seems.

The p calls inspect, and puts/print calls to_s for representing its object. If I run class Graph def initialize @nodeArray = Array.new @wireArray = Array.new end def to_s # called with print / puts "Graph : #{@nodeArray.size}" end def inspect # called with p "G" end end if __FILE__ == $0 gr = Graph.new ...

How to return children objects?

I have -- what I think -- is a simple question. Here's my code: class Fruit < ActiveRecord::Base end class Apple < Fruit end class Kiwi < Fruit end Assume that I have all the STI setup correctly, and there are multiple types of Apple and Kiwi records in the table. From here... fruits = Fruit.find(:all) ...how do I return an arr...

Calculate sum of objects for each unique object property in Ruby

I was helping with an answer in this question and it sparked a question of my own. Pie is an object that has a pieces array made of of PiePiece objects. Each PiePiece has a flavor attribute How do I create a hash that looks like this: # flavor => number of pieces { :cherry => 3 :apple => 1 :strawberry => 2 } This works, but ...

Dev Environment Tests Not 100% Compatible with Staging/Production in Rails

We use a bunch of specific apps/APIs that (unfortunately) differ quite a bit from dev to staging/production. We use tests and continuous integration at each stage, but in dev, the tests fail annoyingly (throwing dialogs, etc - thanks Windows for the 64-bit notification!). I hate to write custom code, but are there some best practices for...

How to access uploaded files in Ruby

I am trying use a Java Uploader in a ROR app (for its ease of uploading entire directories). The selected uploader comes with some PHP code that saves the files to the server. I am trying to translate this code to Ruby, but am stumped on this point: PHP has a very convenient superglobal – $_FILES – that contains a hash of all files up...

Looking to write a Tag class

I'm looking to write a Tag class (a tag is a string with no spaces). My first thought is to inherit from String: class Tag < String def initialize(str) raise ArgumentError if str =~ /\s/ super end end Does this look correct? Are there any other methods I should redefine? ...

combinations of sizes for shipping

Hi there, I've got a bunch of products with sizes to ship and I need to find out the cheapest rate. Given a shipment made out of sizes, say [1,3,3,5] I need to decide how to ship - all together or separate. However it's not as simple as [1,3,3,5] or 1 & 3 & 3 & 5, i need all of the possible combinations something like: [ [[1,3,3,5]], ...

Sequel Migration not running up?

Having some trouble with the Migrations in Sequel and could use another set of eyes. I am running a migration that looks ok but no table is created. It is definitely connecting because I can see the schema_info table has been created. -M 0/1 changes the version as you would expect but still no table. The command: sequel -m . -M 1 ~/Des...

Changing the order of arguments in ruby sprintf

Is it possible to change the order of parameters to sprintf? like sprintf(" this is %arg[2] test %arg[1]" , arg1, arg2) I need to dynamically change the order of the arguments so is that possible with sprintf? ...

Changing Redmine URL structure and adding other domains

I have set up a Redmine installation on a Windows server using the BitNami stack. I would like to change the path of the URL that is used to address redmine at the moment (www.example.com/redmine/...) if possible without physically relocating the installation. map additional subdomains to certain projects (www.example2.com pointing...

How install gems locally?

I have no internet connection on server machine, so I need to install gems locally. I tried gem install rails-2.3.4.gem But, I'm getting errors. How Can I install gems locally. Thanks. ...

How to do a "join" with an anonymous scope in ruby

Hey guys (and girls ^^) !!! Does sommebody knows how to do a "join" with an anonymous scope in ruby ??? With a named scope you just have to add ":joins =>....." but i can't really find the way to do it with anonymous ones ... . Thx in advance for the help ;) ...

Yahoo authentication

Hi - I'm playing around with the new yahoo API. I'd like to scrap some dummy data using the following address http://query.yahooapis.com/v1/public/yql?q=desc%20social.updates.search&amp;format=json&amp;diagnostics=true&amp;env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&amp;callback=cbfunc When I run this I get an authenticaion er...

wxruby - Set max length of ComboBox

Is is possible to set the Max length of a ComboBox in wxruby? I have looked in the documentation but find nothing http://wxruby.rubyforge.org/doc/combobox.html But if i do my_combobox.methods.sort I get set_max_size and set_min_size in the list. But When I call it my_combobox.set_max_length(100) I only get undefined method 'set_max_le...

wxruby - Can I update the options of a ComboBox

I have a ComboBox that I fill dynamically by what the user enters in it. ursls = LOAD_FROM_FILE("urls.txt") my_combobox = ComboBox.new(self, -1, '', DEFAULT_POSITION, DEFAULT_SIZE, urls ) And when somebody submit I save the new url def submit(url) ... APPEND_TO_FILE("urls.txt",url) ... This works great, but the ComboBox is only upd...

How do I find where a ruby method is declared?

I have a ruby method (deactivate!) that is on an activeRecord class. However, I can't seem to find where that method is declared. There have been numerous developers on this project, so it could be anywhere. There is a deactivate! on an unrelated class, but it doesn't seem to get called. Any ideas how to find all the superclasses for...