Ruby, Rails and MS SQL server
Setting up Rails and Ruby to use MS SQL server was always painful task. Fortunately things have changed – a lot! With new Rails SQL Server 2000, 2005 and 2008 Adapter and Christian Werner’s ruby-odbc gem you can do it in a few minutes.
If you want to use these gems on Windows grab Ruby installation from RubyInstaller site and be sure to install DevKit prior to installing ruby-odbc.
Versions of ruby-odbc before 0.9999 do not work on mingw based (RubyInstaller) Ruby. Luckily author was very fast and made new version very quickly after I sent him a patch. Thanks Christian!
Both gems work well on Ruby 1.8.6 and 1.9.1 Ruby versions on Windows with old ActiveRecords, but I hope rails adapter will be ported to ActiveRecords 3 soon.
Easy Emacs
First step
In my previous articles I wrote a lot about Emacs, its customization and adjusting it for Ruby and Ruby on Rails development. Although these articles give detailed instructions how to set everything up, following all steps are somewhat cumbersome and require quite a lot of work.
Fortunately there is a solution. Just clone Emacs starter kit from Github and you will be able to develop Ruby and RoR applications in Emacs in just a few simple steps. Emacs starter kit uses Elpa packaging and is very easy to configure. But let’s start from the beginning.
Clone Emacs starter kit with Git, to your empty .emacs.d directory. Be sure that init.el file is in .emacs.d folder. If you do not use Git (do you realize what you are missing?) you can get archived sources if you press download button on Emacs starter kit page on Github. Unpack archive to the .emacs.d and be sure that init.el is in .emacs.d folder.
Emacs starter kit has some packages that are still not in Elpa but you’ll have to install additional packages required for Ruby and RoR. Let’s do it now:
1 |
M-x package-list-packages |
New buffer with list of available packages will open and you can select those you want to install. If you plan to use Emacs for Ruby and RoR you’ll definitely need Rinari. It will install all dependent packages.
There are few other that might come in handy like css-mode, javascript or yasnippet but you can always add them later. If you install yasnippet you should probably need yasnippets-rails, but more about that later. Installing packages is very easy. Just place cursor on the package line and press ‘i’. When you are finished with selection press ‘x’ and packages will be installed. At any time you can press ‘h’ to get quick help for Elpa packaging system. In order to uninstall package you have to press ‘d’ (and ‘x’ after that).
Further customization
When you are done with packages installation just restart Emacs and you are ready to continue work in your favorite language – Ruby and framework – Ruby on Rails :) But what if you want to adjust some settings or keep some of those you set according to my previous articles? Luckily that is easy to do, too.
First create sub-directory in .emacs.d directory with your user name on the system you are using. Put your .el files there and Emacs starter kit will load them automatically during Emacs start up. If you have changed color theme and you’ve used theme from color-theme library put color-theme-library.el in this folder and add, for example, line
1 |
(color-theme-deep-blue) |
to any of .el files in this folder. I keep all my additional settings in customization.el file.
I already mentioned yasnippet and yasnippets-rails packages. Simplest way to install yasnippet library is from Elpa system following above mentioned procedure. Unfortunately yasnippets-rails cannot be installed that way so you should clone it from the Github:
1 |
git clone git://github.com/eschulte/yasnippets-rails.git |
Directory yasnippets-rails should be in the directory with your user name under .emacs.d. Add following lines to your customization.el file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
(add-to-list 'load-path
(concat dotfiles-dir "/<user-name>/yasnippets-rails"))
(add-hook 'ruby-mode-hook ; or rails-minor-mode-hook ?
'(lambda ()
(make-variable-buffer-local 'yas/trigger-key)
(setq yas/trigger-key [tab])))
(require 'yasnippet)
(add-to-list 'yas/extra-mode-hooks
'ruby-mode-hook)
(yas/initialize)
(setq yas/window-system-popup-function 'yas/x-popup-menu-for-template)
(yas/load-directory (concat dotfiles-dir "/<user-name>/yasnippet/snippets"))
(yas/load-directory
(concat
dotfiles-dir "/<user-name>/yasnippets-rails/rails-snippets/"))
(make-variable-buffer-local 'yas/trigger-key)
|
and you will be ready for using new snippets during development.
Final word
My previous articles were based on Rails reloaded package for RoR development in Emacs. It is good library and if you like fancy GUI things you can still use it. There is a new version on Github.
Still, I would recommend trying Rinari that is a package from Elpa. It doesn’t have any GUI features but once your fingers “learn” all shortcuts your RoR development will be much easier and faster.
PDN powered by RoR
It has been a few months since my last post on the old blog powered by Wordpress. All this time I was searching for a blog engine made in Ruby on Rails. It was not easy to decide what to use. I’ve tested Mephisto, Typo, Radiant, Simplelog and several others I cannot remember now. All of them really have a lot of features, but for my needs they are way too complex. What I was searching for is some simple application that I can easily tweak and adjust to my needs. I was about to move to Mephisto or Simplelog when I found Enki.
As soon as I’ve looked into the code I knew that it is the one. Simple, lightweight blogging engine without fancy stuff that I’ll rarely use, yet with all features I need for my own blog. Moreover Enki’s source is on Github and it was easy to make a fork and start to work on my own version. So I did it. I must say it can be used just as it is, but I wanted to give it a new “look and feel”, so I’ve started with changes on a style sheet and didn’t stop there.
Enki handles comments in a very flexible way. In order to post a comment only name and text of a comment must be filled. On the other hand, if commenter wants to give a little bit more data he can use OpenID authentication. Nowadays with all those spammers around, this was not good enough for me. I didn’t want blog overloaded with bunch of stupid messages so I’ve decided to change comments handling a little bit.
There are lot of ways to protect a blog from spam. You can forbid posting comment without authorization. That way everyone must register before he is allowed to post a comment. That’s too much work for commenter and, frankly speaking, for me too. I wanted to make commenting as simple as possible, still under decent level of control. In order to accomplish it I could use reCAPTCHA or Akismet. Both of them are quite good, but I’ve decided to use Akismet. It leaves commenter same level of simplicity as in the original Enki source but every comment must pass spam filter. So I’ve dropped OpenID authentication, downloaded akismet.rb, adjusted comments controller and fixed tests. It was quite simple and easy.
And here it is up and running.
Finally few thoughts about Enki. Although it can be used out of the box, I think very few users will actually install it that way. But if you are RoR fan, and you like to work in Ruby and Ruby on Rails this is the right choice for you. Code is readable and easy to change. It is not over-engineered except in one part – gems. Enki requires cucumber which, on the other hand, requires rspec, rspec-rails, webrat and, optionally, term-ansicolor, nokogiri, builder and few others. For my mind it is a little overhead for such a simple project, but it is definitely neglectable comparing to other good sides of Enki. Lack of support for images uploading might be a limitation in Enki’s usability, but author wanted to keep it simple so this shouldn’t stop you from using it. At the end if you like Ruby on Rails it will be a fun implementing support for it, isn’t it? Go ahead, grab attachment_fu or paperclip and do it.
