Using your dear friend, Enumerable
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:
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:
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.
Comment on this post (0 comments)
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.
Comment on this post (0 comments)
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:
git clone git://github.com/mbleigh/needy-controllers.git vendor/plugins/needy_controllers
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.
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.
Comment on this post (1 comment)
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.
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.
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"]
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
Comment on this post (7 comments)
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.
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!
Comment on this post (0 comments)
Comment on this post (0 comments)