ruby

updated acts_as_versioned_association

hi has anyone got a acts_as_versioned or acts_as_audited that supports the models associtions ? like the acts_as_versioned_association but this doesnt work in rails 2 + ? Also can you use globalize2 with any of these plugins ? Does anyone have any experience using versions and globalize2 ? thanks alot rick ...

'Who's online?' Ruby Network Program

I have several embedded linux systems that I want to write a 'Who's Online?' network service in Ruby. Below is related part of my code: mySocket = UDPSocket.new mySocket.bind("<broadcast>", 50050) loop do begin text, sender = mySocket.recvfrom(1024) puts text if text =~ /KNOCK KNOCK/ then begin sock = UD...

tips for installing postgres for a rails project on a linux box

hi I want to use a postgres database for 2 rails projects and for some php blogs. Does anybody have tips for me, which pg gem I should install for ruby? I'm searching also for some general postgres config tips. I run Ubuntu 9.04 as Server. Maybe a (not outdated) good tutorial would be great :) thanks guys ...

How to monitor delayed_job with monit

Are there any examples on the web of how to monitor delayed_job with Monit? Everything I can find uses God, but I refuse to use God since long running processes in Ruby generally suck. (The most current post in the God mailing list? God Memory Usage Grows Steadily.) Update: delayed_job now comes with a sample monit config based on thi...

rails project help

hi i am trying to get my head around the best way to develop an app in ruby on rails i have a ducument creation system that for each document has multiple associations ie text docs, images, optional accessories etc. I have created this system now to do CRUD. The next thing i want to do is have each document able to be translated into...

Activate and Deactivate the Rails code hyperlink using JQuery

How to activate and Deactivate the Rails code hyperlink using JQuery for the following code <%= f.add_associated_link "Add another email address",:class => 'add' %> please suggest me to solve this major problem ...

how to iterate a hash

I have a hash like this: { 1=>["a", "b"], 2=>["c"], 3=>["a", "d", "f", "g"], 4=>["q"] } How can I iterate it in order to get: 1----- a b 2----- c 3----- a d f g ...

Change values in a nested hash

I have a configuration class in Ruby that used to have keys like "core.username" and "core.servers", which was stored in a YAML file just like that. Now I'm trying to change it to be nested, but without having to change all the places that refer to keys in the old way. I've managed it with the reader-method: def [](key) namespace, *r...

Differences in instance_eval behaviour between Ruby 1.9.1 and 1.8.6 ?

I noticed that class variables @@my_class var are now looked up in the context of the instance_eval'd object in Ruby 1.9.1 whereas this was not the case in Ruby 1.8.6. What are some other differences in behaviour of instance_eval for Ruby 1.9.1 ? ...

Is there an ActiveRecord way to do this SQL query?

Have Addresses and Lists with many-to-many relationship, as shown below. Sometimes need all the Lists an Address is not in. Using the find_by_sql query shown, and it works great. But is there a way to do it without using direct SQL? class List has_many :address_list_memberships has_many :addresses, :through => :address_list_member...

Ruby Net::FTP Timeout Threads

I was trying to speed up multiple FTP downloads by using threaded FTP connections. My problem is that I always have threads hang. I am looking for a clean way of either telling FTP it needs to retry the ftp transaction, or at least knowing when the FTP connection is hanging. In the code below I am threading 5/6 separate FTP connection...

How to chunk an array in Ruby

In Ruby 1.8.6, I have an array of, say, 100,000 user ids, each of which is an int. I want to perform a block of code on these user ids but I want to do it in chunks. For example, I want to process them 100 at a time. How can I easily achieve this as simply as possible? I could do something like the following, but probably there's an ...

How do I format a date to mm/dd/yyyy in Ruby?

In Perl you can do: my $current_time = DateTime->now(); my $mdy = $current_time->mdy("/"); What's the easiest way to do this in Ruby? ...

Best way to parse a table in Ruby

I'd like to parse a simple table into a Ruby data structure. The table looks like this: http://img232.imageshack.us/img232/446/picture5cls.png Edit: Here is the HTML and I'd like to parse it into an array of hashes. E.g.,: schedule[0]['NEW HAVEN'] == '4:12AM' schedule[0]['Travel Time In Minutes'] == '95' Any thoughts on how to do ...

Convert a Nokogiri document to a Ruby Hash

Is there an easy way to convert a Nokogiri XML document to a Hash? Something like Rails' Hash.from_xml. ...

[Rails] has_many through: how to retrieve the id of a line in the correspondance table?

Hi, I have 2 models 'item' and 'activity'. An 'item' can have many 'activities' (limited number of activities, used by all items). To make it clearer: this is represented by a table with one item per row, one activity per column and something/nothing on the intersection if a line exists in the table matrices. to see an image (worth a 1...

How do I add a twitter search feed to my Ruby on Rails application?

I want to add a twitter feed for a specific keyword search to my rails application. Where should I start? ...

[Rails] To go API or not

My company has this Huge Database that gets fed with (many) events from multiple sources, for monitoring and reporting purposes. So far, every new dashboard or graphic from the data is a new Rails app with extra tables in the Huge Database and full access to the database contents. Lately, there has been an idea floating around of having...

When to use a lambda in rails?

When should a lambda or proc be used? I have seen them described as anonymous functions, but I am struggling to understand this concept. I would appreciate any links to or examples of when you might use one in ruby, but especially in rails. Thanks ...

ActiveRecord primary key is a varchar, error when saving

I have an active record class class Service_Catalogue < ActiveRecord::Base set_table_name "service_catalogue" set_primary_key "myKey" end myKey is an nvarchar (sql server). When I try and save it service_catalogue= Service_Catalogue.new() service_catalogue.myKey = "somevalue" service_catalogue.save I get the fol...