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 0×5b1a602: 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.
chris on August 27th 2009 in /dev/rails, /dev/ruby
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.
chris on August 11th 2009 in /dev/rails
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.
chris on October 6th 2008 in /dev/rails
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.
chris on August 7th 2008 in /dev/rails, /dev/ruby
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.
chris on August 7th 2008 in /dev/rails
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).
chris on July 13th 2008 in /dev/rails, /dev/ruby
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",
rder => "name"
...
end
That was easy.
chris on June 24th 2008 in /dev/rails, /dev/ruby
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.
chris on June 20th 2008 in /dev/rails, /dev/random
In this very interesting interview with Blaine Cook (once of Twitter fame) Blaine provides the best analogy for describing “performance” vs. “scalability” I’ve yet to read:
Performance and scalability are very different things. Performance is like the speed limit; it’s a question of how quickly you can get from point A to point B. In this case, we’re talking about how quickly you can get a page rendered and delivered to the user.
Scalability is a question of how many users you can handle. Highways intrinsically don’t scale, for example, because when they’re full, you get traffic jams. In web architectures, what we aim to provide are systems that will expand (usually by adding more hardware) to handle more traffic.
Obviously they’re related – if you have a traffic jam, then the effective speed limit is lower than the theoretical limit. But increasing the speed limit won’t make traffic jams any better.
There are a whole bunch of ways to make traffic less congested – adding more lanes to the highway, encouraging people to use public transit, or better yet encouraging people to work closer to home.
Likewise, there are many techniques for making web sites more scalable, and most of them don’t involve making things much “faster”.
As an aside, I continue to be impressed by Blaine’s grace under the seemingly relentless “Tw/ails doesn’t scale and it’s your fault” onslaught. Good on you sir.
chris on June 17th 2008 in /dev/rails
Recently Less Everything released their “social network in a box” platform Lovd by Less, built upon the Rails framework, and it’s pretty nice. Very easy to set up and get running. I’m enjoying hacking around in it.
One of the first things I noticed was that users weren’t told how many unread messages they have when in their dashboard. Easy enough to add, just make these two small changes:
1. In _private.html.erb change the Messages link to:
<%= link_to( "Messages (#{@p.unread_messages.length.to_s})", messages_path ) unless @p.received_messages.empty? && !@p.has_network? %>
2. In profile.rb change the has_many association to:
has_many :unread_messages, :class_name => 'Message', :conditions => ["messages.read=?",false], :foreign_key => 'receiver_id'
(I suspect the change above is actually a fix to an existing bug since calling @p.unread_messages as-is throws a SQL error).
chris on March 19th 2008 in /dev/rails