First i thought using the browser-gem and browser.bot? would give me the correct answer. But somehow it did not work. So i am now using this litte snippet to detect bots.
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:
uAgent = request.env["HTTP_USER_AGENT"]
A list of user-agents may be found at http://www.user-agents.org/
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
class UnchangeableValidator < ActiveModel::EachValidator
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")
validates_with UnchangeableValidation::UnchangeableValidator, _merge_attributes(attr_names)
class UnchangeableValidationTest < ActiveSupport::TestCase
instance = User.new
instance.login = "login"
instance.login = "changed"
assert_equal instance.errors[:login].first, "cannot be changed once assigned"
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.
- Download Squirrel SQL Client http://squirrel-sql.sourceforge.net/
- Get this jdbc-Adapter for SQLite: https://bitbucket.org/xerial/sqlite-jdbc/overview
- Throw the lib in the lib-Directory of SQuirrel
- Startup Squirrel
- Create new Driver
- Name: SQLite
- Example-Url: jdbc:sqlite:<PATH>/mydatabase.db
- Website-Url: https://bitbucket.org/xerial/sqlite-jdbc/wiki/Usage
- Class-Name: org.sqlite.JDBC
- Add Alises for your DB and connect to them
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).
„delayed_job and localization (i18n)“ weiterlesen