Skip to main content

Mobomo webinars-now on demand! | learn more.

There have been several methods to deploy an Ruby on Rails application. Until recently, the most popular is to run Apache and proxy balance to multiple Mongrel instances that are running simultaneously.

Passenger, developed by Phusion, is the new kid entering the Rails deployment market. Everyone has been using the Apache PHP module for years and deploying a PHP applications is a snap. This has not been possible with Rails until Passenger. It is extremely easy, and you can still use Capistrano to automate deployment. I will show you how I get it to work on Ubuntu.

sudo gem install passenger passenger-install-apache2-module 

Update: Phusion just released Passenger 2.0 RC 1. You can download this version and do gem install passenger-1.9.0.gem instead. But I had an error compiling it on Mac OS X Leopard. hongli pointed me to use the version from GitHub that has the fix and it works like a charm. Thanks Phusion guys.

To get it from GitHub:

git clone git://github.com/FooBarWidget/passenger.git 

I created a separate /etc/apache2/mods-available/passenger.load and it contains the following:

For 1.0.5:

LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-1.0.5/ext/apache2/mod_passenger.so RailsSpawnServer /usr/local/lib/ruby/gems/1.8/gems/passenger-1.0.5/bin/passenger-spawn-server RailsRuby /usr/local/bin/ruby 

For the GitHub version (Of course the path will look different depending on where your git clone is):

LoadModule passenger_module /home/rlaw/downloads/passenger/ext/apache2/mod_passenger.so PassengerRoot /home/rlaw/downloads/passenger PassengerRuby /usr/local/bin/ruby 

I then tell Apache to load the Passenger module:

a2enmod passenger 

Now, I create a virtual host configuration for one of my Rails app in /etc/apache2/sites-available/myapp:

<VirtualHost *:80>   ServerAdmin webmaster@myapp.com   ServerName myapp.com    DocumentRoot /home/deploy/apps/myapp/current/public    <Directory /home/deploy/apps/myapp/current/public>     Options FollowSymLinks     AllowOverride None     Order allow,deny     Allow from all   </Directory>    LogLevel warn   ErrorLog /var/log/apache2/myapp/error.log   CustomLog /var/log/apache2/myapp/access.log combined </VirtualHost> 

I then restart Apache:

sudo /etc/init.d/apache2 reload 

When you need to restart your application because you have changed some code that Rails does not reload in production, just do:

touch /home/deploy/apps/myapp/current/tmp/restart.txt 

I have not tried their Ruby Enterprise Edition yet. They claim substantial memory and speed improvement at RailsConf 2008, so it will be interesting to see how that develops.

Categories
Author

The new Gem Dependencies of Rails 2.1 give developers an easier-than-ever ability to keep track of and maintain the various library dependencies inherent with any project. However, a much-overlooked additional feature of the Gem Dependencies is the ability to package traditional Rails plugins as a gem and have them hooked in properly. This article is designed as an introduction to how to write and use plugins as gems in Rails projects.

The Basics

The basic method by which this is achievable is that any plugin included through a config.gem command will automatically have the gem-packed file rails/init.rb run upon Rails’s initialization. All it takes is a little bit of effort, and any Rails plugin can be packaged as a gem and easily depended upon through gem dependencies.

You may be wondering why this is a “big deal.” Plugins are already dead simple to install in Rails (and you can even script/plugin install straight from Git now!), why do we need GemPlugins? It’s simple, really: RubyGems are a rock-solid established way of easily distributing versioned reusable bits of code. Using gems for plugins allows for a greater standardization of the way in which plugins are maintained and distributed, as well as a simple path for version-locking to ensure compatibility with legacy code etc.

Another reason that GemPlugins are important is that they provide a level of abstraction from Rails: by releasing a gem rails/init.rb you could also use the same exact code to release a Merb plugin or any other framework that supports gemified add-ons. I think you will begin to see a number of cross-framework plugins be developed as Rails gets some company and shares alike.

Using a GemPlugin

First, let’s go through the process required to use an existing gem plugin. I’m going to be using my Acts As Taggable On plugin as an example throughout because I just recently went through the process of making it available as a gem.

First, you will need to include the dependency in your environment.rb file. I’m assuming here that most plugins are going to be hosted on GitHub, but the same should be true for any gem source.

# in environment.rb    config.gem "mbleigh-acts-as-taggable-on", :source => "http://gems.github.com", :lib => "acts-as-taggable-on"

This is the standard usage of gem dependencies, and for more info on this you can see Ryan Daigle’s post or watch the RailsCast on the subject. Now assuming that you don’t already have the gem in question installed, it’s simple to grab it:

rake gems:install

This will automatically install any gem dependencies in your project, and will tell you what’s happening the same as if you had run gem install from the command line.

That’s it! Once you have successfully installed the necessary gem, you can simply start up your Rails server and the plugin will be loaded and initialized as though it were living in your vendor/plugins directory.

Now that you know how to use a GemPlugin, I’ll show you how you can take an existing plugin and gemify it quickly and painlessly.

Making a GemPlugin

Let’s say I have a plugin called awesome_fu that lives on GitHub at mbleigh/awesome-fu. I’ve already released this plugin, it works great, and now I want to make it compatible with GemPlugins.

First, let’s create a gemspec called awesome-fu.gemspec in line with the requirements for the GitHub Gem Repository. In order to make the file list, I usually find it’s easiest to “find **” in the plugin directory, then copy it into TextMate, make the modifications I need for manifest (using a regular expression to quote each of the files), and saving it in the spec. If you have only a few files in your plugin, it may be easier just to add them by hand.

Next we need to add rails/init.rb. This is a little bit troublesome, because we still want our plugin to work if installed through the traditional method, so we also need init.rb to run the same code (this is automatically fine in edge Rails). What I did for my plugin is copy all of my init.rb code into rails/init.rb and then change init.rb to the following:

require File.dirname(__FILE__) + "/rails/init"

Now they both run the same code without any kind of replication, great! This means that now I have set up my plugin to work equally as a GemPlugin or a traditional plugin with just a couple minutes of work.

All that’s left to do is switch on the RubyGem setting for my GitHub project, update the README, and push! Now anyone will be able to easily require the plugin as a gem dependency and you will get all of the accolades associated with releasing your plugin the “new and hip” way.

Caveat Coder

The one problem with GemPlugins that I have run into is that if you unpack your gems using “rake gems:unpack” the rails/init.rb file is not run on initialization. This is a known issue that is supposed (?) to be resolved but I have still experienced this problem in my experiments. Hopefully this issue will be fully resolved in edge Rails soon and the glorious future of GemPlugins can begin.

Categories
Author

Acts As Taggable On (original post here), the tagging plugin with custom tag contexts, has gathered up some great new features over the past weeks thanks to the efforts of the community as well as fellow Intrideans Pradeep Elankumaran and Brendan Lim. I just wanted to take this opportunity to go over some of what’s new and interesting in the world of acts_as_taggable_on.

Community Fixes

First, Peter Cooper was kind enough to submit a patch that allows acts_as_taggable_on to work with Rails 2.1’s named_scope when using find_options_for_tag_counts.

Secondly, the much requested support for Single Table Inheritance is finally in! It was just a matter of using a class inheritable attribute instead of a class instance variable, and big thanks to slainer68 for hunting that down and taking the time to submit a patch.

If there’s anything you’ve hacked on to Acts As Taggable On, I urge you to submit a patch to the Lighthouse Project. I try to get new patches integrated into the codebase as quickly as possible, so please do submit anything!

During the Community Code Drive at RailsConf two great features were added: taggers and related objects.

Taggers

Tags can now have ownership, allowing for such things as User-tracked tags and more. This was a requested feature and something that I’d been looking forward to myself. Here’s the usage:

class User < ActiveRecord::Base   acts_as_tagger end  class Photo < ActiveRecord::Base   acts_as_taggable_on :locations end  @some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations) @some_user.owned_taggings @some_user.owned_tags @some_photo.locations_from(@some_user)

Find Related

Another request (and another great idea) is the ability to find related objects by similar tags. This is now available through the @object.find_related_on_tags syntax:

@bobby = User.find_by_name("Bobby") @bobby.skill_list # => ["jogging", "diving"]  @frankie = User.find_by_name("Frankie") @frankie.skill_list # => ["hacking"]  @tom = User.find_by_name("Tom") @tom.skill_list # => ["hacking", "jogging", "diving"]  @tom.find_related_on_skills # => [<User name="Bobby">,<User name="Frankie">] @bobby.find_related_on_skills # => [<User name="Tom">]  @frankie.find_related_on_skills # => [<User name="Tom">] 

Gemified!

Acts As Taggable On now works as a GemPlugin in Rails. This is a new way (as of Rails 2.1) of distributing plugins as gems and having them still automatically link up and do their magic. To use it as a gem, add it to your config/environment.rb like so:

config.gem "mbleigh-acts-as-taggable-on", :source => "http://gems.github.com", :lib => "acts-as-taggable-on"

Now you should be able to get the latest version of the plugin just by running rake gems:install. However, this hasn’t been working for me so the alternative is just to install the gem directly:

gem install mbleigh-acts-as-taggable-on --source http://gems.github.com/

Now when you run your Rails app, even though it’s not in vendor/plugins it should be running! To make sure, look for this line on startup:

** acts_as_taggable_on: initialized properly

There are still a couple of issues outstanding in Rails regarding GemPlugins (if you unpack it, it will not run the initialization properly for some reason), but I wanted to give everyone the latest and greatest way to install the plugin possible. It will still work fine using the conventional methods as well.

Community and Future

I’ve been really happy with the response and support of the community, and I would like to do everything possible to cultivate future participation. To that end, I have created an Acts As Community Project for acts_as_taggable_on that will hopefully provide some casual communication about the project. Feel free to post on the wall or in the forums, and look out for additions soon.

Finally, the area of the plugin that still needs some work is tag caching. This is not a particular area of my expertise, so I’m hoping that someone from the community will write up some specs that flesh out the caching functionality in new and interesting ways.

Thanks for all of the patches, and I hope you continue to enjoy using Acts As Taggable On!

UPDATE (6/10/08): The improvements keep on rolling! After writing the post, I went off on a tangent and decided to make the plugin work both traditionally and as a gem. See more details above in the “Gemified” section.

Categories
Author

There will be no killer words in this application: Behold the mighty Fu-fu! And there was much rejoicing… But first, a little history on Fu-fu: The Profanity Filter for Rails.

A Little History

Recently, I needed a simple (profanity/cuss/swear/bad word) filter for a Rails app, so I hit up Google for the answer as this seemed like a problem that should have been solved by an expert. Sadly, this was not the case.

Over the next day or so I was able to get a simple prototype up and running in our application and that’s the way it stayed for the next couple weeks. Then I realized that this was reason I wasn’t able to find a profanity filter plugin on Google.

Upon closer inspection it seems that people are building their own filters and leaving it at that. Almost being guilty of this, I decided that it was time to give back to the community and get a profanity filter plugin out in the wild.

I was able to publish the first version of the Profanity Filter during the Community Code Drive at RailsConf 2008. Hacking in the same room as DHH, David Chelimsky, Chad Fowler, Rich Kilmer, Marcel Molina Jr., and the entire Intridea team is a great motivator.

During RailsConf we decided that the plugin needed a real name; “Profanity Filter” wasn’t cutting it. Someone suggested fu-fu pronounced ‘eff-you-foo’. That was promptly shortened to ‘foo-foo’. How can you not love something named Fu-fu that deals with profanity and abuses plugin idioms at the same time?

Continue Rejoicing (Examples!)

The interface for Fu-fu is clean and straight forward. For example. lets say that ‘frak’ is a common curse word.

class Post < ActiveRecord::Base   profanity_filter :title, :body end  post = Post.create(:title => 'Fraking title', :body => 'What a bunch of frak')  post.title          #=> '@#$% title' post.title_original #=> 'Fraking title'  post.body           #=> 'What a bunch of @#$%' post.body_original  #=> 'What a bunch of frak'

 

By default the filter will replace common curses with the standard curse notation of ‘@#$%’. Fu-fu is also has the ability to do dictionary replacements:

class Post < ActiveRecord::Base   profanity_filter :title, :body, :method => 'dictionary' end  post = Post.create(:title => 'Fraking title', :body => 'What a bunch of frak')  post.title          #=> 'fr*k*ng title' post.body           #=> 'What a bunch of fr*k'

 

Fu-fu comes with a default dictionary file that replaces all vowels with asterisks (*).

You can also add an exclamation point to the end of the filter call (profanity_filter!) and have the method save the filtered text to the database (although this is not recommended for most applications).

You can also call Fu-fu directly:

ProfanityFilter::Base.clean('frak')               #=> '@#$%' ProfanityFilter::Base.clean('frak', 'dictionary') #=> 'fr*k

 

Todos and Fixes

But alas, there is still danger in Caerbannog. As with all things, there is room for improvement.

* better filter regex, doesn't currently catch things like 'f-r-a-k' * needs support for multiple dictionaries and configuration * needs support for different levels of filtering (prude, normal, weak, etc)

 

Installation

To install the Fu-fu: The Profanity Filter on Edge Rails or Rails 2.1 and greater:

script/plugin install git://github.com/adambair/fu-fu.git

 

On earlier versions of Rails:

git clone git://github.com/adambair/fu-fu.git vendor/plugins/fu-fu

 

Resources

Bug tracking is available through the Fu-fu Lighthouse project. Also, feel free to contribute. I’ll be happy to accept patches and push requests for reasonable fixes and additions as long as they come with test coverage.

The source code is available on GitHub.

For general discussion about the plugin, please use the forums and wall of Fu-Fu’s Acts As Community Profile

Thanks to the Intridea team for their time, contributions, and suggestions. I’ve had a great time building Fu-fu and I hope someone may find it useful.

Categories
Author

We had a great time this year at RailsConf 2008 in Portland, Oregon. If you were there, we hope you had a chance to try out Yoga on Rails and hopefully you had a chance to stop by our booth to meet some of us. At our booth we were showing off some of our products, such as Acts As Community, CrowdSound, SocialSpring, Scalr, and MediaPlug. We even handed out a bunch of awesome Intridea t-shirts, which no swag-bag was complete without.

Day Before RailsConf 2008   RailsConf 2008
photo.jpg   RailsConf 2008

The Intridea team participated in the Community Code Drive on Thursday and worked on improving some of our open source plugins, such as Acts As Taggable On, SMS Fu, and Fu Fu. The rest of the conference was filled with informative talks from prominent members of the Rails and Ruby community. Even our very own Chris Selmer gave a talk on ˜How to Build an Rails App in 48 Hours' with Josh Owens of the Web 2.0 Show.

RailsConf 2008    RailsConf 2008
RailsConf 2008   RailsConf 2008
RailsConf 2008

Thanks goes out to everybody who stopped by our booth and everyone we met throughout the event. RailsConf 2008 was a blast and we can't wait until next year when we get to do it all over again.

Categories
Author

It's always a nice surprise when one of our client spontaneously praises Intridea. Recently, our friend and client T.J. of Freewebs.com wrote something nice on RailsConf Job Boards: "Intridea has been a joy to work with, working for them has got to be awesome!" Oh, by the way, we are looking for more Ruby Rock Stars!

RailsConf 2008

Congratulations to T.J. and the crew for raising 15 Million in Series A Funding for their new venture Social Gaming Network. I am jealous, he gets paid to write games!

Categories
Tags
Author

Intridea is going to be actively involved throughout Railsconf 2008. We're sending our entire team, so you're sure to see us around if you're attending.

Official Sponsors - Come Visit Us!

Intridea is an official Silver Sponsor of Railsconf this year. Come check our booth during lunch and the designated expo times (10:00-10:45am, 12:30-2:00pm, 3:30-4:30pm on Friday and Saturday). We'll be giving away t-shirts, will have product demos, and will be announcing the release of two products. Also, be sure to sign up on the Acts As Community.

Intridea Presents Yoga on Rails

Intridea will kick off each morning of RailsConf 2008 by sponsoring a yoga session aimed at refreshing developers' bodies and minds before a day of sessions. Kate Sanderson of Portland's Yoga Bhoga will be leading the session. Yoga on Rails will be an easy beginner's yoga session “ so don't be shy about coming out even if this will be your first yoga experience. We hope to see you there!

Community Code Drive

Intridea will be actively involved in the Community Code Drive on the first day of RailsConf 2008. The Community Code Drive is a chance for Rails developers to give back to the Rails community by teaching others and contributing code to open source projects. The entire Intridea team will be on hand to help support this effort.

Chris and Josh Speaking on Sunday at 1:50pm

Want to build a Rails application quickly? Competitors in the Rails Rumble had 48 hours to design, develop, and deploy a complete application. Chris Selmer and Josh Owens will take attendees through the development processes of the winning four-man Tasty Planner team, and compare it with those of the one-man Your Pet Records team. The discussion will include techniques, short-cuts, helpers, and Rails plug-ins that helped speed development. Join Chris and Josh in the Portland Ballroom 256 at 1:50pm on Sunday.

Categories
Author

Intridea’s latest product, crowdsound has been featured on TechCrunch. We love showcasing our products to a new audience, so it’s definitely a treat everytime we make it to the front page.

Here’s the link:
CrowdSound on TechCrunch

We’re currently hard at work integrating our new features and pay-plans to take us out of public beta. At the same time, our own widget is helping us receive new suggestions effortlessly — these help us polish our existing features till they shine. As such, here’s a status update on some of the most popular suggestions.

You will soon be able to customize your widget top-to-bottom.

Next, we’re working on custom categories/tags. These would be in the form of an admin-created, user-selectable list of keywords to attach to each suggestion. For all those who requested internationalization — we’re working on it. We are also working on a new search algorithm to improve the existing suggestions shown when posting a new suggestion.

The bottom line is that crowdsound is under very active development. We recommend that you subscribe to this RSS feed if you want to hear about new releases. Thank you for your support!

Categories
Author

Intridea is pleased to announce the official public beta release of crowdsound, a new tool that allows companies and websites to gather, organize and respond to suggestions from their users.

By integrating the crowdsound widget on their website, companies can transparently gather suggestions from users without forcing them to navigate away from their page. Using the widget, users can post new suggestions and also vote and comment on existing suggestions — essentially building a community around the improvement of the company’s product or website.

crowdsound’s detailed admin interface then lets companies respond to each suggestion, opening up previously closed lanes of communication between the company and users. The admin interface also allows companies to manage, organize and integrate suggestions into their workflows quite easily.

crowdsound is currently in public beta. After the beta phase, we will launch reasonably priced, tiered subscriptions plans with exciting new features.

Categories
Author
Subscribe to