Jeff Rasmussen’s Healthcare IT Blog

October 18, 2006

Rails and Plugins

Filed under: Ruby — jrasmussen0 @ 10:00 am

dollars_and_cents: a Rails plugin | Archives | codablog | Coda Hale

I thought that Agile Web Development with Rails: Second Edition was going to repeat a lot of information from the first edition. I was wrong; the second edition updates a lot of techniques using conventions that have developed since the last book.

For example, one of the best ways to start a rails project is by using migrations. This book works with that and I assume even more. Personally the migrations section was well worth it. As an added benefit, I’m getting different information going through the depot example a second time because I understand how rails works and can understand better why the examples do this or that.

Quick notes: The book uses Edge Rails which I refused to install (my only problem with the book). The migrations model uses a :decimal call that is not available in rails 1.1.6 I was able to use my first rails plugin called dollars_and_cents. Radrails made the install very easy. The hard part was modifying the code to use this plugin.

Here is my notes:

Migration line: add_column :products, :price_in_cents, :integer, :default => 0

I ran ‘ruby script/generate scaffold Product’ which created a new products view. I used this code to modify the views and then copied them into the admin view.

list.rhtml:

<table>
<tr>
<% for column in Product.content_columns %>
<th><%= column.human_name %></th>
<% end %>
<th>Price</th>
</tr>

<% for product in @products %>
<tr>
<% for column in Product.content_columns %>
<td><%=h product.send(column.name) %></td>
<% end %>
<td><%=h number_to_currency(product.price)%></td>
<td><%= link_to ‘Show’, :action => ’show’, :id => product %></td>
<td><%= link_to ‘Edit’, :action => ‘edit’, :id => product %></td>
<td><%= link_to ‘Destroy’, { :action => ‘destroy’, :id => product }, :confirm => ‘Are you sure?’, :post => true %></td>
</tr>
<% end %>
</table>

_form.rhtml (replace the last couple lines with this):

<p><label for=”product_price”>Price in dollars</label><br/>
<%= text_field ‘product’, ‘price’ %></p>
<!–[eoform:product]–>

show.rhtml (abridged):

<% for column in Product.content_columns %>
<p>
<b><%= column.human_name %>:</b> <%=h @product.send(column.name) %>
</p>
<% end %>

<p>
<b>Price in Dollars:</b> <%=h number_to_currency(@product.price) %>
</p>

September 15, 2006

Mongrel and Capistrano

Filed under: Ruby — jrasmussen0 @ 2:25 pm

So ever since I noticed that I’ve been wanting to use Mongrel to run my Rails apps. For those not familiar with mongrel, it’s a Tomcat-style application host for rails apps that avoids (huzzah) the FCGI palaver that we ordinarily have to deal with.

Sketchpad » Blog Archive » Capistrano, Mongrel, and Mongrel_cluster

My notes to follow.

technorati tags:, ,

September 14, 2006

How I setup Subversion, Apache, and Capistrono

Filed under: Ruby — jrasmussen0 @ 1:45 pm
sudo vi/etc/apache2/mods-enabled/dav_svn.conf
--
#Comment out the following 2 lines with your repo path
#DAV svn <-Comment out this
DAV svn

#SVNPath /var/lib/svn <-Comment out this
SVNPath /var/local/svn

<LimitExcept GET PROPFIND OPTIONS REPORT>
#Require valid-user <-Comment this if you don't need basic authentication
Options Indexes
Order allow,deny
allow from all
</LimitExcept>

HOWTO : Subversion & Eclipse development environment – Ubuntu Forums

You should deviate from the above configuration if you are using this for rails development because otherwise you will allow for anyone to see your database password from the database.yml file. In fact, I wouldn’t be surprised if Yahoo or Google crawls the web repository and make the password searchable.

From here, I followed these instructions to get Capistrano started.

On the client, check out the app

svn checkout svn://svnserver.com/app1 (enter user and pass as needed)
cd app1

capistranize the app:

cap –apply-to app1

Now, to set up the app for capistrano deployment, configure deploy.rb(see example below) appropriately with the correct paths, servers,restart method to restart apache, etc.

On the client,

rake remote:exec ACTION=setup

This will setup the base structure ${deploy_to}/releases /current /shared

current is a symlink to the most recent release/YYYYMMDDHHMMSS/ directory. shared contains shared logfiles etc.

That should do it!

example deploy.rb used for app1 (comments removed):

##########

 

  1. set :application, app1
  2. set :repository, svn://svnserver.com/
  3. role :web, yourserver.com
  4. role :app, yourserver.com
  5. role :db, yourserver.com, :primary => true
  6. set :deploy_to, /home/rails/application_path/
  7. desc Restart the web server
  8. task :restart, :roles => :app do
  9. sudo /usr/local/etc/rc.d/apache2.sh restart
  10. end

#########

PS: apache has to point to /home/rails/application_path/current/public for this to function properly.

Quick guide to setting up svn, capistrano, apache and radrails – Rails Weenie

And here is how I set up my svnserve script for /etc/init.d/svnserve. I didn’t like trying to get inetd or xnetd to work. This is based off of the default one found in the same directory.

 

#! /bin/sh

### BEGIN INIT INFO

# Provides:          svnserve

# Required-Start:    $local_fs $remote_fs

# Required-Stop:     $local_fs $remote_fs

# Default-Start:     2 3 4 5

# Default-Stop:      S 0 1 6

# Short-Description: Subversion server

# Description:       This start svnserve on a particular port.  Others can

#                    access it using svn://servernam/.

### END INIT INFO

#

# Author:       Jeff Rasmussen <jeff.rasmussen at gmail.com>.

#

# Version:      @(#)svnserve     0.0.1  11-Sept-2006  jeff.rasmussen at gmail.com

#set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DESC="Subversion Server"

NAME=svnserve

DAEMON=/usr/bin/$NAME

PIDFILE=/var/run/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME

PORT=3690

REPOSITORY=/var/local/svn/

DAEMON_OPTS="-d --listen-port=$PORT -r $REPOSITORY"

# Gracefully exit if the package has been removed.

test -x $DAEMON || exit 0

# Read config file if it is present.

#if [ -r /etc/default/$NAME ]

#then

#       . /etc/default/$NAME

#fi

#

#       Function that starts the daemon/service.

#

d_start() {

start-stop-daemon --start --quiet --pidfile $PIDFILE 

--exec $DAEMON -- $DAEMON_OPTS 

|| echo -n " already running"

}

#

#       Function that stops the daemon/service.

#

d_stop() {

start-stop-daemon --stop --quiet --pidfile $PIDFILE 

--name $NAME 

|| echo -n " not running"

}

#

#       Function that sends a SIGHUP to the daemon/service.

#

d_reload() {

start-stop-daemon --stop --quiet --pidfile $PIDFILE 

--name $NAME --signal 1

}

case "$1" in

start)

echo -n "Starting $DESC: $NAME"

d_start

echo "."

;;

stop)

echo -n "Stopping $DESC: $NAME"

d_stop

echo "."

;;

#reload)

#

#       If the daemon can reload its configuration without

#       restarting (for example, when it is sent a SIGHUP),

#       then implement that here.

#

#       If the daemon responds to changes in its config file

#       directly anyway, make this an "exit 0".

#

# echo -n "Reloading $DESC configuration..."

# d_reload

# echo "done."

#;;

restart|force-reload)

#

#       If the "reload" option is implemented, move the "force-reload"

#       option to the "reload" entry above. If not, "force-reload" is

#       just the same as "restart".

#

echo -n "Restarting $DESC: $NAME"

d_stop

# One second might not be time enough for a daemon to stop,

# if this happens, d_start will fail (and dpkg will break if

# the package is being upgraded). Change the timeout if needed

# be, or change d_stop to have start-stop-daemon use --retry.

# Notice that using --retry slows down the shutdown process somewhat.

sleep 1

d_start

echo "."

;;

*)

echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2

exit 3

;;

esac

exit 0

technorati tags:, , ,

August 22, 2006

RadRails and Subversion

Filed under: Ruby — jrasmussen0 @ 6:27 am

Integrating Subversion and RadRails

I just spent a time while figuring out how to integrate RadRails and Subversion, and thought I’d share a tidbit in the hope it saves others time. I installed Subversion, created a repository under C:/repository, created a project called edu20 using svnadmin, and then started the lightweight subversion server by typing:svnserve -d –listen-port 3690 -r repositoryFrom RadRails, I selected Window>Show View>other>SVN>SVN Repository, which then displays a SVN window at the bottom of the screen. Then I clicked the + button which allows you to enter the URL of an SVN repository. The trouble is, it wasn’t obvious what this URL should look like. After googling for information and some trial and error, I discovered the magic incantation is:svn://localhost/edu20/trunkIn other words, the protocol is svn, the next part is the host name, and the last part is the path from the repository root to the trunk of the project. I hope this helps someone! Graham Glass, etc., August 17, 2006. [Conversation]

Integrating Subversion and RadRails | Technology4Teachers.com: Google Cache

technorati tags:, ,

Older Posts »

Blog at WordPress.com.