ruby

Ruby geocoding library compatible with latest Google maps, Yahoo maps, Bing APIs

What Ruby / Rails geocoding library is compatible with (can fetch data from): latest Yahoo PlaceFinder api latest Google V3 API Bing maps API Please also comment on the compatibility with Rails 3 and Ruby 1.9 ...

firefox and watir wouldn't work on windows due to a singularize method not found, what's wrong ?

Hi there, I just installed a fresh copy of ruby 1.8.7 on Windows XP SP3 32bits. Install watir. I used the wikipedia example : require 'rubygems' require 'watir/ie' Watir::Browser.default = 'ie' b = Watir::Browser.new b.goto("http://www.google.com") so far so good, works as expected now require 'rubygems' require 'watir/ie' ...

How do I cache a method with Ruby/Rails?

I have an expensive (time-consuming) external request to another web service I need to make, and I'd like to cache it. So I attempted to use this idiom, by putting the following in the application controller: def get_listings cache(:get_listings!) end def get_listings! return Hpricot.XML(open(xml_feed)) end When I call get_listin...

Why doesn't Delayed Jobs work with my ActionMailer production setup?

I am working on a Ruby (1.8.6) on Rails (2.3.5) application in which I am currently using Gmail to deliver email messages. I want to switch to sending the messages with Delayed Jobs. I have delayed jobs sending messages on my development environment but when I deploy to my production server and try the messages get rejected and an error...

Most Efficient way to Recursively Flatten Nested Array to Dot-separated string in Ruby?

I want to convert something like this: class NestedItem attr_accessor :key, :children def initialize(key, &block) self.key = key self.children = [] self.instance_eval(&block) if block_given? end def keys [key] + children.keys end end root = NestedItem.new("root") do children << NestedItem.new("parent_a") do...

RSpec how to stub open?

I've been trying to stub open, the open-uri version, and I'm not succeeding. I've tried doing the following but the request keeps going through: Kernel.should_receive(:open).and_return("Whatever for now") I've also tried to do OpenURI::OpenRead.should_receive(:open).and_return("Whatever for now") Since I tracked down that was wher...

How do I use selenium with Ruby?

I made some tests with the Firefox Selenium and then had it exported to Ruby. Although the tests all ran fine in Firefox, I am having trouble running the same suite in Ruby. I tried to run one of the example programs they have and I also get the same connection refused error. Here is the error I got when trying to run their google_tes...

RSpec vs. Shoulda?

I am new to the unit testing seen; I have only been using unit tests for about 2 months now. When I unit test in Ruby I currently follow the TDD style and use Test::Unit::TestCase. I have also read about RSpec and how it follows the BDD methodology. I also have read about Shoulda which is a in between the two frameworks. My question is, ...

Rails creating local xml file

I need to create a local xml file from a rails application and then copy it to a location on another server. I have tried using the File.new option to create a new file but it gives me an error saying the file does not exist. After looking closer at the documentation it says that File.new opens a file that already exists. I can't see ...

Length of a unicode string

In my Rails (2.3, Ruby 1.8.7) application, I need to truncate a string to a certain length. the string is unicode, and when running tests in console, such as 'א'.length, I realized that a double length is returned. I would like an encoding-agnostic length, so that the same truncation would be done for a unicode string or a latin1 encoded...

How to split a hash based on values in Ruby?

I have a hash in Ruby that is storing the word frequency of a string, with the word as the key and the frequency as the value. words = a_string.split(/ /) freqs = Hash.new(0) words.each { |word| freqs[word] += 1 } freqs = freqs.sort_by {|x,y| y } freqs.reverse! freqs.each do |word, freq| puts word+' '+freq.to_s end I've read that...

Rails's open source projects with best practices and/or code standard?

I would like to know some of the great opensource projects in Rails with some best practices and/or code standard including unit testing, so that I can learn some experiences from building apps from those sources. ...

Ruby question about # Signs

As seen here: http://railstutorial.org/chapters/rails-flavored-ruby#top for the file: app/helpers/application_helper.rb: module ApplicationHelper # Return a title on a per-page basis. def title base_title = "Ruby on Rails Tutorial Sample App" if @title.nil? base_title else "#{base_title} | #{@title}" en...

Is it possible to work with HTTParty request results as an object

Hi guys, I wonder if it possible to work with HTTParty (http://github.com/jnunemaker/httparty) request results as an object. Currently i use string keys to access to values of result: result["imageurl"] or result["address"]["street"] If i were in JavaScript I could simply use: result.imageurl or result.address.street Regards, Alexe...

Upgrading irb on OS X

Hello, I'm trying to update irb on my OS X 10.5 macbook: $ irb -v irb 0.9.6(09/06/30) I'm currently learning Ruby and was following the "Why's Poignant Guide to Ruby" and on this page: http://mislav.uniqpath.com/poignant-guide/book/expansion-pak-1.html they mention auto-completion in irb requires version 1.8 of irb. I'm not sure ent...

Click on word and get the definition...?

I am looking to have a user click on a word and a tip shows up above the word showing the definition. The definitions will come from a glossary of words we already have. We are using Ruby and Jquery for the site. Any suggestions or a finger pointing in a direction? ...

Ruby-Proper Usage of the Date.step() method

I have been trying to use the step() method on Date object to retrieve the previous 2 dates from the current date as follows: date_d.step(2, step=-2){|d| puts d } where 2 is the limit and step is the number of steps backward or forward. I have done this in accordance with the Documentation given here: Date.step() Thi...

Find the source file for class / method using ri or fastri for ruby

For example I do $fri group_by ---------------------------------------------------- Enumerable#group_by enum.group_by {| obj | block } => a_hash ------------------------------------------------------------------------ Returns a hash, which keys are evaluated result from the block, and values are arrays of elements in en...

Redmine ruby run

Hi, i installed redmine with this manual: http://www.redmine.org/wiki/Redmine/HowTo_Install_Redmine_in_Ubuntu but when i try to run redmine i got: #!/usr/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) require "dispatcher" ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if F...

python and ruby equivalent of perls Template::Declare?

CPAN has the Template::Declare package. A declarative way to create html templates in perl code without any html directly written. I would love to use similar packages in python and ruby. Are there equivalent packages for those languages? ...