Tuesday, October 31, 2006

Collecting email addesses on your website

In email marketing it is important to use the names of your subscribers to establish connection. When users fillout the forms to subscribe to your list some of them will be lazy and enter names in all lowercase. When you merge the fields during mailing your newsletter it can be very tedious to clean up the database.

In Rails, you can cleanup the name fields as follows:

test = "StRrIPPed TEst"

This will create a string : "Strripped Test"

Remember that Rails has opened the existing string class and added these methods to it. So to find out the methods that are available:

~/work/testr > ./script/console
(From the Rails project directory)

> test.methods

will give you list of all available methods.

Subversion Setup for Edge Rails

The following steps are customized for my needs from the Subversion Primer for Rails Project.

1. mkdir ~/svn

2. svnadmin create --fs-type=fsfs ~/svn/pinkatio

pinkatio is the name of the Rails project

3. REPOS=file:///Users/balaparanj/svn/pinkatio

For some reason the `pwd' embedded inside the file:// does not work.

4. svn mkdir --message="Initial project layout" $REPOS/trunk $REPOS/tags $REPOS/branches

5. ~/work/pinkatio > rails pinkatio

6. ~/work/pinkatio > svn checkout $REPOS/trunk .

7. ~/work/pinkatio > svn add --force .

8. ~/work/pinkatio > svn mkdir db/migrate tmp

Ignore any error message for tmp directory.

9. ~/work/pinkatio > svn revert log/*

10. ~/work/pinkatio > svn propset svn:ignore "*.log" log

11. ~/work/pinkatio > svn propset svn:ignore "*" tmp

12. ~/work/pinkatio > svn propset svn:ignore "*doc" doc

13. ~/work/pinkatio > svn propset svn:executable "*" `find script -type f | grep -v '.svn'` public/dispatch.*

14. ~/work/pinkatio > svn commit --message="New Rails project"

15. ~/work/pinkatio > svn propset svn:externals "rails http://dev.rubyonrails.org/svn/rails/trunk/" vendor

16. ~/work/pinkatio > svn update vendor

17. ~/work/pinkatio > yes | rails .

18. ~/work/pinkatio > svn commit --message="Living on the Edge - set svn:externals on vendor / for Rails"

I skipped the steps to delete and remove the index.html from svn because the command yes | rails . undoes that step.


1. How to use Rails with Subversion
2. Create a Rails project skeleton and import and checkout from SVN all at once!

Rubyisms in Rails Book Review

I just finished reading this book. This book has the best explanation on symbols. It does a good job of explaining duck typing, blocks and metaprogramming. The topics under metaprogramming are very easy to understand, they are reflection, message sending and method missing.

I found it easier to understand because it shows snippets of Java code to show how the problem can be solved and then gives the Ruby equivalent.

It does not explain very well or go deeper on the DSL topic. This could have doubled the size of the book easily.

Thursday, October 26, 2006

Rails Secure Plugin and Google Checkout Plugin for Rails

secure_action is a ruby on rails plugin which makes it easy to defend your site against assumed logged in attacks.

To install, check out the code in your RAILS_ROOT/vendor/plugins/ directory and follow the instructions in the README:

svn checkout http://secure-action-plugin.googlecode.com/svn/trunk/ secure-action-plugin

Interesting article from a developer


svn checkout http://checkout-on-rails.googlecode.com/svn/trunk/ checkout-on-rails

Rails RESTful Authentication Plugin Part II

1. Include the line: map.connect '/', :controller => "sessions", :action => 'index'
in routes.rb
Browse the source code you will see that after login and logout the action methods route to '/', so the above definition will load the index.rhtml for the sessions_controller

2. In the sessions_controller.rb add the following method:
def index
3. Create a index.rhtml file in the views/sessions directory, include the following lines in the file:

<% if flash[:notice] -%>
<%= flash[:notice] %>

<% end -%>

Now when you login or logout, you will the message "You are logged in" and "You have been logged out message".

4. You can also uncomment the code for remember me functionality in the rhtml file. This will provide a check box that allows the user to login without entering the username and password.

Wednesday, October 25, 2006

How to setup RESTful Authentication

The following steps are tested on Mac OS 10.4.8

1. Create the Rails application: rails testr

2. Cd to testr directory. You need Rails 1.2 for this plugin, so:
rake rails:freeze:edge

3. Install the plugin: ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/restful_authentication/
(the command must be in one line)

4. Add the resouces in the config/routes.rb file (just below the first line):

map.resources :users, :sessions
map.signup '/signup', :controller => 'users', :action => 'new'
map.login '/login', :controller => 'sessions', :action => 'new'
map.logout '/logout', :controller => 'sessions', :action => 'destroy'

I also commented out the last line (default Rails 1.1 style routing).

5. Generate the migrations: ./script/generate authenticated user sessions

6. Generate mailer: ./script/generate authenticated_mailer user

7. Run mysql server

8. Specify the database password in database.yml file in config directory

9. Create testr_development database (Use CocoaSQL, YourSQL, MySQL Query Browser or command line)

10. Cd to db/migrate directory and run: rake db:migrate

11. Start the webserver: $testr > ./script/server

12. Point the browser to http://localhost:3000/signup

13. View the output of the signup process in the server console, you will see SQL insert statement.

14. Check the user table to see the newly created record.

15. Go to http://localhost:3000/login and http://localhost:3000/logout and play with the application.

I am getting sqlsock error in RailsLive CD environment. It has MySQL server 5.0. My mac has MySQL server 4.0 and it does not have any problems.

Monday, October 23, 2006

Getting Real - 37 SIgnals book

Last night I bought the "Getting Real" book from 37 signals and I finished
reading it. Here is the process that they have used with success:

1. Draw html mock-ups using paper and pencil. Easy to change and the cost of
throwing it away is negligible.
2. Create static html mockup for your site. Get feedback and make any
3. Code the most essential feature. Less is more. (They talk about
"Epicenter Design")
4. Release. Say no to all the features requested by customer. Incorporate
only those that align with the "Vision" for your software and is requested
by most of the customers.

In general there is no artifacts such as documentation, specification or
diagrams created during the product development. They are a waste of time
since no one can agree on issues. It is easier to know what we are building
and refine it when we play with the real thing.

It has helped me to think clearly and I have gained so much from this book.
I now have a blueprint for building a successful online business. I highly
recommend this book.

Rails Goodies

Agile Web Development with Rails covers the Model, View and Controller part of the Rails framework very throughly.

It falls short in AJAX and WebServices. OReilly's $10 pdf book on RJS and Webservices really rocks.

Money Train is another pdf book which is basically based on the RailsConf 2006 presentation. It contains very practical tips on Rails development.

Also $100 subscription to the RailsConf 2006 online video is not worth it. The quality of some of the videos is poor. The website has problems streaming the content. It drops the connection several times. Very frustrating experience. Half of the recordings have no video. I got the password for the site after 4 days.

There are some good presentations, I liked the DSL presentations. Google Reader is great, I subscribed for all the Rails related blogs and sites. It saved me money, I decided not to buy the RSS reader for Mac OS.

Thursday, October 19, 2006

Linux RailsLiveCD and VMWare Player on Windows

Booting the RailsLiveCD from the CD was problematic. Changed the BIOS setting to boot from CD, still no luck. Fortunately it is even better with VMWare player. It is free. This method also allows you to run both windows and Linux at the same time.

1. Download and install the free VMware player.
2. Download and install the generic virtual machine.
3. Rename the RailsLiveCD iso file to livecd.iso. Move this file to the same directory as the generic virtual machine.
4. Open the vmx file in the VMware player and enjoy.

This blog is more descriptive.