Posts filed under 'Ruby on Rails'
Obie Fernandez blogged about pair programming today in response to a recent New York Times article that featured well known DevChix, Desi McAdam.
I’ve always worked very closely with my colleagues, and I’ve always wanted to try pair programming. After reading Obie’s article I start to understand why I haven’t had much success pushing this idea with employers. But as I was reading, I was reminded about how awesome the concept truly is.
This October, I’m putting together an event at the Berkman Center. I’m working with the RailsBridge folks to create a free ruby on rails one day bootcamp for women to encourage women developers.
Going forward, I was hoping to bring these women together monthly to contribute to open source because I was inspired by a brilliant keynote talk by Kirrily Robert. And I’m thinking about encouraging our newbies to pair with experienced programmers.
I can’t think of a better way to get up to speed quickly than mentoring in this way. While I can’t invest in the right hardware, I figure there’s still a lot to be gained from working on one laptop for an hour.
Are there any other events in Boston where folks pair? How easy it is for a newbie to jump in and join in the fun at these local hackfests? Since I’ve been in maternity land for the last two years, I haven’t had the opportunity to get involved with the Boston rb community as much as I’d like.
Anyone got any insight into the local Boston events? Anyone pair program in their current work environment?
September 22nd, 2009
How do you confirm the presence of one attribute or another? In other words, what if you want to validate that either one of two fields exists? You use Conditional Validation!
So, I need to validate that a user has a login and then also has either an email address or a twitter id. Here’s how I solved it:
class User < ActiveRecord::Base
validates_presence_of :login
validates_presence_of :email, :unless => :twitter_account?
def twitter_account?
!twitter_id.nil?
end
end
The :if condition also takes a Proc object, but having it call a method is cleaner and easier to extend. And it can be shared across multiple validations or ipossibly used in other situations.
September 16th, 2009
ActiveSupport::Multibyte is part of Rails so everyone can enjoy multibyte safeness in their applications. Within it, the Chars class enables you to work transparently with UTF-8 encoding in the Ruby String class without having extensive knowledge about the encoding. So while in the past you needed to download special gems and libraries to work with foreign language character sets, now you have a multibyte safe proxy for string methods. Problem solved, right?
While ruby operations like downcase and normalize will keep your utf8 characters intact, you need to be wary when you use a regex.
The Acts-As-Taggable-On plugin calls a cleanup method in the Tag.rb library. See if you can spot the problem…
def self.cleanup(name)
n = name.to_s.downcase.gsub(/[^a-z0-9_-]+/, '').strip
n.blank? ? nil : n
end
The regex is removing non-alphanumeric and underscore characters. So foreign language tags are being stripped away! Instead, you can use the /u regex parameter to parse UTF-8 strings containing multibyte characters:
gsub(/[^a-z0-9_-]+/u, ”)
So, one little character makes this plugin localized by treating Far East (and other) characters as individual characters.
def self.cleanup(name)
n = name.to_s.downcase.gsub(/[^a-z0-9_-]+/u, '').strip
n.blank? ? nil : n
end
Ah, but there’s one caveat here. While alphanumeric tags are created with unwanted special characters stripped out, UTF-8 strings are not. So I could end up with a tag that looks like this:
%$%+عربيةعربيةعربيةعربي
Hmm!
August 18th, 2009
We do a lot of prototyping here at the Berkman Center so we have the luxury of creating databases from scratch. And utilizing your Active Record associations fully is the key to enjoying all the rails yummy goodness.
You can find a really useful rundown on how to get the most out of your table relationships at guides.rubyonrails.org. And I ran across a post by Techknow that does a great job of describing Single Table Inheritance.
Got any other juicy tidbits to share?
August 14th, 2009
Last fall, I used the Restful Authentication with all the Bells and Whistles tutorial for basic authorization and have been quite pleased.
OpenID has been a little trickier to implement because of the relative_url_root error, but that has been fixed by the latest version of the open_id_authentication plugin.
I’m also running into an issue with root_url in open_id_redirect_url.
undefined local variable or method `root_url' for #SessionsController:0x4ae735c
Currently I’m working around it by swapping root_url with requested_url. I’ll have to revisit it later on.
But no where did I find anyone using an Anonymous Login option with the plugin. So I decided to hack it myself.
First I created an “anonymous” user:
User.create :login => 'anonymous', :created_at => Time.new, :updated_at => Time.new, :activated_at => Time.new, :enabled => 1
Next, in authenticated_system.rb I added the methods below:
# Returns the anonymous user
def anonymous_user
User.find_by_login("anonymous")
end
# Returns true or false if the user is anonymous.
def anonymous?
current_user == anonymous_user
end
# Login as anonymous_user
def login_as_anonymous
self.current_user = anonymous_user
end
So now my sessions_controller.rb Create method looks like this:
def create
if params[:anonymous]
login_as_anonymous
successful_login
elsif using_open_id?
open_id_authentication(params[:openid_url])
else
password_authentication(params[:login], params[:password])
end
end
I bet you could bypass creating an anonymous user and simply use User.new. What do you think? Is there a better way?
August 7th, 2009
Luis Lavena of the One-Click Installer project aims to build Ruby 1.8 and 1.9 with MinGW and GCC instead of the old Visual C++ compiler to build Ruby and other native gems. This means significant performance gains on Windows. Check out RubyInstaller for mingw32-based releases that are sure to speed up your tests and more.
Could this mean that rubyists will no longer be smirked at for developing on a Lenovo laptop? Probably not, but check out Antonio Cangiano’s blog on Zen and the Art of Programming for benchmarks and details.
August 4th, 2009
The WindyCityRails Conference in Chicago this September 12th is offering daycare thanks to Dana Jones and Ray Hightower. Dana says:
“…having childcare available at conferences, workshops, and other events will be a huge win for families…”
You bet, Dana. You might remember that I needed to bring my daughter to the Voices that Matter: Professional Ruby Conference last November. I was fortunate that she wasn’t yet mobile, and easily entertained. But nowadays, childcare issues often keep me away from events that I’d like to attend. But moms aren’t the only ones with this issue. I saw a few dads bringing their kids to a ruby class I took a couple of years ago.
Making daycare available sets a great tone for the inclusiveness of the rails community. It also sends the message that good programmers include people with commitments away from their computers.
Nice job!
June 18th, 2009
So a few posts ago I wrote about BetterNestedSet. At the time, this seemed like a great solution to store and quickly search/access multiple URLS. But we have a large database and thousands of nodes per tree causes the nested set model to break down. Reseting all of the left/right values down the tree just takes too damn long.
We threw around the idea of pulling out tlds and storing the rest of the urls in many, many flat nested sets. But I just don’t like the idea of little branches hanging around in my table. It’s inelegant and confusing. I’ve refactored the crap out of my original code only to find out that BNS throws an ArgumentError error when you upgrade to Rails 2.1.
wrong number of arguments (3 for 2)
So, rather than upgrading to Awesome Nested Set (which has yet to live up to its name) and hacking my table to death, I’m throwing in the towel and embracing plain old Acts_As_Tree. Unless someone can give me a reason not to….
December 11th, 2008
Okay, so I know that RoR development on Windows is not ideal. But I’ve been faring okay so far using RadRails for Aptana. But Aptana is a memory hog that (in conjunction with firefox and other heavy apps) can slow my laptop to crawl. So in looking for something leaner, I fell in love with NetBeans.
NetBeans is light, subversion integration rocks (color coding allows you to easily track the status of your files) and I love love love code completion. But I can’t use it. I can’t use it because I can’t get the debugger to work!
There were bugs reported in version 6.1 and now it appears that the same problem exists with 6.5. Basically, the web server refuses to start (mongrel or webrick). You get the error “Could not connect to the web server… cannot show /http:localhost:3000/“
Past workarounds from the FAQ do not help, like adding ARGV[0]=”webrick” to the scripts/server file or simply manually opening the webpage. And there’s no help out there on the net. Probably because most folks have wizened up and made the switch to Apple or Linux. *sigh*
Has anyone else out there gotten the debugger to work using Windows and NetBeans version 6.5?
December 2nd, 2008
BadwareBusters.org went live today! My rails shop StopBadware.org and Consumer Reports WebWatch have combined forces to create a friendly online community where casual computer users like our moms and dads can feel comfortable mixing with security experts and power geeks to work together to remove viruses, spyware and other badware from their computers and websites.
The idea behind the site came from my co-worker Jason Callina who also conceived of a reputation and rating system that would visually highlight popular posts. I really enjoyed putting together this site and I look forward to improving it over the next few months as we move from beta into a full launch early next year.
We welcome your feedback on BadwareBusters.org and encourage you to get involved in the online community.
November 21st, 2008
Next Posts
Previous Posts