rails

Rails error: Errno::EIO (Input/output error)

Tagged:

All of a sudden one of my apps (still under development) started throwing the error "Errno::EIO (Input/output error)", coming from different controllers, but always tripping on a 'write' command.  No amount of googling turned up anything useful, but after a little digging, I realized that the offending line was using puts instead of logger.debug to spit out some tracing information.  I guess Rails (2.3.2) doesn't like that and was blowing up. 
 
Changing the appropriate lines to use logger.debug resolved it.
 

Flexible constant caching in Rails

Tagged:

As outlined in By Patrick Reagan's Recipe 61 of the very helpful Advanced Rails Recipes book, it's easy to cache your constants when loading your Rails models, which can help with both performance and speed (and accuracy!) of development. I liked this solution because it's so easy to setup.  However, some of my models are better keyed off a different field than name.  So I made the below modification to give me the flexibility I needed:

</p>

Override Authlogic login error messages for better security

Tagged:

Authlogic is a cool plugin that handles authentication for Rails (and Merb, etc).  But I just ran into a problem with one of its assumptions (which more generally probably ties back to a Rails assumption):  one error == one field == one message.
 
However, when dealing with authentication and other security mechanisms, the less information you leak out, the better the security.  So error messages that distinguish an invalid username from an incorrect password may be friendly, but they can let a would-be attacker gather more intel.  Better to hide it all behind a general "Invalid login" message.

Watch your partial names

Tagged:

I had a partial named _flash.html.erb, but using my own local variables (i.e., I wasn't using the auto-passed flash variable).  So when I tried to utilize Rails' flash var, of course it bombed:

  1. You have a nil object when you didn't expect it!
  2. You might have expected an instance of ActiveRecord::Base.
  3. The error occurred while evaluating nil.[]=

Oops. So watch out for those magic variable names ....

undefined method `+@' for " ":String

Tagged:

I came across this less-than-helpful message while working on a little Rails app (hopefully more to come on that later!):
undefined method `+@' for " ":String

The code was something like:

Java/JSP + Ruby/Rails in a single webapp with JRuby

Tagged:

JRuby has been around for a little while, and is getting lots of attention for its ability to let Ruby developers code for a Java environment, and vice versa. However, as with many young projects, there isn't much documentation when it comes to the fringe cases.

The need I came across is the following: I have a client that's been running a JSP/servlet app under Tomcat for many years (originally started with JSP 0.91!). Over time I've added more and more functionality using the same JSP, Struts, etc. toolkits as everyone else uses.

Easy caching in Rails

Tagged:

If you've got any kind of slow queries in your Rails app, you have to check out EasyCache. Since REXML's XPath processing seems really slow on even a small document, caching is critical for performance. It was super easy to add this around my xpath queries, and immediately boosted the response time of the page. Yea!

Rails & Subdirectories

I spent part of this morning fighting with Rails, trying to get a quick app I wrote hosted below an existing app. It should have been simple, but getting the various pieces cooperating took longer than it should have. The solution is to use the --prefix argument to mongrel_rails. Here's how I got it going:

Scenario:
RailsApp1 hosted as mysite.com/
RailsApp2 hosted as mysite.com/myapp2
Both apps served via Apache 2.0 + mongrel + pen on Debian Sarge

Scripts:

Syndicate content