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!

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

How to install WebMailCompose in Firefox 2.0

written January 15 2007 by
{ Joe }
Comments 129

Update

The plugin now also can be installed for Firefox 3.
If you want to contribute or donate, visit the development site.

In consequence of some obscurities which occurred related to the last article, here’s a little guide on how to install the WebMailCompose Plugin for Firefox 2.0.

This article is continued. Click to read more!

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.

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)

Building a herbal bed

written September 3 2006 by
{ Joe }
Comments 0

My herbal bed

A week ago I ran into a problem.
If you’re like me, you really like fresh herbs in your food. The smell of some fresh basil can lead me to total satisfaction.
Too bad if you’re living in Austria (like me) and want some on weekend. In Austria the shops are usually closed during weekend so I had no chance to get some last weekend. This made me really mad and angry, so I decided to break free from being dependent on the shops open hours (at least when I’m about to want fresh basil)..

Problem — Joe wants to have fresh herbs any time.


Solution — Joe has to build a small herbal bed in his garden.

Things you’ll need

The building process

First of all I thought about the form and size of the bed. I thought about steps (made out of mould) on which the herbs are arranged.

If there’s anything unclear or if you want to have more information on building a herbal bed, feel free to contact me via mail


(philipp [at] sparklingstudios [dot] com) or via comments.

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

You've reached the end of this page. Feel free to dig into the archives of this blog or subscribe to our newsfeed.