Mit puma-dev lassen sich beliebig viele Rack/Rails-Anwendungen durch Erstellen von Symlinks verfügbar machen.
Allerdings ist damit Port 80 blockiert und steht nicht mehr für Apache zur Verfügung.
Zum Glück erlaubt puma-dev nicht nur das Erstellen von Symlinks auf Rack-Apps sondern auch das Erstellen von Files innerhalb von ~/.puma-dev/, die als Inhalt einen alternativen Port enthalten.
Damit kann man alle Applikationen, die statt von puma-dev von Apache behandelt werden sollen, z.B. PHP-Apps und statische Seiten, als Files anlegen, die nur 81 enthalten.
Außerdem muss man Apache auf Port 81 lauschen lassen.
Die erforderlichen Schritte sind:
Apache-Konfiguration /etc/apache2/httpd.conf
Apache soll zukünftig auf Port 80 lauschen:
Listen 81
Die Module für virtuelle Hosts, Rewrite und PHP sollen verwendet werden:
<VirtualHost 127.0.0.1:81>
ServerName any.dev
ServerAlias *.dev
UseCanonicalName Off
VirtualDocumentRoot "/Users/{username}/Sites/%1"
<Directory "/Users/{username}/Sites/*">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
Angenommen die gewünschte PHP-Applikation liegt im Verzeichnis /Users/{username}/Sites/meine-app/.
Erstellt man eine Datei ~/.puma-dev/meine-app mit dem Inhalt 81, dann wird diese unter http://meine-app.test durch Apache verfügbar gemacht.
März 29, 2012 at 12:17 pm · Filed under Rails, Ruby
Let’s say we want a simple controller action that checks, if a given code is valid.
It should return true and false and, if the code is invalid, give the reason (whether that is because it is unknown or because it has been used already). The action could look like this:
Now this deep nesting effectively hides the underlying algorithm, a simple one in this case.
Expressing this using throw and catch straightens the code a bit:
We are down to one respond_with line but the has merging and the throws at the beginning of the line are not particularly pretty.
Let’s introduce a little Ruby mixin for the Hash class that provides it with a compact method that its friend Array has had all along:
Now using this to clean up the response hash and moving the throw statements to the end so the steps of the algorithm are visible we have our final version of the action: