ruby

How to detect mailto links with Hpricot/Nokogiri

I want to match links like <a href="mailto:[email protected]">foo</a>, but this doesn't work only works in Nokogiri: doc/'a[href ^="mailto:"]' What's the right way of doing that? How do I do that with Hpricot? ...

How to handle Ruby on Rails error: "Please install the postgresql adapter: `gem install activerecord-postgresql-adapter'"

Running a Ruby on Rails (RoR) app or Ruby code which uses the ActiveRecord framework, you get the error message: Please install the postgresql adapter: gem install activerecord-postgresql-adapter Trying to run: gem install activerecord-postgresql-adapter also fails, leaving you at a loss. ...

Easiest way to fetch all href contents on page in Ruby?

I'm writing a simple web crawler in Ruby and I need to fetch all href contents on the page. What is the best way to do this, or any other web page source parsing, since some pages might not be valid, but I still want to be able to parse them. Are there any good Ruby HTML parsers that allow validity agnostic parsing, or is the best way j...

Process n items at a time (using threads)

I'm doing what a lot of people probably need to do, processing tasks that have a variable execution time. I have the following proof of concept code: threads = [] (1...10000).each do |n| threads << Thread.new do run_for = rand(10) puts "Starting thread #{n}(#{run_for})" time=Time.new while 1 do if Time.new - tim...

Where do I insert my Rails URL in the JQuery Autocomplete to reference the data set I want?

Where do I reference my controller (Rails) URL to show the dataset that I want in the autocomplete via JQuery? Here is my head: <script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt; <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/lib/jquery.bgiframe.min.js"&gt;&lt;/script&gt...

Best way to display a Twitter feed (with history) on a Rails site

On a Rails site, I'd like to display a certain Twitter feed, with pagination so the visitor can see previous tweets (as far back as needed). I implemented it using the Twitter gem, using Search method, which has a nice pagination method, but hit a limitation that Twitter will only return the statutes from the last two weeks. So after go...

Has anyone successfully deployed a Rails project with Ruby 1.9.1?

Last week I successfully completed the transition of all our company applications from Ruby 1.8.6 to Ruby 1.8.7 including local and remote configurations. From now on, development won't need to ensure backward-compatibility with Ruby 1.8.6. For the sake of curiosity, I tried to run the test suite of a couple of projects against Ruby 1.9...

How to get local time zone name from Ruby in the same way as Java does?

I need to find out local machine time zone name from Ruby (from the TZInfo::Timezone.all_identifiers list of values). I need it so that I could set correctly Oracle database session time zone so that I could handle correctly timestamp with time zone values in the database. I would like to get the same value that in Java you could get wi...

Installing bcrypt-ruby gem on Windows

I'm trying to install bcrypt-ruby on Windows Vista. So far, I have been able to install nmake.exe from a MS knowledge base article and cl.exe from installing Visual Studio 2008 Express. However, I am now encountering this error: cl -nologo -Wall -I. -IC:/InstantRails/ruby/lib/ruby/1.8/i386-mswin32 -I C:/InstantRails/ruby/lib/ruby/1.8/...

How do I convert a String object into a Hash object?

I have a string which looks like a hash: "{ :key_a => { :key_1a => 'value_1a', :key_2a => 'value_2a' }, :key_b => { :key_1b => 'value_1b' } }" How do I get a Hash out of it? like: { :key_a => { :key_1a => 'value_1a', :key_2a => 'value_2a' }, :key_b => { :key_1b => 'value_1b' } } The string can have any depth of nesting. It has all ...

Array to XML -- Rails

I have a multi-dimensional array that I'd like to use for building an xml output. The array is storing a csv import. Where people[0][...] are the column names that will become the xml tags, and the people[...>0][...] are the values. For instance, array contains: people[0][0] => first-name people[0][1] => last-name people[1][0] => Bob p...

How to master java and ruby fastest for a PHPer?

I've been using PHP all the time. Any advice to taking on these two languages? ...

Parsing namespaced XML using libxml-ruby

I'm attempting to parse XML in the following format (from the European Central Bank data feed) using libxml-ruby: <?xml version="1.0" encoding="UTF-8"?> <gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref"&gt; <gesmes:subject>Reference rates</...

[Ruby]: Passing a Class instance member value to another Class function.

I am writing a program to read files and search text in it. I have written the first initial steps. In the below given code you can see a symbol ** -- **. This where I want to pass member variable value of Class [CurrentFile]. Please also suggest what improvements I can do in this code. class CurrentFile attr_accessor :currentFileN...

How to loop through links and click each one using Watir

I have a web page with a grid, and some columns have a link in the column header that will sort the values by that column [by round-tripping to the server]. I want to write a single Watir test that will identify those sorting links and click each one in succession. This is a smoke test that ensures there are no runtime exceptions result...

Ruby on Rails with Repository Pattern?

After working with ASP.Net MVC, it has me thinking about Rails. I worked with Rails prior, but am a little rusty. ASP.Net MVC tutorials recomment hiding data layer implementation with the repository pattern. This allows easiesr Dependency Injection for Unit Testing, and nice decoupling of the controller from the model implementation. ...

Ruby/JQuery Tail Log Files

I need to hack up a quick webpage that displays a log file in real time as contents get added to that file. For example, it would be like a realtime 'tail -f error_log' type of command but would be constantly updated on the webpage. Has anyone seen/heard/dreamt of a Ruby/Jquery solution already out there? (Plugin, gem, etc.)? Thanks,...

Does Rails 2.0 do IPv6 well?

I'm using mongrel + apache 2.2 + mod_proxy_balancer. apache2.2 is IPv6 well http://httpd.apache.org/docs/2.2/en/bind.html#ipv6 Does Mongrel do IPv6 well? Platform:RHEL ruby:1.8.6 /actionpack-2.0.5/lib/action_controller/request.rb which is worried about the particularly . ...

Unable to output MySQL tables which involve dates in Sequel

I'm trying to use Sequel to access a MySQL database in Ruby. When I try accessing a table which involves a date column, I am presented with an error. When I access a table without, it functions fine. What is wrong? Example Code: require 'rubygems' require 'sequel' DB = Sequel.connect(:adapter=>'mysql', :host=>'localhost', :database=>'...

Ruby 1.8 vs 1.9 - destructive reject! operator

Why does this work the way it does? I thought it had something to do with pass-by-reference/value, but that's not the case. Does it have something to do with the new block scopes? def strip_ids(array) array.each{ |row| row.reject! {|k, v| k =~ /_id/ } } end class Foo attr_accessor :array def initialize @array = [] @array...