A A

Archive | Ruby on Rails

Refactoring Tip: Eliminating Model.find(params[:id]) Duplication

Sunday, December 7, 2008

0 Comments

In a controller, you’ll commonly have a method that requires you have an instance variable containing the object you’re working with. An example would be the show, edit, update, and destroy methods (REST). To eliminate having find(params[:id]) in multiple methods, you can use before_filter, like this: class Admin::PostsController < Admin::ApplicationController before_filter :find_post, :only => [:show, :edit, [...]

Using Javascript to Populate Forms During Development

Sunday, December 7, 2008

1 Comment

During development, working with forms quickly gets annoying because you have to constantly fill in each field, sometimes with unique info. One way around this is to write a little Javascript code that just populates the fields. I use something like this on the bottom of the form. I had jQuery no-conflict mode on in [...]

Mephisto for the Masses – Installation HOWTO

Tuesday, October 21, 2008

0 Comments

I’ve recently taken a fancy to Mephisto, a blogging-platform written in Rails. I have nothing against Wordpress, but being in Ruby and using Liquid for themes, Mephisto is far easier (and more fun) to tweak and configure, especially when I want to migrate my sites away from the “blog look” and make them more dynamic. [...]

How To Use Fixtures to Populate Your Database in Rails

Friday, July 11, 2008

5 Comments

UPDATE: I’ve been using this method for awhile now: http://railspikes.com/2008/2/1/loading-seed-data Seed data is data that the app is dependent on. It is data that has to exist if you were to wipe the database clean and reload your schema. Some examples would be a list of cities/states, a list of categories, or the initial ‘admin’ user [...]

Got API? Instantly Search API Documentation

Sunday, June 1, 2008

0 Comments

gotAPI.com does an excellent job congregating API documentation for numerous programming languages under an AJAX interface. No more bulging neck veins or fulmination when you can’t remember the order of those pesky arguments. No support for your favorite language? Contribute. You can add a gotAPI Search Widget to your site: http://www.gotapi.com/widgets/index.html See Ruby/Rails widget below (requires Javascript). Still [...]

Simple Way to Populate a Database in Rails

Tuesday, March 18, 2008

2 Comments

This is how I populate my database when I have a lot of data but can’t be bothered to write more than a quick throw-away hack. This doesn’t use fixtures, nor migrations (nothing wrong with them, I wuv migrations). Just a ruby file and the Rails console (this is optional actually). I create a new rb [...]

Introduction to Validations & Validation Error Handling in Rails

Friday, February 8, 2008

4 Comments

Validations in Ruby on Rails are essentially nothing more than methods that ensure that the data in a model is valid before saving it to the database. Traditionally, we validate data coming in using conditional expressions (for example, if email != NULL or if passwd==passwd_confirmation). This task is essential, but boring and tedious, but Rails’ [...]

Expanding List of Ruby on Rails Sites, Editors, Tutorials, Cheat Sheets and More

Wednesday, January 2, 2008

9 Comments

Most of these Ruby on Rails related links are right out of my bookmarks. I checked for 404s and added more recent entries, but this list is far from complete. New blogs, sites, tutorials and tools are released on a daily basis. Just leave a comment or contact me if you want your link(s) [...]

Understanding Basic Database Relationships in Rails

Wednesday, December 26, 2007

17 Comments

This short tutorial will be beneficial for you if database relationships and keywords like belongs_to and has_many confuse you, or if you’re trying to find out how relationships are implemented in Rails. As we create a small demonstration project, you’ll see that one beauty of Rails is how it does most of the work gluing [...]

Using Vim as a Complete Ruby on Rails IDE

Thursday, December 13, 2007

30 Comments

NOTE: If you are experiencing segmentation faults with vim and rails.vim, see this post. When coding in Ruby on Rails, you’ll usually be switching between files and running scripts a lot. It can be time-consuming and frustrating coding Rails using a traditional text editor designed for working on big files individually. Vim lets you hop around [...]