ruby

Why Does Ruby Only Permit Certain Operator Overloading

In Ruby, like in many other OO programming languages, operators are overloadable. However, only certain character operators can be overloaded. This list may be incomplete but, here are some of the operators that cannot be overloaded: !, not, &&, and, ||, or ...

versioned rails db and differ

I'm wondering if there's an integrated solution to have a database with versioned records supported by rails (ala version_fu ar_versioned) and a differ thanks! ...

How to fix / debug 'expected x.rb to define X.rb' in Rails

I have seen this problem arise in many different circumstances and would like to get the best practices for fixing / debugging it on StackOverflow. To use a real world example this occurred to me this morning: expected announcement.rb to define Announcement The class worked fine in development, testing and from a production console, ...

Specifying model in controller?

I came across a controller in an older set of code (Rails 1.2.3) that had the following in a controller: class GenericController > ApplicationController # filters and such model :some_model Although the name of the model does not match the name of the model, is there any reason to specify this? Or is this something that has d...

Overriding a MIME type in Rails

I want to override the JSON MIME type ("application/json") in Rails to ("text/x-json"). I tried to register the MIME type again in mime_types.rb but that didn't work. Any suggestions? Thanks. ...

Should I use haml or erb or erubis for potentially high traffic site?

I have been playing with Haml recently and really like the way the resulting code looks to me...the developer. I'm also not too worried about a designer being able to consume or change it...we're a small team. That said, beginning work on a project we believe will generate quite a bit of traffic (who doesn't?). I'm concerned that there...

Ruby on Rails: no such file to load -- openssl on RedHat Linux Enterprise

I am trying to do 'rake db:migrate' and getting the error message 'no such file to load -- openssl'. Both 'openssl' and 'openssl-devel' packages are installed. Others on Debian or Ubuntu seem to be able to get rid of this by installing 'libopenssl-ruby', which is not available for RedHat. Has anybody run into this and have a solution for...

Asterisk AGI framework for IVR; Adhearsion alternative?

I am trying to get started writing scalable, telecom-grade applications with Asterisk and Ruby. I had originally intended to use the Adhearsion framework for this, but it does not have the required maturity and its documentation is severely lacking. AsteriskRuby seems to be a good alternative, as it's well documented and appears to be ...

Java .properties file equivalent for Ruby?

I need to store some simple properties in a file and access them from Ruby. I absolutely love the .properties file format that is the standard for such things in Java (using the java.util.Properties class)... it is simple, easy to use and easy to read. So, is there a Ruby class somewhere that will let me load up some key value pairs fr...

How do I get Haml to work with Rails?

I am trying to get Haml to work with my Ruby on Rails project. I am new to Ruby on Rails and I really like it. However, when I attempt to add an aplication.html.haml or index.html.haml for a view, I just receive errors. I am using NetBeans as my IDE. Any help would be appreciated. ...

Understanding [ClassOne, ClassTwo].each(&:my_method)

I was watching a railscast and saw this code. [Category, Product].(&:delete_all) In regards to clearing a database. I asked about the line in IRC and was told (&:delete_all) was a shortcut for {|model| model.delete_all} I tested this with the following class ClassOne def class_method puts 1 end end class ClassTwo def class_m...

Anyone know of a good Ruby on Rails 2.1 Tutorial?

I'm new to Ruby on Rails, but not to MVC web development, having cut my teeth on Turbogears, Django, etc. I'm having trouble finding a piece of good intro documentation to Ruby on Rails -- either the tutorial is for RoR 1.x, or the tutorial is for RoR 2.1.x, but assumes that you already know how RoR works. Does anyone know of a tutoria...

Can you Distribute a Ruby on Rails Application without Source?

I'm wondering if it's possible to distribute a RoR app for production use without source code? I've seen this post on SO, but my situation is a little different. This would be an app administered by people with some clue, so I'm cool with still requiring an Apache/Mongrel/MySQL setup on the customer end. All I really want is for the s...

When is it appropriate to use Time#utc in Rails 2.1?

I am working on a Rails application that needs to handle dates and times in users' time zones. We have recently migrated it to Rails 2.1 and added time zone support, but there are numerous situations in which we use Time#utc and then compare against that time. Wouldn't that be the same as comparing against the original Time object? When...

Is there a more user friendly alternative to Net::HTTP for interacting with REST APIs?

Net::HTTP can be rather cumbersome for the standard use case! ...

How do you write a binary literal in ruby?

Most languages (Ruby included) allow number literals to be written in at least three bases: decimal, octal and hexadecimal. Numbers in decimal base is the usual thing and are written as (most) people naturally write numbers, 96 is written as 96. Numbers prefixed by a zero are usually interpreted as octal based: 96 would be written as 014...

Rails-like Database Migrations?

Is there any easy to install/use (on unix) database migration tools like Rails Migrations? I really like the idea, but installing ruby/rails purely to manage my database migrations seems overkill. ...

Understanding the behaviour of inject used with a lambda in Ruby

I often plug pre-configured lambdas into enumerable methods like 'map', 'select' etc. but the behavior of 'inject' seems to be different. e.g. with mult4 = lambda {|item| item * 4 } then (5..10).map &mult4 gives me [20, 24, 28, 32, 36, 40] However, if I make a 2-parameter lambda for use with an inject like so, multL = lambda {|...

Compatible encryption between C# and PHP, ColdFusion, Ruby, Python

We're developing a service that will accept a POST request, and some of the POST data will need to be encypted before the POST as it will be stored in hidden fields on a form. The application is written in C# but we want third party clients to be able to easily integrate with it. We find that most clients use PHP, Classic ASP or VB.Net....

Automate a Ruby Gem install that has input

I am trying to install the ibm_db gem so that I can access DB2 from Ruby. When I try: sudo gem install ibm_db I get the following request for clarification: Select which gem to install for your platform (i486-linux) 1. ibm_db 0.10.0 (ruby) 2. ibm_db 0.10.0 (mswin32) 3. ibm_db 0.9.5 (mswin32) 4. ibm_db 0.9.5 (ruby) 5. Skip this...