ruby

Ruby Rescue To Display Full Backtrace

Here's a real quick example: puts File.join(nil, "hello") Would output test.rb:4:in 'join': can't convert nil into String (TypeError) from test.rb:4 But when I do this: begin puts File.join(nil, "hello") rescue => exception puts exception.backtrace end This will output test.rb:4:in 'join' test.rb:4 Now how do I capture th...

How to set a minimum size for a Window in wxRuby

Hi people! I'm doing a simple GUI using wxRuby. I have just only read the tutorials and FAQ on the official site of the gem, but there are just a few examples. I want to know if there's a way (i'm sure there is a way but i don't know how to implement it) to set a minimum size of the windows... For example, i want to set the minimum siz...

Ruby: Create hash with default keys + values of an array

I believe this has been asked/answered before in a slightly different context, and I've seen answers to some examples somewhat similar to this - but nothing seems to exactly fit. I have an array of email addresses: @emails = ["[email protected]", "[email protected]"] I want to create a hash out of this array, but it must look like this: i...

Ruby on Rails tutorial problem

Quick question which I hope is easily answered.. I am following this tutorial: http://oreilly.com/pub/a/ruby/archive/rails.html?page=2 and all is going well until I try create a controller and view it in my browser. The server is running and it shows the default page okay (http://127.0.0.1:3000). I ran ruby script\generate controller ...

How do you generate executables within a gem with Rake?

I've been learning Ruby recently, and I've not gotten into the dirty recesses of learning Rake yet. I've been playing around with NetBeans, and I made a little Ruby project with a file that simply prints "Hello, World!". I was looking at the Rakefile that NetBeans generates, and I noticed that it had commented out the s.executables line,...

How do I remove the first n lines from a string in Ruby?

One\n Two\n Three\n Four\n remove_lines(2) would remove the first two lines, leaving the string: Three\n Four\n ...

How do I make named_scope work properly with a joined table?

Here's my situation. I have two tables: pledges and pledge_transactions. When a user makes a pledge, he has only a row in the pledges table. Later when it comes time to fulfill the pledge, each payment is logged in my pledge_transactions table. I need to be able to query all open pledges which means that the sum of the amounts in the t...

Outputting STDOUT To A File And Back Again

I routed STDOUT to a file using this code: STDOUT.reopen(File.open("./OUTPUT",'w+')) Now I need to route STDOUT to the terminal again. How would I do this? ...

Download an image and save it.

Hello, what's the best way to download an image and save it? My current code is: temp_file = Tempfile.new "filename", "#{RAILS_ROOT}/tmp/" temp_file.puts open(path_to_picture, 'User-Agent' => 'Test').read mimetype = `file -ib #{temp_file.path}`.gsub(/\n/,"") But it seems, that the mimetyp isn't ok. Best regards ...

What is the ruby test tool called that 'breaks' your code to see how tight your tests are?

A wee while ago I ended up on a page which hosted several ruby tools, which had 'crazy' names like 'mangler' or 'executor' or something. The tool's job was to modify you production code (at runtime) in order to prove that your tests were precise. Unfortunately I would now like to find that tool again, but can't remember what it was call...

ActiveRecord: Clever Join and Include

Hi all, I am trying to get ActiveRecord to perform the following query: SELECT A.*, B.*, C.* FROM A INNER JOIN B ON B.ID = B_ID INNER JOIN C ON C.ID = C_ID The dataset is rather large, and I need as the best performance, hence this specific query. I have my models and query as follows: class A < ActiveRecord::Base belongs_to :b ...

Why would a long Rake task just stop, then start again?

I have a complex legacy data migration problem. MS Access data going into MySQL. I'm using a Rake task. There's a lot of data and it requires a lot of transforming and examining. The Rake task is hundreds of lines across about 12 files. The whole thing takes about two hours to run. It has to run on Windows (I'm using XP VMware VM hosted ...

Errno 0 in ruby memcached?

I'm getting "Errno 0. Key{< redacted >=>< redacted >}" when calling get in memcache pretty consistently (the < redacted >'s are mine). Here is the offending method in the memcache library. Any idea what could be going on? ...

Building the equivalent of a C structure in RubyCocoa

I'm trying to do something similar to this code sample but in RubyCocoa. In particular, I'm having some trouble trying to build a SecKeychainAttributeList. I suspect I need to make use of Array#pack or something to build a suitable structure in Ruby. Any advice on how to build the equivalent of attributes in the following chunk of code w...

Manipulating keychain ACLs from RubyCocoa

I'm trying to translate some of the following sample code into RubyCocoa :- SecAccessRef createAccess(NSString *accessLabel) { OSStatus err; SecAccessRef access=nil; NSArray *trustedApplications=nil; //Make an exception list of trusted applications; that is, // applications that are allowed to access the item withou...

pg.so problem with Ruby in Windows

I have installed the pg module with help of gem install pg Which returned Successfully installed pg-0.8.0-x86-mswin32-60 When a .rb-file looks like this require 'rubygems' require 'pg' I get an LoadError (exception 126) which tells me that it can't find the module C:/Ruby/lib/ruby/gems/1.8/gems/pg-0.8.0-x86-mswin32-60/lib/pg.so....

Ruby:Watir cannot connect to IE running under non-Admin account on 'default' desktop.

Some Background on architecture of the app is needed: Windows 2003/Apache-v2.2/IE7/Watir-v1.6.2/Ruby-v1.8.5 Apache running under 'localsystem' account. Request to run a Watir script comes in. Apache CGI kicks off IE7 under a particular user, e.g. 'tester', and attaches the IE7 window to the "default" desktop environment. This allows ...

Git replaced all of my LF with CRLF - How do I fix this?

I just ran a git add -A on my first git project. I got back about a thousand responses: "warning: LF will be replaced by CRLF" as it went through each file (Ruby files, some are gems). I deleted my .git directory and tried to disable this default setting by typing this command: git config core.autocrlf false Then I tried ...

Nokogiri: How to select nodes by matching text?

If I have a bunch of elements like: <p>A paragraph <ul><li>Item 1</li><li>Apple</li><li>Orange</li></ul></p> Is there a built in nokogiri method that would get me all, for example, p elements that contain the text "Apple"? (the example element above would match, for instance). ...

How do I relate two fields with Ruby on Rails?

Just starting to use Ruby on Rails to see what its like. I have a user model with an id and a post model with an adderId. The adderId of the post model should be the user id of the user that created it. How can I relate these with Ruby on Rails? ...