how to setup a new edge rails project with a geostack

Edgerails: If I want to run edgerails with all my geostack development tools it can get quite long winded. So I have tried to compile this post hoping to it will inspire me to create a script to automate it … something like railify which I forked from Nicolás Sanguinetti with that very intent. Also given that rails and several other projects are moving to git I decided to try the git submodules for tracking remote git repos.

To get edge rails working as a git submodule checkout this excellent post. Except I am going to grab edgerails from my local fork to save me time and money.


$ rails geostack -d postgresql
$ cd geostack/
$ cat /c/apps/Rails/templates/dot-gitignore > .gitignore
$ touch log/.gitignore
$ git init
$ git status
$ git add .
$ git commit -m "Initial commit"
$ cd /c/apps/Rails/_rails/
$ git pull origin
$ cd /c/NetBeansProjects/geostack/
$ git submodule add /c/apps/Rails/_rails/ vendor/rails
Initialized empty Git repository in c:/NetBeansProjects/geostack/vendor/rails/.git/

lets see what we did

$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD …” to unstage)
#
# new file: .gitmodules
# new file: vendor/rails

all good to commit and initialize the submodules

$ git commit -m "Use git submodules to track HEAD of local _rails repository."
Created commit 327f3b8: Use git submodules to track HEAD of local _rails repository.
2 files changed, 4 insertions(+), 0 deletions(-)
create mode 100644 .gitmodules
create mode 160000 vendor/rails
$ git submodule init
Submodule 'vendor/rails' (c:/apps/Rails/_rails/.git) registered for path 'vendor/rails'
git submodule update

Lets now get the plugins. Starting with spatial_adapter2 which I forked to add geo_scaffold (discussed later)

$ git submodule add git@github.com:sabman/spatial_adapter2.git vendor/plugins/spatial_adapter2
$ git commit -m "Import of spatial_adapter2 from github"

or if u don’t care about tracking it just do:

$ ruby script/plugin install git://github.com/sabman/spatial_adapter2.git

then ym4r_gm again 2 options:

$ git submodule add git://github.com/bitbckt/ym4r-gm.git vendor/plugins/ym4r_gm
$ git commit -m "ym4r_gm added"
or
$ ruby script/plugin install git://github.com/bitbckt/ym4r-gm.git

next the good old geokit

$ ruby script/plugin install git://github.com/ptb/geokit.git

finally seeing as I’m too slack to test unless its TDD we get rspec and rspec_on_rails.
First I update my local git fork of rspec and rspec-rails so we don’t have to keep cloning the huge remote repo

cd /c/apps/Rails/my_plugins/rspec
git pull
cd /c/apps/Rails/my_plugins/rspec-rails
git pull
git add .
git commit -m "update"
#Add git submodules for the local projects
git submodule add /c/apps/Rails/my_plugins/rspec vendor/plugins/rspec
git submodule add /c/apps/Rails/my_plugins/rspec-rails vendor/plugins/rpec_on_rails
git status
git diff --cached
git commit -m "Import the RSpec & Rspec-rails plugins' current HEAD as a submodule."
# and finalize
$ git add .
$ git commit -m "added required plugins"

next create a PostGIS database and setup database config

createdb -T template_postgis geostack_development -U postgres
development:
adapter: postgresql
encoding: UTF8
database: geostack_development
username: postgres
password: secret
test:
adapter: postgresql
encoding: UTF8
database: geostack_test
username: postgres
password: secret
production:
adapter: postgresql
encoding: UTF8
database: geostack_production
username: geostack
password:

… and my ugly hack to ensure our test database rake task create the correct database we are going to modify the default databases.rake file from rails. don’t look

$ find ./vendor/rails/ -type f -iname databases.rake | xargs -i cp {} ./lib/tasks/databases.rake.orig
$ sed 's/^.*`createdb .* -U "#{.*}"/& -T template_postgis /' ./lib/tasks/databases.rake.orig > ./lib/tasks/databases.rake
rm ./lib/tasks/databases.rake.orig

ok all done… geo_scaffold in action:

$ ruby script/generate geo_scaffold Hotspot name:string description:text location:point
mime_types Mime::Type.register "application/vnd.google-earth.kml+xml", :kml
mime_types Mime::Type.register "application/rss+xml", :georss
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/hotspots
exists app/views/layouts/
exists test/functional/
exists test/unit/
create app/views/hotspots/index.html.erb
create app/views/hotspots/show.html.erb
create app/views/hotspots/new.html.erb
create app/views/hotspots/edit.html.erb
create app/views/hotspots/index.kml.builder
create app/views/hotspots/index.georss.builder
create app/views/hotspots/show.kml.builder
create app/views/hotspots/show.georss.builder
create app/views/layouts/hotspots.html.erb
create public/stylesheets/geo_scaffold.css
create public/images/google_earth16x16.gif
create public/images/google_earth32x32.gif
create public/images/feed-icon16x16.png
create public/images/feed-icon32x32.png
create public/images/kml_icon16x16.png
create public/images/feed-icon16x16.gif
create public/images/bullet.gif
create public/images/header_backdrop.png
create public/images/Globe2.png
create public/javascripts/geo_scaffold.js
create app/controllers/hotspots_controller.rb
create app/helpers/hotspots_helper.rb
route map.resources :hotspots
dependency geo_model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/hotspot.rb
create test/unit/hotspot_test.rb
create test/fixtures/hotspots.yml
create db/migrate
create db/migrate/20080429142617_create_hotspots.rb
exists db/migrate
create db/migrate/20080429142618_add_index_to_hotspots.rb

Run migrations and go!

$ rake db:migrate
$ mongrel_rails start

And here is the result tada!
geoscaffold 4 index

1 Comment so far

  1. […] Following on from my last post where we created a mapping app using geo_scaffold I am going to show how to use cURL to play around […]

Leave a Reply