Synthesis : Scott Becker

AssetPackager released!

Asset Packager has been released! (Formerly known as MergeJS) New features include:

Go here to check it out: AssetPackager

Comments Off on AssetPackager released!

MergeJS to become AssetPackager

I’m working on an even better version of MergeJS, to be renamed AssetPackager, which will include:

stay tuned!

Comments Off on MergeJS to become AssetPackager

New Plugin: MergeJS – Easily merge, compress, cache, and version your javascript with Ruby on Rails

After reading Cal Henderson’s article on Vitamin Serving Javascript Fast I was immediately inspired to create a plugin to easily facilitate this in Ruby on Rails. I whipped up most of it right then, and finally got around to polishing it up for release today.

Here you go: Merge JS: Easily merge, compress, cache, and version your javascript with Ruby on Rails

Comments Off on New Plugin: MergeJS – Easily merge, compress, cache, and version your javascript with Ruby on Rails

Rails 1.1, keep dreaming

Dreamhost has apparently upgraded Ruby on Rails to 1.1 on their servers. Too bad someone was asleep (har har) when they did it, because it’s all broken. Various gems didn’t get installed correctly and none of the rails commands work right. Hopefully this entry will soon look dated.

As documented by others, there is a way around this – get the rails 1.0 gems and unpack them into /vendor/rails in your rails apps.

Or if like me and you have multiple apps, make a centralized “resources” directory and put the rails gems in there, then symlink them to all of your apps vendor directories.

mkdir /home/username/resources
svn export "http://dev.rubyonrails.org/svn/rails/tags/rel_1-0-0" /home/username/resources/rails
ln -s /home/username/resources/rails /home/username/rails_app/vendor/rails

It’s the reason this blog is up and running right now.

It’s a good idea to always freeze gems on your apps if your running on a shared host, otherwise you’re vulnerable to breakage whenever they upgrade.

Comments Off on Rails 1.1, keep dreaming

jEdit Snippets for Ruby on Rails

So, I don’t have a Mac yet (its on the way), so in the meantime, I use jEdit, the unsung hero of the non-Mac Rails programmer world. It’s a super fast, highly extensible editor. Having now read a few articles and installed some additional plugins, I found I can get most of the whiz-bang Textmate editor features, for free, on all platforms!

I thought I’d “give a little back to the community” and whip up some SuperAbbrev files for ruby and rhtml that mimic all of the Textmate Rails bundle snippets.

Note: This was totally inspired by Textmate and the syncPEOPLE Rails plugin for Textmate. So thanks to you guys for being awesome. I just thought I’d see how close I could get.

And why not, lets take it a little beyond the Textmate rails snippets, and throw in a few more that seem useful and obvious.

Basically, on the RHTML side, there is a TON of additional useful snippets.

Now this doesn’t include the other neat syncPeople commands, but if someone wants to help out with writing some jEdit macros, that would be dope.

So please, try it out, let me know if it works, add more snippets, etc.

Update: Matt Torok alerted me on the Rails mailing list that SuperAbbrevs only works with jEdit versions >=4.2final and <=4.3pre2. If you’re using the latest beta release, 4.3pre3, it’ll go wacky when you try to hit tab to switch between the fields.

What are snippets?

Snippets are small capsules of code that are activated by a key sequence followed by [CTRL-Enter]. For example, mct[CTRL-Enter] will activate the Migration Create Table snippet. The SuperAbbrevs plugin makes this possible.

Download:

Instructions:

  1. Install jEdit 4.2 if you haven’t already. (Note: Apparently SuperAbbrevs isn’t currently compatible with 4.3pre3)
  2. Install the SuperAbbrevs plugin (use the built in plug in manager to install it).
  3. Configure a keyboard shortcut for SuperAbbrevs expansion – mine is set to CTRL-Enter. Learn how to do this here.
  4. The files in the archive are SuperAbbrevs setting files. Extract them into {userhome}/.jedit/SuperAbbrevs/

    On windows, that’ll be something like:
    C:\Documents and Settings\username\.jedit\SuperAbbrevs\

  5. Restart jEdit and go to Plugins > Plugin Options > SuperAbbrevs. Under the Abbrev Set dropdown, select either Ruby or Rhtml to get a list of all the shortcuts.
  6. The best way to learn these is to go through the reference guide (below) while running jEdit and just try each one out. You’ll catch on quick. The naming scheme is really simple and follows a pattern – first letter of each word. bt becomes belong_to, ho becomes has_one, ist becomes image_submit_tag, etc.

Documentation / Reference Guide

Comments Off on jEdit Snippets for Ruby on Rails

upgrade

Upgraded the blog to the latest version of Typo, and I’m now using the “modernist” theme. I still plan to make my own design, but at least it doesn’t look like a generic typo install anymore. And thanks to Typo Filters I can now do syntax highlighting on code. That blog article seems to be the only place where it’s mentioned you can do it, and not everyone seems to know about it, so there you go.

def oh(yeah)
  render :text => "sweet!"
end

Comments Off on upgrade

jEdit rocks

Awesome tutorials on setting up jedit for ruby on rails development.

SuperAbbrevs is an awesome plugin that gets you the Textmate style
shortcut editing abilities…

Comments Off on jEdit rocks

A little update

A quick update:

To all who want the Grid control – yeah it works, but the code is sloppy and not very Rails-ish. Too much view logic in the controller. I want to re-write it before I put anything out there with my name on it. I’ll start “Getting Real” soon, I promise!

Comments Off on A little update

Active Record Relationship Design Patterns

In the world of web applications, eventually you’ve seen it all, and you start to see the same relational patterns occur over and over. To help out the newbies, here’s a list of various relationships (in Ruby on Rails syntax) that we see all the time.

Can you think of any more common relationship patterns?

Customer Relationship Management

class Company < ActiveRecord::Base
  has_many :contacts
end

class Contact < ActiveRecord::Base
  belongs_to :company
end

E-Commerce

class Category < ActiveRecord::Base
  has_many :products
end

class Product < ActiveRecord::Base
  belongs_to :category
end

class Order < ActiveRecord::Base
  has_many :line_items
end

class LineItem < ActiveRecord::Base
  belongs_to :product
  belongs_to :order
end

Roles Based Access Control

class User < ActiveRecord::Base
  has_and_belongs_to_many :roles
end

class Roles < ActiveRecord::Base
  has_and_belongs_to_many :users
  has_and_belongs_to_many :permissions
end

class Permission < ActiveRecord::Base
  has_and_belongs_to_many :roles
end

Mailing Lists:

class MailingList < ActiveRecord::Base
  has_many :subscribers
end

class Subscriber < ActiveRecord::Base
  belongs_to :mailing_list
end

Surveys / Questionaires / Quizzes:

class Survey < ActiveRecord::Base
  has_many :questions
  has_many :responses
end

class Question < ActiveRecord::Base
  belongs_to :survey
  has_many :choices
end

class Choice < ActiveRecord::Base
  belongs_to :question
end

class Response < ActiveRecord::Base
  belongs_to :survey
  has_many :response_choices
end

class ResponseChoice < ActiveRecord::Base
  belongs_to :response
  belongs_to :question
  belongs_to :choice
end

Hierarchical Content Management:

class Page < ActiveRecord::Base
  acts_as_tree
  acts_as_list :scope => :parent
end

Blogs:

class BlogEntry < ActiveRecord::Base
  has_many :comments, :dependent => true, :order => "created_at ASC"
end

class Comment < ActiveRecord::Base
  belongs_to :blog_entry
end

Social Networking:

(from: wiki.rubyonrails.com)

class User < ActiveRecord::Base
  has_and_belongs_to_many  :users,
                           :join_table => 'users_known_users',
                           :foreign_key => 'known_user_id',
                           :association_foreign_key => 'user_id',
                           :after_add => :create_reverse_association,
                           :after_remove => :remove_reverse_association

  def known_users
    self.users
  end

  private
    def create_reverse_association(associated_user)
      associated_user.known_users << self unless associated_user.known_users.include?(self)
    end

    def remove_reverse_association(associated_user)
      associated_user.known_users.delete(self) if associated_user.known_users.include?(self)
    end
end

Any major ones I’m missing here?

Comments Off on Active Record Relationship Design Patterns

up and away

Sweet, I’ve finally managed to upgrade to the latest Typo release (2.6.0) and move this blog to Dreamhost. I just couldn’t get my sites to stay up on Textdrive, so unfortunately I’m having to move away. I really like TxD, with the cool hacker culture, the active forums and direct association with rails, but I just found them to be too unreliable. More often than not I would go to my sites and find them down, or getting a random error. I realize its a challenge in a shared hosting environment, with lots of developers trying random things, but I haven’t been having these issues at Dreamhost, so here we are.

Comments Off on up and away