Mephisto Contact form plugin
February 23rd, 2009
Being very much into Mephisto lately, I came across James Crisp’s contact form plugin. As my needs are multisite-oriented, I forked and tweaked it as needed. You can find it here
How to fix broken article versions in emk/mephisto edge (post 0.8.1)
February 19th, 2009
UPDATE March 15, 2009: Good news, Eric Kidd informed me that the patch has been applied to mephisto edge, commit
Currently in mephisto edge, which is maintained and developed by Eric Kidd (aka emk) article versions are broken. More precisely, the bug comes up ONLY when the installation operates in multisite mode (or even more precisely, when there are at least two articles belonging to two different sites).
After reporting the ticket on lighthouse I found out what the bug was. So..
The problem is how acts_as_versioned is being used. An acts_as_versioned record has among others an “id” column (the default id that ActiveRecord requires) and a “version” column.
Currently Mephisto falsely does the following inside \app\controllers\admin\articles_controller.rb on line 38 (edit action)...
@version = params[:version] ? @article.versions.find(params[:version]) : @article or raise(ActiveRecord::RecordNotFound)
the whole problem is the find(params[:version]) . What happens here is, that we lookup an article’s version by searching for its id instead of for its version column (even though we do use the correct :version parameter.)
So this has to change to find_by_version(params[:version]) and thus become..
@version = params[:version] ? @article.versions.find_by_version(params[:version]) : @article or raise(ActiveRecord::RecordNotFound)
Notice though that this doesn’t break in a single-site installation, because in this case id and version bot get the same (concurrent) increment. That is because all articles belong the same one and only Site instance.
‘nough said, voila le patch
Using error codes for ActiveRecord validations
February 10th, 2009
While working on the unit tests of Lele I had the situation where I wanted to differentiate among several validation errors a specific field might have.
Since I didn’t want to start comparing error messages contained in model.errors I came up with the following petit hack
For each validation error I cared about detecting (mostly the custom ones) I did the following…
inside say model Private.rbdef validate errors.add(:joined, "Run for your life!!!"+ercode(123)) if grenade.released? end
Now what’s ercode(123) ? The argument is arbitrary, ercode is the following method monkey patch of ActiveRecord inside /config/initializer/application.rb
class ActiveRecord::Base
def ercode(code)
#turn an integer like '1' into a string like '01'
str_code = (code <10 ? "0"+ code.to_s : code.to_s)
ENV['RAILS_ENV'] == "test" ? str_code : "" # I only want this when testing
end
end
Given this, inside private_test.rb I can check whether a particular validation has been triggered by detecting its error code inside the models error strings.
For example…
def test_custom_validations
...
assert_error_code(private, 123)
end
def assert_error_code(model, code)
assert model.errors.full_messages.join("").include?(code.to_s) # test wether too long left
end
Mephisto Multisite, Passenger, Apache2
February 5th, 2009
Here is my vhost file for using a multisite installation (default nowdays with Mephisto 0.8.1) being served by apache 2 and passenger.
Don’t forget to a2ensite foo.com your domain, for apache to pick it up.
NameVirtualHost *:80
<VirtualHost *:80>
ServerName coderado.com
ServerAlias www.coderado.com
RailsEnv production
DirectorySlash Off
DocumentRoot /var/apps/m8/public
ErrorLog /var/apps/m8/log/apache.log
CustomLog /var/apps/m8/log/access.log combined
<Directory /var/apps/m8/public>
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
RailsAllowModRewrite on
RewriteEngine On
# Rewrite / to index.html
RewriteCond %{REQUEST_URI} ^/assets/.*$
RewriteCond %{DOCUMENT_ROOT}/assets/%{HTTP_HOST}/$1 -f
RewriteRule ^/assets/(.*)$ /assets/%{HTTP_HOST}/$1 [QSA,L]
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}/index.html -f
RewriteRule ^/(.*)$ /cache/%{HTTP_HOST}/index.html [QSA,L]
RewriteCond %{REQUEST_URI} ^/[^.]+$
RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}%{REQUEST_FILENAME}.html -f
RewriteRule ^/(.*)$ /cache/%{HTTP_HOST}%{REQUEST_FILENAME}.html [QSA,L]
RewriteCond %{REQUEST_URI} ^/.+$
RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}%{REQUEST_FILENAME} -f
RewriteRule ^/(.*)$ /cache/%{HTTP_HOST}%{REQUEST_FILENAME} [QSA,L]
</VirtualHost>
Installing Nokogiri gem on debian 4
February 3rd, 2009
Mephisto 0.8 requires nokogiri. Apparently a simple gem install nokogiri is not enough.
here’s what is…
- sudo apt-get install libxml2-dev libxslt1-dev
- sudo gem install nokogiri
make mephisto search case insensitive
January 25th, 2009
small hack applies to mephisto 0.8.1.
around line 76 in mephisto_controller.rb the case sensitive code…
conditions = ['(published_at IS NOT NULL AND published_at <= :now) AND (title LIKE :q OR excerpt LIKE :q OR body LIKE :q)',
has to become…
conditions = ['(published_at IS NOT NULL AND published_at <= :now) AND (lower(title) LIKE lower(:q) OR lower(excerpt) LIKE lower(:q) OR lower(body) LIKE lower(:q))',
this downcases all strings before comparing.
trouble switching from sqlite to mysql
October 28th, 2008
UPDATE 9/3/2009
So you’re happily rake test ing the shit out of your app, and see nothing but dots.. Then cap deploy and you see nothing.. at all!
Why you ask? I’ll tell ya.
Using Rails 2.1.0 on my dev box, I ran sqlite as dev and test db. All was fine and happy.
Then deployed (to mysql) and all hell broke loose. Looks like Mysql doesnt like lines such as
named_scope :exclude, lambda {|id| { :conditions => ['id <> ?', id] } }
Instead, it prefers
named_scope :exclude, lambda {|id| { :conditions => ['`services`.id <> ?', id] } }
weird huh?
LeLe, private's facebook
October 18th, 2008
It’s been a month since the launch of LeLe, our social networking app for former privates of the greek army. People haven’t quite embraced it yet but that shouldn’t keep us from evolving it, should it? No Sir!
So in that spirit, as of yesterday we support OpenID on it, cause no one needs another password. Next step is to enhance its TDD with some shoulda magic (check this comparison by josh susser )
cheers
you gotta... shock the monkey!
September 7th, 2008
Peter Gabriel sang about it… , so I thought I’ll do the coding part ;)
Through coderado, happily presenting monkey chord. In a nutshell: it transposes music chords found inside a webpage.
So grab your guitar mate…
web app implementation footprint
August 13th, 2008
I was just browsing Geoffrey Grosenbach’s wonderful nubyonrails and that “Manufactured with” in the left bottom corner got me interested.
It’s nothing new of course for someone to post info regarding implementation aspects such as tools used on a site. But I wonder if there such thing somewhere somehow centralized…? Sounds like a new pet project.
OpenID is getting better and better
August 8th, 2008
More major sites are already jumping on the openID wagon. Of course one could argue that this was just a matter of time.
In my eyes though the latest n greatest is PhoneFactor and it’s CallVerifID. Single sign on can’t get any better. Can’t wait to see Greece on the list.