ruby-on-rails

Rails Single Table Inheritance - What is the best way to explicitly set type?

I am using single table inheritance in my rails application, and want to explicitly set the type of an instance. I have class Event < ActiveRecord::Base class SpecialEvent < Event Implemented through single table inheritance. SpecialEvent.new works as expected, but I want to be able to do things like Event.new(:type => 'SpecialEv...

Why does this simple Rails unit test fail when the actual is the same as the expected?

I have an extremely simple unit test. I'm not sure why it fails when the expected is the same as the actual! Here is the method I am testing: def calibration_constant big_decimal = self.coefficient * (10**self.exponent) return big_decimal.to_f end Note, that coefficient is "6.1" and exponent is "1" Here is the relevant test lin...

Rails unit tests fail because of unique constraint on schema_migrations

I'm trying to run rake test:units and I keep getting this: Mysql::Error: Duplicate entry '2147483647' for key 1: INSERT INTO `ts_schema_migrations` (version) VALUES ('20081008010000') The "ts_" is there because I have ActiveRecord::Base.table_name_prefix set. I'm confused because there is no value '20081008010000' already in the tabl...

What is the best way to display spreadsheet data in Ruby on Rails?

I am looking for a way to edit data and have values dynamically calculated (i.e. totals, averages, etc.) My application is a web based gradebook system for teachers and one of the big challenges is allowing them to enter/update grades. The most natural solution for this type of data is a table or spreadsheet grid and my first thought w...

Thinking Sphinx indexing non-expired records.

What would be the best approach to have Thinking Sphinx only index records where Today's date is less than or equal to the record's "expires_at" field? Thanks in advance. ...

Modifying Database IDs from Rails Console?

I have a small database and have been adding entries through a Rails page. I "destroyed" one of the entries and now my sequence of IDs are skipping by one. For example, I now have 42 then 44, instead of the obvious: 42, 43, 44. I was wondering if there was a way to edit the ID number of a new object through the console. I have tried: r...

Where does Rails store data created by saving activerecord objects during tests?

Where does Rails store data created by saving activerecord objects during tests? I thought I knew the answer to that question: obviously in the _test database. But it looks like this is not true! I used this system to test what's happening to saved ActiveRecord data during rspec tests: $ rails -d mysql test $ cd test $ nano config/d...

Rails testing with out-of-process database access?

I'm building a Rails application that requires some models to interact with some necessary Java libraries. To do this, I want to use Rails on on MRI - not JRuby or RBJ. The Java code only needs read access to the database tables managed by the Rails app. One way to do this is to set up a Servlet that reads the Rails app's database table...

Custom Rails URL argument separators?

We're building a Facebook application at work using Ruby on Rails. We're currently switching it from a canvas to an iframe application for technical reasons. There is however a problem, Facebook sends you the fb_sig_api_key and others as GET varialbes in the URL (blah.com/?fb_sig_api_key=12345&whatever=hello). However, for some reason,...

Where is _why?

I have been trying to reach the sources and references for Hpricot at code.whytheluckystiff.net For a long time now. Do you know if the site, the repository or the author moved to a different location or if it is only a transient situation? Best regards and happy coding ...

Where do rspec tests for code under lib/ go?

I've got some code in the lib/ directory that don't really belong under controls, models or helpers. I'd like to write some rspec tests for this code, but am not sure where they should go under the spec/ directory. Is there a convention that's commonly followed? ...

Correct Model Data Structure? (My 1st Rails App)

I'm about to build my first Ruby on Rails application (and first anything beyond xhtml and css), and I'm looking for some helpful feedback on my model structure. I've included a mockup to help visual the application. The only models I'm sure I need so far are: 1. a movie model (to serve as the main model, named movie so URL's will look...

Server-side Push in Rails

I'd like to implement a scalable chatroom in rails using AJAX. I know from research that the only scalability happens with a server-side push. My two questions are: 1) In a reasonably efficient chat server, at what point does polling become prohibitive? 2) I really don't want to use Juggernaut. I don't know much about how comet works...

How do I test helpers in Rails?

I'm trying to build some unit tests for testing my Rails helpers, but I can never remember how to access them. Annoying. Suggestions? ...

Build a Plugin or Gem?

Typically I create a plugin when I have a module that I know I'm going to need over again in my other projects, however, they could also be packaged as gems. When should I be building a gem over creating a plugin? Is there any criteria for making the call? ...

What's wrong with "magic"?

I'm trying to decide whether to use a Rails or a Django guru to create a web app for me. I've been recommended to use Django because it uses less "magic". From my perspective however, the "magic" of Rails seems like a good thing since it could make development more concise for my contractor resulting in fewer billable hours at my expense...

Why is passenger hitting my index page so aggressively

Hi, I just moved my apache/mongrel setups to use passenger and I started noticing my index page is getting hit pretty aggressively (approx 5000 hits a day) I chucked in some logging and it turns out the ip address (REMOTE_ADDR) is showing up as "::1" for these hits. Has anyone seen this kind of activity? There must be a reason for ...

Using memcached in Rails app with Single Table Inheritance?

I have a Rails app that uses STI to handle different types of Users, such as: class Admin < User ... end I want to use memcached, but I keep getting the dreaded "unknown class/module" error. I've tried pre-loading all of my ActiveRecord models to no avail. The first request works as normal, but the first pull from memcached errors o...

Why don't my Rails server render times add up?

I'm having some trouble with my Rails app being very slow on my staging server. What is most confusing is that the final line of the log output for each request. It seems the View and Database times aren't even close to the entire render time. On one page it is as bad as ~1000ms for Completion, ~450ms for the View and ~20ms Database. ...

Is there a good resource for data on Ruby Enterprise Edition usage in the wild?

We're having great results with the Phusion stack (Passenger and Ruby Enterprise Edition) in house, but I haven't been able to find much in the way of data on their use in the wild, particularly REE. I'd love something akin to WWR's High Profile Organizations Using Rails or Ben Forta's Who's Using ColdFusion? list. There's some google g...