Categories
ruby on rails Social Media TechBiz WebApps

What the Next Rails Will Look Like

History repeats itself, yet it is obscure to the very people making it: innovators and inventors. Ruby on Rails was an invention that hit the scene in July of 2004 as a revelation. There was a video that promised that you could make a blog in less than 15 minutes that left many speechless.

When Rails hit the seen, my reaction was:

1. This is something that we should have been doing all along.

Books like The Pragmatic Programmer had been preaching what Rails was doing since the 1990s. Software engineers would half-heartedly code the “Rails ways” but never got around to building something like Rails.

2. I need less people on my web team.

It seemed that you could work with just a designer and get lots done. I didn’t have to go to IT as much as database issues. I could use generators and save hours of time.

3. That startup that seemed impossible now seems within reach.

I remember a young Chris Wanstrath at a Ruby meetup I hosted saying with a tired look in his face that he wished he was working in Ruby. He was at CNET / CBS Interactive at the time. He’s built the best tool for developers out there and I use github.com every day.

That’s the past, now what’s the future?

The tough question to ask is, “What should we, as an industry, be doing that we are not?” The Rails philosophy was loudly yelling, “We aren’t doing DRY.”

It seems that there are 4 things that need to be done in the “next” Rails:

1. Mobile ready out of the box.

We should all be using CSS media queries and have the ability to support the mobile web. There are so many missed opportunities to retain users simply because mobile is still shockingly ignored. Mobile databases can even be integrated for a better application experience; visit Couchbase for more information and options.

2. Social Sharing out of the box.

This basically means that there has to be a standard for creating an API for APIs.

3. The backend will just look like an API.

Say good bye to complex SQL joins.

4. Designing tools with deep integration into the cloud.

Languages have been designed for CPUs in non-networked environments. This means that at a core-level, the next Rails will be SSL capable, e-commerce capable and ready to scale out of the box.  Hints of this can be seen in Erlang.

Categories
os x ruby on rails WebApps

Rails on Nginx with Passenger on Mac OS X Lion

This is a quick and dirty guide to getting Ruby on Rails working on Nginx with Passenger on Mac OS X Lion:

brew install nginx
gem install passenger
cd ~/Library/Caches/Homebrew/
tar zxvf nginx-*.tar.gz 
cd nginx-*
passenger-install-nginx-module 

Now you to edit this file:

/usr/local/Cellar/nginx/1.0.11/conf/nginx.conf

Make sure there’s something like the stuff below:

  server {
        listen       8080;
        server_name  localhost;

        root /Users/me/repos/my_awesome_rails_app/public

        rails_env development;
        passenger_enabled on;

        charset utf-8;
  }

nginx
lynx http://localhost:8080

Guides Online:

http://mrjaba.posterous.com/rails-31-asset-pipeline-with-nginx-and-passen

http://samsoff.es/posts/running-rails-local-development-with-nginx-postgres-and-passenger-with-homebrew

Categories
Coding How-To ruby ruby on rails WebApps

Upgrade Your Rails Facebook App to SSL

On October 1st of this year, Facebook will be requiring that all apps on Facebook must support HTTPS (SSL).

I’ve provided a guide below which I’ve used for apps I’ve worked on that are Rails based.

This guide shows you how to change your Rails Facebook App into an app that supports SSL using Passenger and Apache2.

Step 1: Get an SSL cert or roll your own.

Dreamhost.com made it very easy to add an SSL cert for just $15.00 / year.

I tried out my app out using a locally signed certificate which seemed to work just fine:

openssl genrsa -des3 -out server.key 2048
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Step 2: Install and compile Apache 2

Get the latest version of Apache: http://httpd.apache.org/download.cgi.

Configure and compile Apache:
./configure –prefix=/usr/local/apache2 –enable-rewrite –enable-so –enable-ssl
make && make install

Step 3: Configure your Rails app

gem install passenger
passenger-install-apache2-module

Step 4: Edit your Apache 2 config files:

Edit httpd.conf. For example:

LoadModule fcgid_module modules/mod_fcgid.so
LoadModule passenger_module /Users/jimbarcelona/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.8/ext/apache2/mod_passenger.so
PassengerRoot /Users/jimbarcelona/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.8
PassengerRuby /Users/jimbarcelona/.rvm/wrappers/ruby-1.9.2-p290/ruby


    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all


Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-ssl.conf


IPCCommTimeout 40
IPCConnectTimeout 10

# TODO: change this to production if you are on production
DefaultInitEnv RAILS_ENV development
SocketPath /tmp/fcgidsock

Edit extra/httpd-vhosts.conf:


  ServerName berkeley.l33tcave.com
  ServerAdmin wwwadmin@berkeley.l33tcave.com
  DocumentRoot /Users/jimbarcelona/rails_apps/github/hipsterhookups.com/public
  ErrorLog /usr/local/apache2/logs/rails_error_log
  RewriteEngine On
  
    AllowOverride All
    Options -MultiViews
  
  RailsEnv development

Edit extra/httpd-ssl.conf:

#   General setup for the virtual host
DocumentRoot "/Users/jimbarcelona/rails_apps/github/hipsterhookups.com/public"
ServerName berkeley.l33tcave.com:443
ServerAdmin you@example.com
ErrorLog "/usr/local/apache2/logs/error_log"
TransferLog "/usr/local/apache2/logs/access_log"

# needed for rails
Options Indexes ExecCGI FollowSymLinks
RewriteEngine On
RailsEnv development


AddHandler fcgid-script .fcgi

  
    AllowOverride All
    Options -MultiViews
  

Be sure to add your SSL certs in the httpd-ssl.conf too!

Step 5: Start Apache

# check syntax
apachectl configtest
# start apache
apachectl start

Step 6: Go to facebook and use https for canvas URLs

Categories
Coding ruby ruby on rails

Upgrading To Rails 3

Here’s how I upgraded Sitebeagle.net to Rails 3.

1. Go into your site’s Rails directory and install rails_upgrade:

script/plugin install git://github.com/rails/rails_upgrade.git

Run the following commands and follow the instructions:

rake rails:upgrade:check
rake rails:upgrade:backup
rake rails:upgrade:routes
rake rails:upgrade:gems
rake rails:upgrade:configuration

2. Make sure that your version of Ruby 1.9+ has iconv working.

Mine didn’t, so I went through this process:

rvm package install readline
rvm package install iconv
rvm remove 1.9.2
rvm install –trace 1.9.2 -C –with-iconv-dir=$HOME/.rvm/usr

to test:
irb
require ‘iconv’ # should return true

3. Upgrade to Rails 3: gem install rails

4. Start migrating to Rails 3: I branched my site using git and went into my Rails root directory and typed:

rails `pwd`

Use your best judgment on what can and cannot be over-written. Here’s my list:

* let rails overwrite?
* overwrite rake file
* overwrite application_controller.rb? yes but copy
* application_helper.rb ? yes
* routes.rb ? yes but copy
* environment.rb ?
* make new initializer for contants
* config.gem? copy and put into a Gemfile
* application.js ? only if confident in js
* scripts? overwrite all

5. See if stuff works:

rails server

Twitter-auth broke for me, so I had to update it to work on Rails 3 using this guide:

https://github.com/benders/twitter-auth/compare/master…rails_3

How’s your upgrade to Rails 3 go? Let me know in the comments below.

Update (14 January 2011):

Chris Laco wrote up this great guide to upgrading Rails 3 on Dreamhost. It solves path problem issues with gems.

Categories
How-To ruby on rails

Redboxing with Rails: Modal Windows FTW

There’s a great lightbox plugin for Ruby on Rails called Redbox. Unfortunately, it doesn’t work out of the box, but here’s the patch for redbox.js:

Replace:

Element.setTop(window_id, boxTop);
Element.setLeft(window_id, boxLeft);

With:

$(window_id).style.top = boxTop + “px”;
$(window_id).style.left = boxLeft + “px”;

Remove or comment out:

Element.hide(‘RB_loading’);

Remove:

<div id=”RB_loading”></div>
Categories
How-To ruby on rails WebApps

The Rails Console Makes Test Object Creation and Debugging Easy

I really like how the Rails console solves the problems of test object creation and debugging.

Usually, a web developer will push code to the webserver and hit shift-reload on the web browser. With the Rails console, you can avoid all that shift-reload madness.

If I wanted to create 10000 blog posts for testing, I could do something like this:

script/console
10000.times
{ |i| Post.create(:title => “post number: ” + i.to_s, :body => “autogen Booyah!”) }

Through the console I can also do debugging pretty easily:

>> p = Post.find 888

And get this as output:

=> #

A lot of problems in Rails are just solved by running script/console and checking the values of certain variables that are pretty hard to get at through a web browser.

There is pretty much no limit to what can be done through the Rails console. Konstantin Gredeskoul, web developer and songwriter, has found a way to load session data through the console.

Categories
ruby on rails TechBiz WebApps

Mephisto: Blogging Software on Rails

Blogging software should meet four important criteria:
1) Easy import from a pre-existing piece of blogging software we’re not happy with.
2) Spam filtering protection in comments
3) Make it easy to add web analytics javascript tracking without deleting it during each upgrade.
4) Should make it easy to not look like Mephisto blogging software or WordPress or like generic blogging software.

Mephisto screenshot

Mephisto meets all four criteria.

Plus it leverages the advantages of Rails in that out of the box you can deploy to development, test and production environments. Also it integrates with no mess into shopify or any other Rails project that you might be working.

Hats off to Rick Olson(Development) and Justin Palmer(UI/Design) for making Mephisto along with “a bunch of other cool people.”