Rails 2 + Merb 1 = Rails 3

written December 24 2008 by
{ Kommen }
Comments 1

I recently heard some whispers that Rails and Merb are going to be merged and the result should be call “Rails 3”. I simply couldn’t believe it–at least until the bombshell dropped on blogs and on twitter.

Enough has been written on what this is all about so I won’t duplicate it here–just my 2 cents.

Overall, I think this is a huge thing for the ruby community. I always had an eye on Merb and considered it more than once for a new project. Main reason: Performance. However, I never made the move. So I’m happy to see that all the corner stones of Merb are going to hit Rails’ code base soon. Besides the performance stuff, I’m looking forward to have a stable API for plugins. This should make it a lot easier and less work to maintain plugins for Rails.

To quote David:

Rails 3 is going to kick ass.

timed_fragment_cache for Rails 2.2

written December 24 2008 by
{ Kommen }
Comments 1

The current version of timed_fragment_cache from Richard Livsey is not yet compatible with Rails 2.2.

I’ve added a patch to my fork of the plugin on github, which makes it compatible with Rails 2.2 by using the new output_buffer method instead of a binding.

Note that the change breaks compatibility with earlier versions of Rails. So use my fork only with Rails 2.2 or later.

You can find the code here: timed_fragment_cache

Textmate Filetype Detection with RSpec and Rails Bundles

written May 24 2008 by
{ Kommen }
Comments 0

A thing which annoyed me for a long time since switching to RSpec was the
incorrect recognition of RSpec and Rails files.
If you told TextMate to use the RSpec bundle for the spec files, it also used
it for the Rails files.

Now I found the solution for this on the TextMate blog:
http://blog.macromates.com/2007/file-type-detection-rspec-rails/

Check Rails Applications For Rails 2.0 Compatibility

written September 23 2007 by
{ Kommen }
Comments 0

Mislav just posted this in #rails-contrib on irc.freenode.net: Pastie

This little script checks your existing Rails application for Rails 2.0 compatibility. Should be very useful for everyone
who wants to upgrade and use the latest and greatest Rails features.

It will give you rough clues about where you have to get your hands on.

Akismator — The Better Way To Protect a Rails App Against Spam

written September 16 2007 by
{ Kommen }
Comments 1

As I wrote some time ago, we protect our blog with Akismet against spam.

For those who don’t follow Ryan Bates’ Railscasts (I really suggest to do so) I want to introduce Akismetor. It’s a small library that simplifies the use of Akismet. I really recommend watching this free screencast about how it works or alternatively you can read the Akismator README.

3 Years Ruby on Rails

written July 30 2007 by
{ Kommen }
Comments 0

Today 3 years ago, DHH released Rails to the public.

http://flickr.com/photos/lclark0621/868120928/

Happy Birthday Rails and thanks to all contributors to make me enjoying web development so much!

Ostrova on Rails Photos

written June 22 2007 by
{ Kommen }
Comments 0

Joe and I currently are in Ostrava on the Ostrava on Rails Conference.

The first day of the conference (where all presentations were in english) is over. Tomorrow there will be presentations in czech. Today 10pm there is a party in the city center of Ostrava. Luckily the party is just a few meters away from our hotel. :-)

Here is the photostream from the arrival and the conference: http://flickr.com/photos/unkai/sets/72157600421346067/

RadRails or Emacs?

written February 24 2007 by
{ Kommen }
Comments 3

The last RadRails version 0.7.2 was released 3 months ago and it seems the RadRails-Team members are spending their time on other things. RadRails isn’t feature complete yet and there are still many bugs bugs waiting to be fixed.

And honestly, I don’t like to work with software, which needs some work but isn’t under maintenance/development any more.

So I (again) took a look at other Rails editors/IDEs to try out. After playing around with vim and emacs I decided to give emacs a try.

This article is continued. Click to read more!

Text-Link-Ads Plugin For Ruby On Rails

written February 12 2007 by
{ Kommen }
Comments 7

As Joe wrote in the article about our shiny new blog, he mentioned that we now use Text-Link-Ads for doing advertising on our blog.

Text-Link-Ads provide some adcode for Ruby On Rails applications, but using their code is not as convenient as it could be. Also, I had problems with some parts of it:
It seems that they overwrite a Rails method (request) which meshes up the application until you rename it.

I did some modifications to the adcode so I could use it more easily in the system. Then I extracted the code and created a Rails plugin. This plugin I want to share.

This article is continued. Click to read more!

Resoaked. Resoaped.

written February 6 2007 by
{ Joe }
Comments 2

Resoaked. Resoaped.
soaked and soaped has redesigned. What you see in front of you is a new layout paired with everything Rails 1.2 offers for us programmers.

This article is continued. Click to read more!

Two Excellent RadRails Tutorials

written January 29 2007 by
{ Kommen }
Comments 1

I just want to highlight two very well written and helpful RadRails tutorials posted on the radrails.org blog:


Rolling with Ruby on Rails
and How To Setup/Configure Eclipse SQL Explorer Plugin

Administrate SQLite Databases from RadRails

written November 5 2006 by
{ Kommen }
Comments 2

Recently, when I switched from Ubuntu Dapper Drake to Edgy Eft, I also had to set up my development environment again.
This time I decided to use SQLite3 for Rails development on my notebook instead of MySQL.

I used to administer my databases with phpMyAdmin or with the Data Perspective in RadRails. Now my problem was, that the SQLite JDBC driver which RadRails uses sucks and the Data Perspective wont work.

So I looked for a solution to easily manage the SQLite databases from my projects with RadRails.
Here it is:

Install rSQLiteGUI

rSQLiteGUI is a very simple but useful graphical interface to manage SQLite databases written in Ruby and using GTK2.

To install it, just download the latest version from here and extract the archive to a directory. Make sure rsqlitegui.rb is executable.

Configure RadRails to work with rSQLiteGUI

In RadRails you can define File Associations. So associate the *.db files with rSQLiteGUI:

Done! Now you can view or edit a SQLite database just double clicking on it in the Rails navigator.

The Rails Way

written November 1 2006 by
{ Kommen }
Comments 0

I just came across a new interesting site: The Rails Way


From the About:

The Rails Way is all about teaching “best practices” in Rails application design. It is run by Jamis Buck and Michael Koziarski, both of whom are members of the Rails core team and have had extensive experience with both designing and building web applications.

How To Protect A Rails Application Against Spam with Akismet

written October 1 2006 by
{ Kommen }
Comments 75

Spam is more and more a problem for many sites. And there are many approaches to fight spam. One is Akismet.

Akismet is a collaborative effort to make spam a non-issue. While there are Akismet plugins for Typo, WordPress, etc. you have to do some work to use it in your own application.

In this article I will demonstrate how to use Akismet in your own
Rails application to protect it against spammers. As example I will use comments, e.g in a weblog.
I’m assuming you already have your blog up and running, and want to add spam protection with Akismet.

Get an Akismet key

Akismet is free for personal use. But for using it, you have to get a key. Either a commercial or a personal one.
So go to http://akismet.com/ and get one.
For the personal one you will get redirected to the WordPress signup. If you just
want the key for your application, choose the option Just a username, please..

After submitting the form, you’ll get an activation email. Click on the link in the email
to verify your email address. Then you will get another email, which contains your
user data and your Akismet key labeled with API Key:.

Get the Akismet API for Ruby

David Czarnecki has written a Ruby interface that you can use in your application to easily access the Akismet API.
Download the akismet.rb file from here:
http://soakedandsoaped.com/files/akismet.rb
and put it in the lib directory from your Rails application.
The filename has to be akismet.rb. (case sensitive!)

Create a little helper function

In your controller write a little helper function that checks comments for spam.
This could look like this:

 1 
 2   protected
 3   
 4   def check_comment_for_spam(author, text)
 5     @akismet = Akismet.new('< your Akismet key here>', '<your blog url here>') # blog url: e.g. http://sas.sparklingstudios.com
 6     
 7     # return true when API key isn't valid, YOUR FAULT!!
 8     return true unless @akismet.verifyAPIKey 
 9     
10     # will return false, when everthing is ok and true when Akismet thinks the comment is spam. 
11     return @akismet.commentCheck(
12               request.remote_ip,            # remote IP
13               request.user_agent,           # user agent
14               request.env['HTTP_REFERER'],  # http referer
15               '',                           # permalink
16               'comment',                    # comment type
17               author,                       # author name
18               '',                           # author email
19               '',                           # author url
20               text,                         # comment text
21               {})                           # other
22   end

Call the method before saving a comment

Your create method could look like this:

 1 
 2   def create
 3     @comment = Comment.new(params[:comment])
 4     unless check_comment_for_spam(@comment.author, @comment.comment_text)
 5       if @comment.save
 6         flash[:notice] = 'Comment was successfully created.'
 7         redirect_to :action => 'list'
 8       else
 9         render :action => 'new'
10       end
11     else
12       # Spam detected! Do something with the spammer.
13       flash[:notice] = 'Go away!'
14       render :action => 'new'
15     end
16   end

Test your spam protection

You can test your spam protection by trying to create a comment with author set to viagra-test-123
Akismet should always say that this is spam.

You’re done! Akismet is now watching at your comments and blocks spammers!

Help Akismet

Note that you can submit spam also! Use the submitSpam function of the API.

Ressources

Tutorial Competition: Multiple Models in One Form

written September 27 2006 by
{ Kommen }
Comments 0

Ryanb has posted two tutorials in which he explains how to create and edit two models at the same time in one form.
In his example the models are releated with _has_many_ and _belongs_to_.

Creating Two Models in One Form


and


Editing Multiple Models in One Form

Tutorial Competition: Refactoring on Rails: Move to Model

written September 26 2006 by
{ Kommen }
Comments 0

This article shows how to refector your Rails application by moving some code from the view to the model.
Ryanb also explains how to use Unit Tests for that process to ensure nothing gets broken while cleaning up the code.

See the complete article here

Tutorial Competition: Make A Rails Plugin From Scratch

written September 23 2006 by
{ Kommen }
Comments 0

Yesterday danger posted a nice tutorial about writing your own Rails plugin.
I found that very useful, because I didn’t know how easy it is to write your own plugin.
And I think it’s interesting for everybody else who wants to write his own one.
Here is the link:

http://railsforum.com/viewtopic.php?id=682

Tutorial Competition at railsforum.com

written September 19 2006 by
{ Kommen }
Comments 0

The railsforum.com admin-team has announced a tutorial competition. The one who posts the best tutorial there until November 1st, wins an new iPod shuffle with 1 GB space.

For more details read the announcement.
I’m looking forward to see some good tutorials.

Parse natural language date/time strings in Ruby with Chronic

written September 14 2006 by
{ Kommen }
Comments 1

Yesterday, while fighting against spam on the Ruby on Rails wiki, I came over a nice gem: Chronic

With Chronic you can easily parse natural language date and time formats into a DateTime object. You don’t have to mess around with regex to parse things manually. As gem, it’s easy to install and it’s also very handy to use.

Install it

$ gem install chronic
Thats it.

Use it

Put this in your model or controller file:


require 'chronic'


Then you can use Chronic.parse in your methods. E.g. Chronic.parse('tomorrow'),
Chronic.parse('monday', :context => :past), Chronic.parse('this tuesday 5:00')

Or more complex: Chronic.parse('3rd thursday this september'), Chronic.parse('3 months ago saturday at 5:00 pm')

And of course it can do a lot more! For a complete reference and more examples see chronic.rubyforge.org

Validate with it

 1 You can also use Chronic to validate malformed date strings:
 2 
 3 class Meeting < ActiveRecord::Base
 4 
 5   def validation
 6     errors.add :meeting_date, 'is not a valid date' if Chronic.parse(meeting_date.to_s).nil?
 7   end
 8 
 9 end

Ressources (Sites I’ve looked at and borrowed the code snippets) for writing this article

Install Mongrel on Ubuntu 6.06 Dapper

written September 13 2006 by
{ Kommen }
Comments 13

As I mentioned in my last post, RadRails 0.7.1 now supports Mongrel. So I decided to use Mongrel instead of Webrick for development on my notebook. But it was a bit tricky and took me a bit of googling to get it.

As Joe wrote in his post about installing Mongrel on MacOS X, I’ll describe how to install it on Ubuntu, assuming you already have Ruby and Ruby on Rails up and running.

Because Mongrel is partly written in C/C++ for more performance, you have to install the build-essential package. It will install all needed packages so that you can compile C/C++ applications.

sudo apt-get install build-essential
(You can also use the synaptic package manager to install it, if you prefer a GUI)

You also need the @ ruby1.8-dev@ package. When you try to install Mongrel without this installed, it will complain with this errormessage:
extconf.rb:1:in `require’: no such file to load — mkmf (LoadError)
from extconf.rb:1

Install the package with this command:
sudo apt-get install ruby1.8-dev

Then just use gem to install Mongrel:
sudo gem install mongrel —include-dependencies

Gem will ask you, which version of Mongrel you want to install. Choose the latest ruby verion.
Then you’ll see some output from the C/C++ compiler.


Ok, you’re done! Now you can start the server with mongrel_rails in your Railsapp directory.

NOTE: Even without the build-essential package installed, Mongrel will install and say that installation was successful. But when you try to start the server, you’ll get an error message like this:
** Starting Mongrel listening at 0.0.0.0:3000
/usr/local/ruby-1.8.4/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3/lib/
mongrel.rb:666:in `register’: undefined method `resolve’ for
nil:Mongrel::URIClassifier (NoMethodError)

RadRails 0.7.1 released

written September 11 2006 by
{ Kommen }
Comments 0

For the case you missed it: 2 days ago the RadRails team released version 0.7.1 of their Rails IDE.

I just downloaded it. (the “Update RadRails..” function didn’t work in the old 0.7)
There are some new features and a lot of bugfixes.

The most important features (for me)

See the full announcement here: http://www.radrails.org/blog/2006/9/9/radrails-0-7-1

Notice that they also relaunched their website. There is a community section now.

Migrations in Ruby on Rails

written September 5 2006 by
{ Kommen }
Comments 8

This is all about how to use Migrations in Ruby on rails to make your work even more productive.

I’m developing with Ruby on Rails since 8 month now, coming from Java and PHP.
But only a few days ago I discovered one powerful feature of Ruby on Rails: Migrations.

I think there are a lot of others (like I was) who develop with Rails, but don’t know how to use migrations and how helpful they are.

For those, here is a litte introduction.

This article is continued. Click to read more!

railsforum.com - A Ruby on Rails community

written September 2 2006 by
{ Kommen }
Comments 0

3 weeks ago I read about railsforum.com.


I signed up and joined the community. Currently railsforum.com has 415 members. When I registered, there were about 300. There are a lot of people who read and write on a daily basis.
It’s a small, but friendly and helpful community. You can get answers to trival and also to more complex questions.

Join today if you’re interested and give it a try.

Installing Mongrel on OS X

written September 1 2006 by
{ Joe }
Comments 1

A few days ago I began working on a design for the “soaked and soaped”-blog. Webrick seemed a bit slow for working offline on an app like Typo so I decided to give mongrel a try.

After installing it via RubyGems…
$ sudo gem install mongrel

.. I quickly realized that something went wrong during installation.
I tried to start mongrel in my RailsApp directory but all that happened was getting an error message that HttpHandler doesn’t exist.

I googled a bit and finally found this.

It says that the mongrel installation routine needs a programm called ginstall to work proper. Bad luck, Mac OS X has no program called ginstall, but one which is called install and which resides on another location than ginstall.

So all you have to do, do get mongrel running on OS X is:

1. Uninstall it (if you have already installed it).
$ sudo gem uninstall mongrel

2. Set a symbolic link from the “install”-command to the place, the install script wants to have a program called “ginstall”.
$ sudo ln -s /usr/bin/install /opt/local/bin/ginstall

3. Install mongrel again via RubyGems
$ sudo gem install mongrel

4. After installation is complete, switch into your railsapp directory and start mongrel.
$ cd your/railsapp
$ mongrel_rails start

Exception Notifier - Ruby on Rails plugin

written August 31 2006 by
{ Kommen }
Comments 26

Yesterday I came over Exception Notifier.

I found it really useful because it is really easy to install and you can instantly react to Application Errors. Your customers don’t have to notify you because you get a bunch of information to track the error via email.

This article is continued. Click to read more!
You've reached the end of this page. Feel free to dig into the archives of this blog or subscribe to our newsfeed.