ruby

Ruby/Rails Collection to Collection

I have a two tables joined with a join table - this is just pseudo code: Library Book LibraryBooks What I need to do is if i have the id of a library, i want to get all the libraries that all the books that this library has are in. So if i have Library 1, and Library 1 has books A and B in them, and books A and B are in Libraries 1, ...

ActiveRecord#save_only_valid_attributes

Hello, I'm looking for a variation on the #save method that will only save attributes that do not have errors attached to them. So a model can be updated without being valid overall, and this will still prevent saving invalid data to the database. By "valid attributes", I mean those attributes that give nil when calling @model_insta...

diff a ruby string or array

Is there a ruby library that will take two strings or two arrays and return the difference between the two strings/arrays? ...

Ruby - Match All Occurrences Of a Regex

Is there a quick way to find every match of a regular expression in Ruby? I've looked through the Regex object in the Ruby STL and searched on Google to no avail. Thanks! ...

Overriding "find" in ActiveRecord the DRY way

I have a few models that need to have custom find conditions placed on them. For example, if I have a Contact model, every time Contact.find is called, I want to restrict the contacts returned that only belong to the Account in use. I found this via Google (which I've customized a little): def self.find(*args) with_scope(:find => { ...

in Rails, how do I execute direct SQL code on a different database?

Here is the case. I'm writing a Rails application which will monitor data quality over some specific databases. In order to do that, I need to be able to execute direct SQL queries over these databases - which of course are not the same as the one used to drive the Rails application models. In short, this means I can't use the trick of ...

Deadlock in ThreadPool

I couldn't find a decent ThreadPool implementation for Ruby, so I wrote mine (based partly on code from here: http://snippets.dzone.com/posts/show/3276 , but changed to wait/signal and other implementation for ThreadPool shutdown. However after some time of running (having 100 threads and handling about 1300 tasks), it dies with deadlock...

Rails or Grails?

Grails vs Rails. Which has better support? And which one is a better choice to develop medium size apps with? Most importantly which one has more plug-ins? ...

How to start facebook app?

Just want to know what is better way to get start developing faccebook app?Any tutorial recommnedation?And which is better to start up -php or rails? ...

Issues with using ruby (on rails) in 64-bit multiple platforms

Has anyone used ruby in 64-bit environments in various platforms (HP=UX, Solaris, AIX etc.) in a commercial production environment that heavily relies on database. Have you faced any issues / bugs during these times? I know that overall things look ok. Compilation, deployment etc. I would like to know if you encountered any 'gotcha's ...

Ruby Net::HTTP - Read only x number of bytes of the body

It seems like the methods of Ruby's Net::HTTP are all or nothing when it comes to reading the body of a web page. How can I read, say, the just the first 100 bytes of the body? I am trying to read from a content server that returns a short error message in the body of the response if the file requested isn't available. I need to read e...

What's the best linux distribution for ruby on rails development and hosting ?

I would like to know if there is a particular distribution that's more suited (has more utilities) for development and deployment of websites created using ruby on rails and javascript Thanks ...

Interacting with Outlook appointments using rails

Hi, I have a rails application running on a Linux server. I would like to interact with Outlook/Exchange 2003 appointments from the rails application. For example, certain actions should trigger sending an appointment, and then preferably accepting/canceling the appointment in Outlook should trigger events in the application. Failing t...

Mixing ActiveRecord find Conditions

I want to find records on a combination of created_on >= some date AND name IN some list of names. For ">=" I'd have to use sql condition. For "IN" I'd have to use a hash of conditions where the key is :name and the value is the array of names. Is there a way to combine the two? ...

Rails books?

Hey ya guys ...do you know good books for ruby on rails .I know 'Grails'.Keeping that in mind please suggest some good books for Rails ! ...

Why learn Perl, Python, Ruby if the company is using C++, C# or Java as the application language?

I wonder why would a C++, C#, Java developer want to learn a dynamic language? Assuming the company won't switch its main development language from C++/C#/Java to a dynamic one what use is there for a dynamic language? What helper tasks can be done by the dynamic languages faster or better after only a few days of learning than with th...

Converting an integer to a hexadecimal string in Ruby

Is there a built in way to convert an integer in Ruby into its hexadecimal equivalent. The opposite of "0A".to_i(16) =>10 or "0A".hex =>10 I know how to roll my own, but it's probably more efficient to use a built in ruby function ...

Is it possible to combine a series of PDFs into one using Ruby?

I have a series of PDFs named sequentially like so: 01_foo.pdf 02_bar.pdf 03_baz.pdf etc. Using Ruby, is it possible to combine these into one big PDF while keeping them in sequence? I don't mind installing any necessary gems to do the job. If this isn't possible in Ruby, how about another language? No commercial components, if poss...

What's the best way to model recurring events in a calendar application?

I'm building a group calendar application that needs to support recurring events, but all the solutions I've come up with to handle these events seem like a hack. I can limit how far ahead one can look, and then generate all the events at once. Or I can store the events as repeating and dynamically display them when one looks ahead on th...

Is there a tutorial that teaches common Ruby programming idioms used by experienced programmers, but may not be obvious to newcomers?

I'm looking for a Ruby's equivalent of Code Like a Pythonista: Idiomatic Python Desirable features: easy to read single document which covers all topics: tips, tricks, guidelines, caveats, and pitfalls size less than a book idioms should work out of the box for the standard distribution (% sudo apt-get install ruby irb rdoc) Please,...