10 Jan 2012, 3:28pm
/dev/rails
by

leave a comment

Rails 3.1, deprecation warning, and primary_key_name

We’ve spent the past couple days upgrading the Travergence site from Rails 3.0 to 3.1 and while it hasn’t been entirely smooth, it hasn’t been horrible either. Except for one issue:

DEPRECATION WARNING: primary_key_name is deprecated and will be removed from Rails 3.2 (use foreign_key instead).

This would cause recursion somewhere in the stack, eventually leading to:

SystemStackError (stack level too deep)

After much digging, googling, commenting-out of code, and swearing I finally figured out that it was rails3_acts_as_paranoid causing the issue. One more google led to this solution by Chris Hilton, which involves patching rails3_acts_as_paranoid to prevent circular aliasing.

Hopefully Gonçalo Silva will fix it in the official branch on Github. Until then you can either fork and patch it yourself or grab ours:

gem 'rails3_acts_as_paranoid', :git => 'git@github.com:travergence/rails3_acts_as_paranoid.git'
5 Dec 2011, 1:10pm
/dev/rails
by

leave a comment

ActiveMerchant, Bogus Gateways, and Credit Cards

When working with ActiveMerchant‘s BogusGateway, it wants very explicit credit card numbers for testing. But it doesn’t really want numbers, it wants strings.

If you’re seeing this error, as I was:

Bogus Gateway: Use CreditCard number 1 for success, 2 for exception and anything else for error

make sure that your 1 and 2 are not integers but rather are strings.

When you create your credit card instance, I highly recommend casting the number explicitly:

ActiveMerchant::Billing::CreditCard.new( :number => number.to_s, :verification_value => security_code.to_s
27 Aug 2009, 4:16pm
/dev/rails /dev/ruby
by

leave a comment

Rcov, NaN, and Fatal Crashes

Seems its possible to crash the current version of rcov hard under certain circumstances (version as of this writing: rcov (0.8.1.2.0)). If you find it crashing with:

ruby(17057,0xa0124720) malloc: *** error for object 0x5b1a602: Non-aligned pointer being freed
*** set a breakpoint in malloc_error_break to debug
/opt/local/lib/ruby/1.8/rss/rss.rb:274: [BUG] Segmentation fault
ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9]

rake aborted!
NaN

Check to see if you have any empty helper files that don’t have any coverage. I had a couple that resembled the following. Removing them removed the “divide by zero” issue that causes the crash:

module ProductHelper
end

Update
Scratch that, it doesn’t entirely fix the issue. I’ve also implemented Stew Welbourne’s hack for round_to_tenths(decimal) in MetricFu but that too does not seem to be a complete solution. The seg fault still happens, though intermittently (sometimes it runs through the complete test suite, sometimes it doesn’t).

The search continues.

11 Aug 2009, 2:17pm
/dev/rails
by

leave a comment

Rails, date_select and “index out of string”

If you’re working in Rails and using date_select() or datetime_select() (and presumably select_date() and select_datetime()) and you find yourself up against an error like the following:

index 3873 out of string

Check that your :default parameter is either nil or an actual Date/Time/DateTime instance and not a String. Passing in a string as :default really messes things up.

6 Oct 2008, 11:14am
/dev/rails
by

Comments Off

My Stylesheets Don’t Route?

Over the weekend I was mucking about with my soon-to-be-released-for-public-consumption site when all of a sudden I started getting routing errors on my stylesheets. Madness, that, expecting to need to define a controller and action for stylesheets. Imagine!

Turns out the problem was not with routing per se but with the permissions on the public/stylesheet/ directory. In my mucking it seems I’d set the permissions on that directory to 777 instead of 755. For whatever reason (I’m sure it’s in the Rails source somewhere) that small (and rather dangerously stupid) change switched stylesheet serving from Apache-handled to Rails-handled.

So, beware the permissions for they are strict indeed.

7 Aug 2008, 1:28pm
/dev/rails /dev/ruby
by

2 comments

Ultrasphinx Bootstrap Error

You’re installing Ultraspinx (perhaps per these instructions from Inoshi, which are the best I’ve found thus far) and you run into this error when time comes to bootstrap your installation:

~/Sites/ticklists/: sudo rake ultrasphinx:bootstrap –trace
(in /Users/chris/Sites/ticklists)
** Invoke ultrasphinx:bootstrap (first_time)
** Invoke ultrasphinx:_environment (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute ultrasphinx:_environment
** Invoke ultrasphinx:configure (first_time)
** Invoke ultrasphinx:_environment
** Execute ultrasphinx:configure
rake aborted!
You have a nil object when you didn’t expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]

I couldn’t find this one in the google anywhere. Turns out the cause of this is defining non-existent properties for indexing on your models (perhaps I’m the only one dumb enough to do that).

You’ll know if this is the cause because you’ll see something akin to this in your Rails console:

** ultrasphinx: warning: field f is not present in User
** ultrasphinx: warning: field descritpion is not present in Profile

Remove (or fix the spelling of) those and everything should work hunky-dory.

7 Aug 2008, 10:17am
/dev/rails
by

1 comment

Collision Between Ultrasphinx and TextMate Footnotes

If, when running in production, your Rails app throws the following error:

uninitialized constant Footnotes::Filter

You’re probably experiencing a collision between Rails’ initializer.rb file and Footnotes’ initializer.rb file.

The fix is detailed at the bottom of Searching a Ruby on Rails application with Sphinx and Ultrasphinx with the specific implementation details available via this github commit: 9bf8344b2d9ece09ff301dfc4e500e00fd46b9bc.

13 Jul 2008, 8:57pm
/dev/rails /dev/ruby
by

Comments Off

Two-weekend website: Applican

Applican A couple of weeks ago, in the middle of getting DreamBank ready for launch I was feeling like I needed a break. Of course that meant “what can I develop in Rails over a single weekend?” See, I had an idea for an application that would fulfill a need we had at DreamBank: how to manage incoming applicants and resumes against available job positions and I was pretty sure it would go.

My one-weekend project became a two weekend project and a bunch more time was shoe-horned in here and there for bug fixes and improvements until it was finally usable. And then we really got serious about the other launch and development got forgotten; it was released and functional and – dare I say it – even useful but neglected.

I now present to you “Applican“, a Rails-based resume/applicant/job tracker designed (as much as it has been) as an internal tool for small & medium-sized companies. For more details see the proto-documentation here.

I consider the current release to be about v0.4: it works, it’s useful, it undoubtedly has bugs, they’re may not be critical, there’s definitely functionality to be added. It’s free, it’s open-sourced, it’s available on Github and it require Rails 2.1.

(Apologies to Robert Rodriguez for stealing and bastardizing one of the best lines in cinema history).

24 Jun 2008, 10:46pm
/dev/rails /dev/ruby
by

Comments Off

Rails: Won’t Someone Think of the Children?

I have a class, it acts_as_tree. I want to be able to delete nodes from the tree and heal the rift between grandparent and children, joining them as parent-child afterwards.

Seems like it should be pretty obvious but nothing I was coming up with was doing the trick. The node was always deleting yet so were its children. Then I googled upon this forum and the solution was found. When executing a before_destroy filter on a class that acts_as_tree, put the before filter first:

class VettingStage < ActiveRecord::Base
  before_destroy :extract_self_from_chain
  acts_as_tree :foreign_key => "parent_id", :o rder => "name"
  ...
end

That was easy.

20 Jun 2008, 12:47pm
/dev/rails /dev/random
by

Comments Off

The Ultimate .htaccess File

This is a thing of beauty: My Webapplication Firewall Tutorial.

Note that if you’re going to use it with a Rails app you’ll probably want to remove DELETE from line 5.