detecting bots by user-agent in rails

First i thought using the browser-gem and would give me the correct answer. But somehow it did not work. So i am now using this litte snippet to detect bots.

class BotDetection

    matches = nil
    matches = agent.match(/(facebook|postrank|voyager|twitterbot|googlebot|slurp|butterfly|pycurl|tweetmemebot|metauri|evrinid|reddit|digg|sitebot|msnbot|robot)/mi) if agent
    return (agent.nil? or matches)


In my Base-Controller:

def bot_request?
  uAgent = request.env["HTTP_USER_AGENT"]

A list of user-agents may be found at

ActiveRecord disallow changes using unchangeable validation

Not allowing changes to be made to e.g. the login of the user only by the UI is in my eyes not enough.
The model should also ensure, that changes cannot be made once assigned.

So i tried to find an validation that does this for me.
But the once i found did not quite work as i expected.

So i wrote my own that i want to share:

class User < ActiveRecord::Base
  validates_unchangeable :login


require 'active_support/concern'
require 'active_model'
require 'active_record/base'

module UnchangeableValidation
  extend ActiveSupport::Concern

  class UnchangeableValidator < ActiveModel::EachValidator

    def initialize(options)

    def validate_each(object, attribute, value)
      if(!object.new_record? && value.present?)
        abChanged = attribute.to_s + "_changed?"
          object.errors[attribute] << (options[:message] || "cannot be changed once assigned")

 module ClassMethods

   def validates_unchangeable(*attr_names)
     validates_with UnchangeableValidation::UnchangeableValidator, _merge_attributes(attr_names)

ActiveRecord::Base.send(:include, UnchangeableValidation)


require 'test_helper'

class UnchangeableValidationTest <  ActiveSupport::TestCase

  def test_login_unchangeable
    instance =
    instance.login = "login"!
    instance.login = "changed"
    assert_equal instance.errors[:login].first, "cannot be changed once assigned"


Squirrel SQL Client and SQLite Databases

Working with RubyOnRails i use sqlite in development.

In my dev-environment (windows) i used to use SQLiteBrowser to look into the DB. But the usability was not what i was used to.

So i tried to get Squirrel SQL Client to work with SQLite and had my problems integrating the two together.


Because i googled and googled and did not find a working answer.

In the end it was easy.

  1. Download Squirrel SQL Client
  2. Get this jdbc-Adapter for SQLite:
  3. Throw the lib in the lib-Directory of SQuirrel
  4. Startup Squirrel
  5. Create new Driver
    1. Name: SQLite
    2. Example-Url: jdbc:sqlite:<PATH>/mydatabase.db
    3. Website-Url:
    4. Class-Name: org.sqlite.JDBC
  6. Add Alises for your DB and connect to them

Manually Creating HeapDumps in Java honoring +XX:HeapDumpPath JVM Option

+XX:HeapDumpPath is a JVM-Option that is honored by the HeapDumpOnOutOfMemory JVM-Option.

With it we can define where HeapDumps are written to the Disk.

Why do we need this?

Well, running multiple servers we may want to have them dumped centrally on a mapped network drive specifically for logfiles or dumps. Also maybe we sized the Partition for the JVM-Process too small so that a dump will not be able to be written into it (ok, disk space is cheap, even with a raid, but often we save money at the wrong end).

But if i trigger an heapdump directly (like with jconsole) i often only write the name of the dump into it or want to have it generated. Normally those dumps will now be written into the working directory of the jvm.

To avoid this, we can use the following Code to have it honored and registered as our own MBean that we will use from now on.

„Manually Creating HeapDumps in Java honoring +XX:HeapDumpPath JVM Option“ weiterlesen

delayed_job and localization (i18n)

delayed_job is a nice gem for executing work in the background in Ruby On Rails.

But what happend to me is that mails did not get send correctly. I was expecting to get them send in german and not english (default locale).

What happend?

„delayed_job and localization (i18n)“ weiterlesen

1blu VServer Neuinstallation und EMails

Mails, das ganz alltägliche Kommunikationsmedium.

Blöd wenn keine Mails ankommen, oder?

Nach Neuinstallation meines 1blu VServers mittels Template sind keine Mails mehr angekommen. Von der Konfiguration her nutzte ich keinen eigenen Mailserver, sondern den default (globaler von 1blu).

Nur warum sind dann Mails die über WordPress gesendet wurden nicht angekommen?


Ursache: Das Template mit Plesk hat leider einen kleinen Haken aktiviert, der dafür sorgt dass der VServer selbst sich als Mailserver sieht. Und weil keine Mailaddressen dort eingerichtet waren (warum auch) droppte er diese.


Lösung: Im Plesk Control Panel zu folgendem Eintrag navigieren:

E-Mail => E-Mail Einstellungen

Hier den Haken “E-Mail-Dienst auf Domain aktivieren” deaktivieren.


Dann schlägt auch nicht:

Vorgehensweise bei E-Mails an nicht-vorhandene Benutzer

mit Standardwert zurückweisen zu.