Using your dear friend, Enumerable

Posted by on January 28th, 2008.

I recently had to look over some code that was returning inconsistent results. I was able to fix the code with a few minor changes, but it was still very hard to follow. Take a look:


Continue reading this post

Share:

Comment on this post (0 comments)


Social Matchbox DC Event on January 28th

Posted by on January 17th, 2008.

Intridea is sponsoring the Social Matchbox DC Event on January 28th.

This is an open event that will bring together DC startup community members to discuss jobs, ideas and collaborative opportunities. Participation is free. Registration is required.

Visit jobmatchbox.com for more information.

Share:

Comment on this post (0 comments)


Presenting at acts_as_conference

Posted by on January 16th, 2008.

Josh Owens and Dave Naffis will be presenting at the upcoming acts_as_conference February 8th and 9th in Orlando Florida.

Adding Media to Your Rails Application

Adding media such as audio and video to a web application can be costly and time consuming. In this talk we'll cover the fundamentals and break down several solutions for uploading large files and transcoding audio and video in Rails.

Share:

Comment on this post (0 comments)


Needy Controllers - DRYing Stylesheets, Scripts, and Fetching

Posted by on January 11th, 2008.

After developing a number of applications, there were some actions I found myself performing over and over again with each new controller in each new application. With my DRY-sense tingling, I decided to do something about it and create a plugin to clean up some of those repetitive tasks that were vital but annoying to set up. Introducing Needy Controllers.

Needy Controllers takes care of your controllers’...well, needs. You can include stylesheets, javascripts, and memoized record helpers in your controllers and views with a single command, and even use filter-chain-esque options to specify and tailor to your needs. Basically, it simplifies the process of:

  1. Including stylesheets in your app on a per-controller/action basis
  2. Including javascripts on a per-controller/action basis
  3. Having helper functions to fetch records in common RESTful resource mappings

Installation

git clone git://github.com/mbleigh/needy-controllers.git vendor/plugins/needy_controllers

Usage

Styles and Scripts

To use Needy Controllers for styles and scripts, you simply call a “needs” option inside your controller like so:

class MyController < ApplicationController
  needs :styles => :standard
  needs :styles => :show, :only => :show
  needs :scripts => :behave, :except => :show

  def index
    # this action will have access to the 'standard.css' stylesheet
  end

  def show
    # this action will have access to the 'show.css' stylesheet
    # in addition to 'standard.css'
    # but will not have access to 'behave.js'
  end
end

Now that you have created your behavior and style chains, you need to include them in the view. Luckily, this is exceedingly easy! Just include :needs in your include and link tags like so:

<%= stylesheet_link_tag 'something', :needs %>
<%= javascript_include_tag 'prototype', :needs, 'effects' %>

An additional benefit of the style and behavior chains is inheritance: namely, any controller that inherits from a controller with a stylesheet or javascript included using the above method will automatically have the same stylesheet and javascript included in itself. This allows you to easily set up includes that are scoped to your exact needs with as little work as possible.

Model Fetching

To use Needy Controllers for fetching records, you use it similarly, and it creates a helper:

class MyController < ApplicationController
  # here's a standard problem
  needs :record => :user, :from => :id, :as => :user
end

The :from and :as options in this example are the defaults (:id for :from and :as defaults to the name of the record). This will create a method (“user” in the example) that will be accessible both from the controller and from the view as a helper. It will find the record with a matching ID to the URL parameter associated with the :from option. Therefore if you had nested resources you could call it as such:

needs :record => :user, :from => :user_id

That’s pretty much it, just a few simple ways to make your coding life easier. As always, there is a Trac available for any issues and I would love to hear any feedback you might have.

Share:

Comment on this post (1 comment)


Beboist - A Rails Plugin for the Bebo Social API

Posted by on January 10th, 2008.

UPDATE

Click here for the latest on Beboist


The Beboist plugin provides a Rails interface to the Bebo Social Networking API.

The plugin was designed from the ground-up to be flexible enough to accommodate any changes to the API, while at the same time providing a clean interface that will be familiar to most Rails developers.

Setup

Ensure that the json gem is installed on your system and the Beboist plugin is installed in your vendor/plugins folder:

gem install json
script/plugin install http://svn.intridea.com/svn/public/beboist

Generate your config/bebo.yml file using

script/generate beboist_settings

Fill in your appropriate app settings in config/bebo.yml. Ensure that your app name is right.

Generate the first migration for your users table using:

script/generate beboist_user_migration

Migrate your database using

rake db:migrate

In your application.rb, insert the following filters:

before_filter :reject_unadded_users
before_filter :find_bebo_user

Write your app, and keep an eye on your logs to catch any possible error messages.

API Reference

The methods listed in the Bebo API Documentation are mapped to Ruby classes in the following manner:

users.get_info(uids => "1,2,3", fields => "first_name, last_name")
  # BECOMES
BeboUsers.get_info :uids => [1,2,3], :fields => ["first_name", "last_name"]

Notes

The Beboist plugin uses Bebo’s JSON API, and the ‘json’ gem to directly convert JSON objects to Ruby. It works with Rails 2.0+, but has not been tested on Rails 1.2. Check the README for more details, and file tickets at Intridea’s Public Trac

Share:

Comment on this post (7 comments)


When You Absolutely Have To: Rails Development in Windows

Try as I might to avoid it, there comes the inevitable point in a project when I have to start doing browser compatibility. Plenty of people use VMWare Fusion or Parallels to run Windows and OS X side by side, but I find them both slow and unreliable when it comes to real testing scenarios, which leaves me with the necessity of creating a Windows development stack for Rails. After some considerable looking, I’ve settled on what I consider to be the “best” tools for the job – though they still fall short of the OS X equivalents.

  • Ruby/Rails: I use the full recommended Ruby distribution as opposed to InstantRails or similar to provide maximum flexibility and customization. I also use the MySQL Community Server for the database portion of my development stack.
  • Version Control: TortoiseSVN is a very easy to use SVN front-end, but my fingers have long since learned the console commands and continue to crave them, so I use the Apache 2.0 binaries for Windows to allow me to use SVN from the prompt.
  • Console: An absolutely indispensable application for me is Console. This open-source app provides tabbed command prompts in a much prettier interface with a number of other incredibly useful features. I highly recommend it.
  • Editor: This isn’t a slam dunk, but the closest thing to TextMate in Windows is, well, the app that was created to be TextMate for Windows. E Text Editor is very good (though in my opinion still too buggy to be called a 1.0) and comes the closest to approximating my Mac development environment. The heavier IDEs such as NetBeans and Aptana With RadRails are also viable options, but I like the speed and simplicity of E.
  • Debugging: Since the reason I end up in Windows in the first place is usually IE compatibility, I need tools to approximate the incomparable FireBug. For markup inspection, the most-helpful-least-hurtful I’ve found is Microsoft’s own Internet Explorer Developer Toolbar. Javascript debugging, the most heinous of all tasks, is made much less painful by the Microsoft Script Debugger. Don’t let the “Windows NT 4.0 and later” fool you, this is the most useful thing I’ve managed to find to get some kind of control over IE Javascript debugging.

These aren’t by any means the only tools available, and your needs/mileage may vary, but after finally getting this stack together I can develop in Windows without going into fits of hyperventilation and frustration. If you have your own indispensable tools for Rails development in Windows, I’d love to hear about them!

Share:

Comment on this post (0 comments)