Archive for the '/dev/rails' Category

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.

No Comments »

chris on August 7th 2008 in /dev/rails, /dev/ruby

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.

No Comments »

chris on August 7th 2008 in /dev/rails

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).

No Comments »

chris on July 13th 2008 in /dev/rails, /dev/ruby

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”, :order => “name”
  …
end

That was easy.

No Comments »

chris on June 24th 2008 in /dev/rails, /dev/ruby

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.

No Comments »

chris on June 20th 2008 in /dev/rails, /dev/random

Blaine Cook on Scalability

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.

No Comments »

chris on June 17th 2008 in /dev/rails

Unread Messages Count in LovdByLess

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).

No Comments »

chris on March 19th 2008 in /dev/rails

Ruby 1.9: Not For Rails

Do NOT install or upgrade to Ruby 1.9 if you’re using Ruby for Rails development.

There, that warning ought to suffice.

On Dec. 25 Matz announced that a development release of Ruby 1.9 was available in which the Ruby 1.9 spec has been frozen:

We are happy to announce of the release of the 1.9.0 the development
release.

We hope this helps you to enjoy hacking. Happy Holidays.

matz.

However, Ruby 1.9.0 is not a drop-in replacement for Ruby 1.8.* with more good stuff inside, many fundamentals have changed, often in incompatible ways. As Dave “PickAxe” Thomas notes:

This is a development release, not a production release. It has known bugs, and there’ll be more to come.

It contains several incompatible changes (block parameters are now block-local, String is no longer Enumerable, “cat”[1] now returns “a”, rather than 65)

It is more rigorous that 1.8 when it comes to detecting invalid code. For example, 1.8 accepts /[^\x00-\xa0]/u, while 1.9 complains of invalid multibyte escape

the likes of which are guaranteed to break either Rails, some critical gem, a required plugin or your own code. Honestly, it’s guaranteed.

As example from the Rails list:

just now i installed ruby 1.9 and rails 2.0.2 on it. when i create new rails application

username@ubuntu7.04:~/project$ rails app
can’t convert Enumerable::Enumerator into Array

and

Agreed. I just upgraded to 1.9 and found all my applications totally
hosed. I had to delete 1.9 and reinstall 1.8.6, along with Ruby Gems (on
Leopard).

I’ll be waiting for the official announcement of compatibility on the
Rails blog.

and from Rick DeNatale:

I just answered a post from someone on the TextMate forum who
installed Ruby1.9 as ruby. Now he gets a syntax error inside textmate
when he tries to run a ruby program, since Textmate uses ruby
internally, and some of that code ran into one of the syntax
incompatibilities.

Anyway, you get the idea.

If you really want to play around with Ruby 1.9, perhaps to help with the testing or just to get an idea of what cool stuff will be landing in Ruby 2.0, Dave Thomas’ post, cited above, provides great details in just how to do that.

Congrats to Matz and all the ruby-core team on 1.9.

Update: Should you need even more proof of the current “dev” state of Ruby 1.9.0, a fairly significant string encoding bug was bound found, isolated and fixed just four days after release.

No Comments »

chris on December 30th 2007 in /dev/rails, /dev/ruby

Jump-start on Rails 2.0: Rails2 PeepCode

Ruby on Rails 2.0 was released on Dec 6, 2007 and fortunately for me I had the luck of starting a brand new Rails project on Dec 9. A brand new slate on which to try out all the new Rails toys.

Invaluable in this has been Ryan Daigle’s Rails2 PDF, a well-written compendium of what’s new, what’s changed and examples thereof. It also contains the complete Rails changelog, which seemed silly to me at first glance but has since been surprisingly useful as a desktop, keyboard-side reference in its own right.

Admittedly all the information contained within can probably be found on the web and piece-meal if you manage to read all the major Rails blogs each day but for $9 having it summarized like this has made it well worth the price as a bridging document until the Rails 2.0 books start to appear.

No Comments »

chris on December 13th 2007 in /dev/rails

Rails Functionality Into Plugins

With the release of Rails 2.0 quite a bit of core functionality has been pushed out into plugins, presumably to lighten the core and allow for these plugins to take development paths and release schedules independent of that of Rails itself.

I just ran head-first into this while trying to use in_place_edit_for which generated this error:

undefined method `in_place_edit_for’ for FaqQuestionController:Class

The docs don’t make it immediately obvious (or rather, they’re completely obtuse) about which plugin the functionality has been moved to. Fortunately one can figure this out for one’s self via the Svn repository:

· CHANGELOG
· account_location/
· acts_as_list/
· acts_as_nested_set/
· acts_as_tree/
· atom_feed_helper/
· auto_complete/
· continuous_builder/
· deadlock_retry/
· exception_notification/
· http_authentication/
· in_place_editing/
· javascript_test/
· legacy/
· localization/
· open_id_authentication/
· scaffolding/
· scriptaculous_slider/
· ssl_requirement/
· token_generator/
· tzinfo_timezone/
· tztime/
· upload_progress/

(Thanks to Ryan Bigg via the rubyonrails-talk list.)

1 Comment »

chris on December 10th 2007 in /dev/rails