Excellent! what else I say about Barcamp Delhi 2

Yesterday I was at Barcampdelhi2 sponsored by Opera and supported by Impetus tech. It was my first barcamp ever and it was excellent, great sessions by great people. There were 2 or 3 sessions about web standards and they forced me to think  about web standards. I never take care of them, do you…?
Anyways Thanks to Opera for T-Shirts, Pen, Ball, Lunch and Beer.

You can find BarcampDelhi2 photos at http://www.flickr.com/photos/tags/barcampdelhi2/
and slides at http://slideshare.net/tag/barcampdelhi2

Accessing session data using session_id

This is the very rare case but some times we need to access the data stored in session through session_id(specially when the request is not coming from browser). Here is a way I found and like to share:

@user=CGI::Session::ActiveRecordStore::Session.find_by_session_id(@session_id).data[:user]

BarCampDelhi-2: see you there…

barcamp.gifI will be at BarCamp this Saturday, 9th Dec. Most probably I will be presenting something related to ROR. If you’re going to attend BarCampDelhi-2, I hope that you’ll come out and hear me speak there. This will be my first public presentation ever. If you wanna attend/present at BarCamp please add yourself in the campers list(here) so the planners can arrange the space.

Ruby On Rails Search engine for Mozilla Firefox

Some days ago we created a customized google search engine for ROR, now you can use this search engine with Mozilla Firefox. What you have to do is: Download rails_search.xml, save it in your searchplugins directory under Mozilla FireFox installation path (usually it is  C:\Program Files\Mozilla Firefox\searchplugins) and you are done. Restart FireFox and Rails search engine will appear in the search engine list at top right corner.

*To download the file, right click on the link above and save link as rails_search.xml

Ajax based drag drop and sortable tree for Rails

My friend sur wrote and shares his code for Ajax based drag drop sortable tree for rails. He is also trying to pluginize this, and soon it will be publicly available. Find more detail here.

Uploading files using AJAX

There is no way to upload files using AJAX. How Gmail does it then? Well, the answer is using <iframe>. Here is a post that describe this technique in detail. Infact we are using this technique from months, obviously inspired by Gmail. ;-)

update: Technically speaking, it’s not Ajax. Just an iframe hack. You are absolutly right Pratik.

Cheat Sheet

  • Capistrano1.2.0 cheat sheet here.
  • REST cheat sheet here.
  • Rails cheat sheet here.
  • Rails testing cheat sheet here.

Deprecated Method in ActionView::Helpers::PrototypeHelper

Prototype helper method update_element_function is deprecated now, Please use RJS instead.

Installing subversion from pre-compiled packages or source code

What is subversion(svn):

Subversion is an open source version control system used for keep track of change to source code. Subversion manages files and directories over time an increments revision made to the file system. A tree of file is placed into a central repository. The repository is much like an ordinary file server, except that it remembers every change ever made to your files and directories. This allows you to recover older version of your date or examine the history of how your data changed.

Subversion can access its repository across networks, which allows it to be used by people on different computers. At some level, the ability for various people to modify and manage the same set of data from their respective locations fosters collaboration.

Installation:

There are two types of installation:

  1. Installation from pre-compiled packages
  2. Installation from source code

Installation from packages:

For RedHat Linux(or other Linux distributions which supports RPM) download subversion RPM package and install. See manual of rpm utility for installation.

For Debian Linux issue apt-get install subversion and by confirming the installation you are done. I also recommend to install subversion-tools by issuing apt-get install subversion-tools.

Installation from source:

Installation from source code is slightly tricky. First of all download latest version of subversion code from http://subversion.tigris.org.

Now extract source to your preferred directory (lets assume /home/testuser/svncode/), and issue the following command in sequence after switching to svncode directory:

  • ./configure
  • make
  • make install

./configure will create Makefile
make makes Subversion form the just-created Makefile
make install install Subversion if make is successfullyAnd you are done….

Issue svnadmin create /home/testuser/repository to create a new repository, this should create a directory structure like:

drwxrwxrwx   7 root root 4096 2006-11-07 17:18 .
drwxrwxrwx  14 root root 4096 2006-11-07 17:18 ..
drwxrwxrwx   2 root root 4096 2006-11-07 17:18 con
drwxrwxrwx   2 root root 4096 2006-11-07 17:18 dav
drwxrwxrwx   2 root root 4096 2006-11-07 17:18 db
-rwxrwxrwx   1 root root    2 2006-11-07 17:18 format
drwxrwxrwx   2 root root 4096 2006-11-07 17:18 hooks
drwxrwxrwx   2 root root 4096 2006-11-07 17:18 locks
-rwxrwxrwx   1 root root  379 2006-11-07 17:18 README.txt

Now we need to allow remote access to it so that users can import their files. By editing conf/svnserve.conf we can set user accounts, permissions.

Initially svnserve.conf looks like:

### This file controls the configuration of the svnserve daemon, if you
### use it to allow access to this repository.  (If you only allow
### access through http: and/or file: URLs, then this file is
### irrelevant.)
### Visit http://subversion.tigris.org/ for more information.
### [general]
### These options control access to the repository for unauthenticated
### and authenticated users.  Valid values are "write", "read",
### and "none".  The sample settings below are the defaults.
### anon-access = write
### auth-access = write
### The password-db option controls the location of the password
### database file.  Unless you specify a path starting with a /,
### the file's location is relative to the conf directory.
### The format of the password database is similar to this file.
### It contains one section labelled [users]. The name and
### password for each user follow, one account per line. The
### format is
### USERNAME = PASSWORD
### Please note that both the user name and password are case
### sensitive. There is no default for the password file.
### password-db = passwd
### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa.  The default realm
### is repository's uuid.
### realm = My First Repository

Uncomment line containing [general], anon-access, auth-access and password-db with suitable permissions. Also add file named passwd parallel to svnserve.conf containing

[users]SVNUSERNAME = SVNUSERPASSOWRD

You can add as many users you want. Now you are done with user accounts and permissions.

Next you have to start the svnserver by issuing svnserve -d -r /home/testuser/repository.

Now you are ready with your subversion server, you can access your repository from svn://yourdomain.com/repository/

On some systems (like Debian GNU/Linux) this requires to write an init script so that the server starts up every time the system is rebooted. This could be done by creating a file called svnserve in the /etc/init.d directory, and then editing it to look like the following example file:

#! /bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/svnserve NAME=svnserve DESC="SVN Repository Server Daemon"
test -x $DAEMON || exit 0
OPTIONS="-d -r /cvs/src"
# Get lsb functions
#. /lib/lsb/init-functions
. /etc/default/rcS start() {        echo "Starting $DESC... "
#       echo "Starting $DESC: "
if ! start-stop-daemon --start --quiet --oknodo --exec $DAEMON -- $OPTIONS
>/dev/null 2>&1; then
status=$?
echo $status
return $status
fi        log_end_msg 0
return 0
}
case "$1" in
start)
start
;;
stop)
echo "Stopping $DESC: "
start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
echo $?
;;
restart|force-reload)
$0 stop
sleep 1
start
#echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac exit 0

This script also allows to manually start and stop the svnserver service whenever needed. Note: be sure and change the OPTIONS line to reflect the location of your repository; in our previous example this location was /home/testuser/repository. Once this file is created and edited to look like the previous example, you need to chmod the script to be executable by issuing chmod +x /etc/init.d/svnserve and also set it to startup at boot time by issuing update-rc.d svnserve defaults

Now simply start/stop the service by issuing:

/etc/init.d/svnserve start/stop

Please refer Subversion book for more help and usage.

Deprecated FormTagHelpers

Following FormTagHelpers are deprecated and will be removed in Rails 1.2

  • start_form_tag (use form_tag instead)
  • end_form_tag (use </form> instead)

technorati tags: , , rubyonrails