ruby

Dynamically instantiate a Ruby class similar to Java

How can this line in Java be translated to Ruby: String className = "java.util.Vector"; ... Object o = Class.forName(className).newInstance(); Thanks! ...

Good Ruby or Python OpenSource projects that need help?

Anyone know any good Ruby or Python OpenSource projects that are in need of some help at the junior level? I seen this link: http://stackoverflow.com/questions/38881/how-to-find-opensource-projects-looking-for-help but I am looking for some opinion. ...

Rails test hanging - how can I print the test name before execution?

I'm having a test hang in our rails app can't figure out which one (since it hangs and doesn't get to the failure report). I found this blog post http://bmorearty.wordpress.com/2008/06/18/find-tests-more-easily-in-your-testlog/ which adds a setup hook to print the test name but when I try to do the same thing it gives me an error saying...

RoR: Creating/Updating: Showing validation errors while preserving previous values

I have a basic model in which i have specified some of the fields to validate the presence of. in the create action in the controller i do the standard: @obj = SomeObject.new(params[:some_obj]) if @obj.save flash[:notice] = "ok" redirect... else flash[:error] = @obj.errors.full_messages.collect { |msg| msg + "<br/>" } redirect ...

Inject data members to an object

This question is based on another question of mine(thankfully answered). So if in a model I have this: def self.find_extended person = Person.find(:first) complete_name = person.firstname + ', ' + person.lastname return person end How can I inject complete name in the person object so in my controller/view I can access it...

Is Ruby a functional language?

Wikipedia says so, but I'm not convinced.Why or why not? ...

What is the difference between Ruby and Python versions of"self"?

I've done some Python but have just now starting to use Ruby I could use a good explanation of the difference between "self" in these two languages. Obvious on first glance: Self is not a keyword in Python, but there is a "self-like" value no matter what you call it. Python methods receive self as an explicit argument, whereas Ruby do...

What options do exist now to implement UTF8 in Ruby and RoR?

Following the development of Ruby very closely I learned that detailed character encoding is implemented in Ruby 1.9. My question for now is: How may Ruby be used at the moment to talk to a database that stores all data in UTF8? Background: I am involved in a new project where Ruby/RoR is at least an option. But the project needs to rel...

Rails Request Initialization

We all hear a lot about scaling issues in Rails. I was just curious what the actual costs in handling a HTTP request is in the Rails framework. Meaning, what has to happen for each and every request which comes in? Is there class parsing? Configuration? Database Connection establishment? ...

Rails Console Doesn't Automatically Load Models For 2nd DB

I have a Rails project which has a Postgres database for the actual application but which needs to pull a heck of a lot of data out of an Oracle database. database.yml looks like development: adapter: postgresql database: blah blah ... oracle_db: adapter: oracle database: blah blah My models which descend from data on th...

ruby/ruby on rails memory leak detection

I wrote a small web app using ruby on rails, its main purpose is to upload, store, and display results from xml(files can be up to several MB) files. After running for about 2 months I noticed that the mongrel process was using about 4GB of memory. I did some research on debugging ruby memory leaks and could not find much. So I have tw...

'pass parameter by reference' in Ruby ?

In Ruby, is it possible to pass by reference a parameter with value-type semantics (e.g. a Fixnum)? I'm looking for something similar to C#'s 'ref' keyword. Example: def func(x) x += 1 end a = 5 func(a) #this should be something like func(ref a) puts a #should read '6' Btw. I know I could just use: a = func(a) ...

What's the purpose of instance methods in Modules without classes?

Imagine the following Ruby Module: module Foo def inst_method puts "Called Foo.inst_method" end def self.class_method puts "Called Foo.class_method" end end Obviously Foo.class_method can be called without any class instances. However, what's happening to Foo.inst_method? Is it possible to call Foo.inst_method without ...

Why is Apache + Rails is spitting out two status headers for code 500?

I have a rails app that is working fine except for one thing. When I request something that doesn't exist (i.e. /not_a_controller_or_file.txt) and rails throws a "No Route matches..." exception, the response is this (blank line intentional): HTTP/1.1 200 OK Date: Thu, 02 Oct 2008 10:28:02 GMT Content-Type: text/html Content-Length: 122...

Why does ActiveRecord's serialize randomly corrupt my data?

I use serialize in one ActiveRecord model to serialize an Array of simple Hashes into a text database field. I even use the second parameter to coerce deserialization into Arrays. class Shop < ActiveRecord::Base serialize : recipients, Array end It seems to work fine but, after a few requests, the content of recipients turns to Hash...

RoR: Model validation question

I have a basic ActiveRecord model in which i have two fields that i would like to validate. The requirement is that at least one of the fields must have a value. Both can have values, but at least one needs a value. How do i express this with validates_presence_of statements? For example: validates_presence_of :main_file validates_...

With Rails, where should I put html snippets? I don't want partials but I want them reloaded during development.

Being lazy (and liking DRY code), I'm the kind of guy who's going to write a few little wrappers for recurring HTML markup. Those provided by Rails are good already, but sometimes I have something a little more specific that I know I'm going to repeat over and over. In some situations a partial can be the solution, but sometimes I'm jus...

Setting default values (conditional assignment)

In Ruby you can easily set a default value for a variable x ||= "default" The above statement will set the value of x to "default" if x is nil or false Is there a similar shortcut in PHP or do I have to use the longer form: $x = (isset($x))? $x : "default"; Are there any easier ways to handle this in PHP? ...

What do you need to take into consideration when deciding between MySQL and Amazon's SimpleDB for a RoR app?

I am just beginning to do research into the feasibility of using Amazon's SimpleDB service as the datastore for RoR application I am planning to build. We will be using EC2 for the web server, and had planned to also use EC2 for the MySQL servers. But now the question is, why not use SimpleDB? The application will (if successful) need t...

Error Updating a record

I get a mysql error: #update (ActiveRecord::StatementInvalid) "Mysql::Error: #HY000Got error 139 from storage engine: When trying to update a text field on a record with a string of length 1429 characters, any ideas on how to track down the problem? Below is the stacktrace. from /var/www/releases/20081002155111/vendor/rails/activere...