ruby

Best way to store constants referenced in the DB?

In my database, I have a model which has a field which should be selected from one of a list of options. As an example, consider a model which needs to store a measurement, such as 5ft or 13cm or 12.24m3. The obvious way to achieve this is to have a decimal field and then some other field to store the unit of measurement. So what is th...

Which version of rails should I start with?

I have been dabbling with Ruby for some time now and also was thinking of learning RoR they released a new version for it. :) So now should I start learning RoR v1.2 or v2.x especially keeping the following in mind I couldn't find any great free books/in-depth tutorials on RoR 2.x yet I want to learn RoR with the eventual goal of doin...

Use of Migrations in Ruby on Rails

I would like to confirm that the following analysis is correct: I am building a web app in RoR. I have a data structure for my postgres db designed (around 70 tables; this design may need changes and additions during development to reflect Rails ways of doing things. EG, I designed some user and role tables - but if it makes sense to us...

How do I write this in Ruby/Python? Or, can you translate my LINQ to Ruby/Python?

Yesterday, I asked this question and never really got an answer I was really happy with. I really would like to know how to generate a list of N unique random numbers using a functional language such as Ruby without having to be extremely imperative in style. Since I didn't see anything I really liked, I've written the solution I was lo...

What is the popen equivalent to read and write to a child process in Windows?

Ruby's standard popen3 module does not work on Windows. Is there a maintained replacement that allows for separating stdin, stdout, and stderr? ...

What is the best practice for an environment based configuration file in Ruby on Rails

I have several properties that are dependent on the environment the application is running. For example, there are links to another application that is being developed concurrantly that get displayed in the header and footer. I want those links to be different depending on what environment they are in. This is slightly different than t...

How does theming for ziya charts work?

I'm implementing charts using The Ziya Charts Gem. Unfortunately, the documentation isn't really helpful or I haven't had enough coffee to figure out theming. I know I can set a theme using chart.add(:theme, 'whatever') Problem: I haven't found any predefined themes, nor have I found a reference to the required format. ...

Do callbacks stop operations in rails

If a callback handler returns false, does it cause only the handlers for that callback to not be called, or does it cause the remaining callbacks in that handler and all subsequent callbacks to not be called as well? ...

How do I 'validate' on destroy in rails

On destruction of a restful resource, I want to guarantee a few things before I allow a destroy operation to continue? Basically, I want the ability to stop the destroy operation if I note that doing so would place the database in a invalid state? There are no validation callbacks on a destroy operation, so how does one "validate" whethe...

What's Your Favourite IRB Trick?

What's your favourite IRB tip or trick? It could be a handy shortcut within the IRB console itself or maybe a .irbrc customization. I really like that you can type an underscore to retrieve the result of the last expression. ...

Are ruby command line switches -rubygems & -r incompatible?

I recently converted a ruby library to a gem, which seemed to break the command line usability Worked fine as a library $ ruby -r foobar -e 'p FooBar.question' # => "answer" And as a gem, irb knows how to require a gem from command-line switches $ irb -rubygems -r foobar irb(main):001:0> FooBar.question # => "answer" But the...

How do I quickly slice and dice large data files in Ruby?

I'd like to slice and dice large datafiles, up to a gig, in a fairly quick and efficient manner. If I use something like UNIX's "CUT", it's extremely fast, even in a CYGWIN environment. I've tried developing and benchmarking various Ruby scripts to process these files, and always end up with glacial results. What would you do in Ru...

Does anyone know of any cross platform GUI log viewers for Ruby On Rails?

I'm tired of using: tail -f development.log To keep track of my rails logs. Instead I would like something that displays the info in a grid and allows my to sort, filter and look at stack traces per log message. Does anyone know of a GUI tool for displaying rails logs. Ideally I would like a standalone app (not something in Netbeans...

Widget Data Across Multiple Controllers

Let's say that I have a widget that displays summary information about how many posts or comments that I have on a site. What's the cleanest way to persist this information across controllers? Including the instance variables in the application controller seems like a bad idea. Having a before filter that loads the data for each contr...

What is the best Ruby tutorial online?

Please share the link to ONE Ruby tutorial that you think deserves the title. If you have information about the intended target audience's skills, please include it in your answer as well. This will help readers choose an appropriate tutorial. ...

When do transactions start when using (restful) rails

Is it the case that the entire restful verb is under a single all encompassing transaction? That is to say, if I raise a Error in the validation or callbacks at any point in the handling of a UPDATE, DELETE, or CREATE operation, is every database operation that I may have performed in previous callbacks also rolled back? Succinctly, does...

SQL Server Adapter for Rails

Trying to find the sqlserver adapter for rails on windows. I have tried getting it from (without luck): gem install activerecord-sqlserver-adapter --source=http://gems.rubyonrails.org Where else can I get this gem? UPDATE: Make sure to run the command prompt as the administrator. Right click on the command prompt and click "Run as a...

How do I generate an array of pairwise distances in Ruby?

Say I have an array that represents a set of points: x = [2, 5, 8, 33, 58] How do I generate an array of all the pairwise distances? Thanks! ...

Long running ruby process that uses ActiveRecord to store records in a database

I'm trying to write an app using Ruby on Rails and I'm trying to achieve the following: The app needs to receive UDP messages coming in on a specific port (possibly 1 or more per second) and store them in the database so that the rest of my Rails app can access it. I was thinking of writing a separate daemon that would receive th...

Best Way to Conditional Redirect?

Using Rails v2.1, lets say you have an action for a controller that is accessible from more than one location. For example, within the Rails app, you have a link to edit a user from two different views, one on the users index view, and another from another view (lets say from the nav bar on every page). I'm wondering what is the best w...