Rails3 and Datamapper quick start May 21st, 2010
Rails3 is almost released and I decided to try it out with Datamapper to see how things work. Things work AWESOME!
Here's a rundown of the steps I used:
gem update --system # you need rubygems >= 1.3.6
git clone http://github.com/rails/rails.git
cd rails
rake install
cd ..
rails my_dm_rails3_app -m http://github.com/jeremyd/rails-templates/raw/master/dm_rails_master.rb
cd my_dm_rails3_app
bundle install
Note: I cloned snusnu's repository here and modified to install a Gemfile that uses prerelease rubygems instead of git repository checkouts. This seems much faster and there were less dependency problems for me..vim ctags goto definition and omni-complete August 16th, 2008
When you're reviewing or writing lots of code, it helps to have a sharp tool. I prefer to write ruby and just about everything else in vim since it's available on all platforms and I'm constantly switching from platform to platform (mostly Linux and OSX these days though).
Vim is a great, lightweight, powerful editor with all the features that any other editor can provide (yeah, even the famed textmate has nothing vim doesn't have). The steps below can get you going at a birds eye view.
1) compile vim with ruby support (if you don't already have it). To see if ruby support is enabled type 'vim --version' and look for "+ruby". If you see "-ruby" then ruby support is not enabled.
2) install ctags (via apt-get or ports). You can run it in your project's directory and jump-to-definition will start working:
ctags -R --exclude=*.js
3) install the rails-vim plugin into ~/.vim
4) cook up a great .vimrc
set smartindent
let g:rails_menu=2
set viminfo^=!
colorscheme desert
syntax on
set path=~/myproject/trunk/**
set tabstop=2
set expandtab
set shiftwidth=2
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
VIM commandsJump to tag (ie: go to definition of the method under your cursor)
Control + ]
Bring up the OMNI complete window in insert mode
Control+X Control+O
acts_as_serializable March 15th, 2008
You heard it here first folks. Acts_as_serializable is making it's public debut today! Yes it may be horrifically stuck in a brain twister of recursion that could bring your server to it's knees when used improperly, AND THAT'S why I feel it is finally READY.
Are YOU ready? Here we go:
script/plugin install http://svn.rubyonlinux.org/acts_as_serializable/trunk
Haha, I know no one is even reading this. That's ok because I need someone to help me finish coding it first :) It's really coming along though! Even as I'm writing this, I would describe it to you but instead I'm going to work on the documentation and tests.
...
OK, I think the way I was approaching it was too crazy. I think this serializable thing is better suited to be some kind of helper like the TestFactory. Mocks etc should be used to stub out required relationships. Building a generic solution is way less effective than teaching how to export your data serialized in yaml form (custom).
Example:
..coming soon
If what you see in the SVN interests you, drop me a comment.
Textmate style rails plugins for VIM. October 11th, 2007
"Textmate is cool, but VI is forever"
Here's how to get some textmate like potential out of VIM using plugins.
I have the following plugins installed: project.vim, genutils.vim, rails.vim, multvals.vim, rubycomplete.vim and surround.vim.
non-insert mode
| what to type | what it does |
| :help surround | shows help for the surround plugin |
| yss= | surrounds the current line with <%= %> |
| yss CTRL-E | turns the current line into a block <% -%>newline char<% end -%> |
| yss- | surrounds the current line with <% -%> |
| CTRL-X CTRL-O | brings up the OMNI complete window for the current object/method |
| ysse | creates an ending for the current block. ie: an 'end' or closing brace |
| CTRL-G e | creates an ending for the current block. use in insert mode |
| what to type | what it does |
| :help surround | shows help for the surround plugin |
| CTRL-G = | surrounds the current line with <%= %> |
| CTRL-G CTRL-E | turns the current line into a block <% -%>newline char<% end -%> |
| CTRL-G - | surrounds the current line with <% -%> |
| CTRL-X CTRL-O | brings up the OMNI complete window for the current object/method |
| CTRL-G e | puts an 'end' on the next line |
Generating KML / XML on the fly in Ruby on Rails June 7th, 2007
KML can now be used both in Google Maps and Google Earth.
I wrote a simple KML generator using Builder and Rails.
I also used an RSS parser to read geographic coords from an RSS feed which is in use now at Baleen.org, but that is a code story for another day..
I wanted to post some code snips from the project, cause it's cool.
The view "kml.rxml"
xml = Builder::XmlMarkup.new(:indent => 2)
xml.instruct! :xml
xml.kml( "kmlns" => "http://earth.google.com/kml/2.1" ) do
xml.Document {
xml.name("someplaces")
xml.description("someplaces.org locator")
xml.Style( "id" => "highlight" ) {
xml.IconStyle {
xml.Icon {
xml.href("http://URL to transparent 32x32 png image.png")
}
}
}
Place.find_all.each do |p|
xml.Place {
xml.name(p.tooltip)
xml.description {
x=p.popup.dup
xml.cdata!("#{x.slice!(1..250)}<br><a href=#{p.ext_url}>..Read more</a>")
}
xml.styleUrl("#highlight")
xml.Point {
xml.coordinates("#{p.x},#{p.y},4")
}
}
end
}
end
In the controller, you must specify the following headers.
def kml
render_without_layout
@headers["Content-Type"] = "application/vnd.google-earth.kml+xml kml; charset=utf-8"
@headers["Content-Disposition"] = "attachment; filename=someplaces.kml"
end
Here is the migration I used: "001_create_places.rb"
For storing latitude/longitude and a few other useful Google Earth / Maps data to be used in the KML
class CreatePlaces < ActiveRecord::Migration
def self.up
create_table :places do |t|
t.column :x, :string
t.column :y, :string
t.column :ext_url, :string
t.column :tooltip, :string
t.column :popup, :text
end
end
def self.down
drop_table :places
end
end
Use a route to behave as a downloadable file.
map.connect '/someplaces.kml', :controller => 'places', :action => 'kml'
That's all you need to start generating KML on the fly with Rails. Have fun!Bonus Code !! Example Javascript for Google Maps API that loads up KML from an URL.
var geoXml = new GGeoXml("http://URL to someplaces.kml");
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.12755479789267,-112.7487179140864),3);
map.setMapType(new GMapType([G_SATELLITE_MAP.getTileLayers()[0]], G_NORMAL_MAP.getProjection(), "test", {}));
map.addOverlay(geoXml);
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
}
}
Also, make sure you have 2.x as the version string where you delcare the Javascript, otherwise your placemarks might go missing!
<script src="http://maps.google.com/maps?file=api&v=2.x&key=YOURKEY>
Leave a comment if this tutorial helped you. Thanks!
Rails Conf was crazy! May 20th, 2007
My mind feels like a flat tire with a buncha fix-a-flat pumped in at 60 miles an hour right now. I can't help but sit here try to blurt out some useful info. Took lots of notes, which I need to organize.
Here are some cool links
Sweet site, IRC bot grabbed a buncha good quotes and links from #railsconf during the conference. Reading it is a great re-cap if you attended the whole thing. The quotes are priceless (and very spot on).
Ni.hili.st
O'Reilly's official wiki
presentation slides
Also worth noting.. There was a lot of sponsored talks/discussion around GlassFish3 which is Sun's much hyped name for Java EnterpriseEdition (latest version). They made it sound really cool but later when I did some research it seemed to me that it's not as cool as you might think. Running jruby w/rails instead of ruby (native), while a novel idea, is only useful if you can't install anything except for java (literally, if you can't install ruby even tho it would compile, install and run fine because of company policy and pre-existing support contracts).
Do not be fooled by the jRuby hype!! Go ruby 2.oh and Yarv!!
Netbeans sounds like it might be a cool editor.. However, the Sun guys at the booth made it sound like it wasn't too super close to release.. Early next year would be my guess. If anyone wants to check it out, I got this link from a Sun dude for the daily builds etc. You cannot download Netbeans 6 from the official Netbeans site.
here's the secret netbeans dashboard url
Thank you Rails Conf. It's been real.
Rails conf 2007! May 16th, 2007
Woo! Rails Conf this weekend here in Portland, Oregon. I'm so excited my company paid for us to go to this. I've been working on some stuff for Baleen.org that I'll be making a post about here soon. They are riding their bikes to Costa Rica for the SOS children's villages. I've programmed up some rails XML magic to read in RSS and output KML for a google map/earth that tracks their current location. Pretty cool, cause I'm such an XML junkie. Anyway, I'm going to post some snippits from this for all you XML/KML fans out there.