Smilies in Rails using BBCodeizer

I’ve already described how to enable support for Smilies in Rails using RedCloth. If you want to use BBCodeizer instead of RedCloth (Textile), here’s how to do it. We need to extend the BBCodeizer class. We could do this by creating a file in our /lib directory (e.g. my_string.rb), which has to be included [...]

Smilies in Rails using RedCloth

There’s also a guide to use Smilies in Rails using BBCodeizer.
RedCloth doesn’t come with support for smilies, so i’ve added it for one of my projects.
You need to extend the RedCloth class. You could do this by creating a file in your /lib directory, which you have to include in your environment.rb. Here an example [...]

Rails: routes and special characters like dots

Rails doesn’t seem to like dots and other special chars in its routes.
If you want to use URLs like http://www.domain.com/post/1/just_a_test.. logically the following route seems to be sensible:
map.connect ‘/post/:id/:title’, :controller => ‘forum’, :action => ’show_post’
But rails won’t like the dots. Use a route like the following to allow a URL with special characters to be [...]

Functional test for HTTP Basic Authentication in Rails 2

If you want to provide a username and password for a HTTP Basic Authentication in one of your functional tests, simply use the following:

def test_should_get_index
@request.env["HTTP_AUTHORIZATION"] = “Basic ” + Base64::encode64(”username:password”)
get :index
assert_response :success
assert_not_nil assigns(:articles)
end

Keywords: rails test, functionals, authorization, basic http authentication, how to test

404 in rails

If you need to show a 404 error page from your controller without using an exception, this could help:
render :file => “#{RAILS_ROOT}/public/404.html”, :status => 404 and return

Rails 2: authenticate_or_request_with_http_basic and Apache

I’ve tried to use the new authenticate_or_request_with_http_basic function of Rails 2 to include a simple authentication for some special pages in an application. But Apache kept refusing authorization, even if the authenticate_or_request_with_http_basic-block was set to be always true.
To fix this, add or change this in your public/.htaccess (if using FastCGI):
RewriteRule ^(.*)$ dispatch.fcgi [E=X-HTTP_AUTHORIZATION:%{HTTP:Authorization},QSA,L]
Keywords: rails2 rails [...]

Localization problem with Wordpress 2.3

I’ve transferred a wordpress system to another server which runs PHP 5. The language file didn’t work anymore. After one annoying hour I’ve found out that the gettext functions are buggy.
Solution:

Get the current version of php-gettext at http://download.savannah.nongnu.org/releases/php-gettext/
Extract the gettext.php and streams.php to your wp-includes-directory

That’s all.
Keywords: wordpress, localization, php 5, language file, problem, 64 [...]

Rails 1.2: has_and_belongs_to_many-Beziehung (habtm) mit zusätzlichen Attributen

Die habtm-Funktionalität in Rails ist für n:m-Beziehungen gedacht. Beispiel: ein User soll Teil verschiedener Gruppen sein können und einer Gruppe sollen mehrere User angehören können. Was aber, wenn jede dieser Beziehungen zusätzliche Attribute mit sich bringen soll? Beispiel: User 1 hat in Gruppe 1 die Rolle “admin” inne, in Gruppe 2 “member” etc. Hierfür bietet [...]

Rails 1.2: nl2br für Rails

Es lebe die nl2br-Funktion! Nur leider hatte ich sie bei Rails bzw. Ruby nicht gefunden (inzwischen schon, siehe Ende des Beitrags). Darum hatte ich kurzerhand ein klitzekleines Plugin namens EnhanceString für Rails geschrieben, dass die String-Objekte um die nl2br-Funktion erweitert.
Für Ahnungslose: nl2br() ist eine Funktion der PHP Syntax, die alle Zeilenumbrüche eines Strings in dessen [...]

Rails 1.2: Fehlender Zeichensatz der Rails console (irb)

Die console von Rails 1.2 akzeptiert unter einem deutschen Windows leider nicht von Haus aus alle Zeichen. Darunter die wirklich oft benötigten eckigen Klammern [], der senkrechte Strich | oder auch die Tilde ~
Ich habe einige Beschreibungen im Netz gefunden, die leider nur teilweise funktionierten. Die einfachste Lösung ist es, die –readline Option in der [...]


linkboost