<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TommyBlue.it &#187; RubyOnRails</title>
	<atom:link href="http://www.tommyblue.it/tag/rubyonrails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tommyblue.it</link>
	<description>Bombardare per la pace è un po' come trombare per la verginità...</description>
	<lastBuildDate>Tue, 24 Jan 2012 09:34:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to fix redmine-mylyn-connector &#8220;Server Error: undefined method `visible_by&#8217;&#8221;</title>
		<link>http://www.tommyblue.it/2011/12/14/how-to-fix-redmine-mylyn-connector-server-error-undefined-method-visible_by/</link>
		<comments>http://www.tommyblue.it/2011/12/14/how-to-fix-redmine-mylyn-connector-server-error-undefined-method-visible_by/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 13:11:08 +0000</pubDate>
		<dc:creator>TommyBlue</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Mylyn]]></category>
		<category><![CDATA[Redmine]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://www.tommyblue.it/?p=1266</guid>
		<description><![CDATA[With version 5324 the method Project.visible_by has been deprecated in favor of Project.visible_condition and redmine-mylyn-connector plugin stopped working with error: Server Error: undefined by `visible_by&#8217;. Here&#8217;s the patch you need to fix the plugin: diff -r redmine-mylyn-connector-2.7.5/app/controllers/mylyn_connector/issues_controller.rb redmine-mylyn-connector-2.7.5-patched/app/controllers/mylyn_connector/issues_controller.rb 63c63 &#60; :conditions =&#62; &#91;&#34;#{Issue.table_name}.id in (?) and #{Issue.table_name}.updated_on &#62;= ? and &#34; &#60; &#60; Project.visible_by, issues, [...]]]></description>
			<content:encoded><![CDATA[<p>With <a href="http://www.redmine.org/projects/redmine/repository/revisions/5324" target="_blank">version 5324</a> the method <strong>Project.visible_by</strong> has been <a href="http://www.redmine.org/projects/redmine/repository/revisions/5324/diff/trunk/app/models/project.rb" target="_blank">deprecated in favor of <strong>Project.visible_condition</strong></a> and <a href="http://sourceforge.net/apps/wordpress/redmin-mylyncon/" target="_blank">redmine-mylyn-connector</a> plugin stopped working with error:<strong><em> Server Error: undefined by `visible_by&#8217;</em></strong>.</p>
<p>Here&#8217;s the patch you need to fix the plugin:</p>
<pre>
<div class="codecolorer-container ruby railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">diff <span style="color:#006600; font-weight:bold;">-</span>r redmine<span style="color:#006600; font-weight:bold;">-</span>mylyn<span style="color:#006600; font-weight:bold;">-</span>connector<span style="color:#006600; font-weight:bold;">-</span>2.7.5<span style="color:#006600; font-weight:bold;">/</span>app<span style="color:#006600; font-weight:bold;">/</span>controllers<span style="color:#006600; font-weight:bold;">/</span>mylyn_connector<span style="color:#006600; font-weight:bold;">/</span>issues_controller.<span style="color:#9900CC;">rb</span> redmine<span style="color:#006600; font-weight:bold;">-</span>mylyn<span style="color:#006600; font-weight:bold;">-</span>connector<span style="color:#006600; font-weight:bold;">-</span>2.7.5<span style="color:#006600; font-weight:bold;">-</span>patched<span style="color:#006600; font-weight:bold;">/</span>app<span style="color:#006600; font-weight:bold;">/</span>controllers<span style="color:#006600; font-weight:bold;">/</span>mylyn_connector<span style="color:#006600; font-weight:bold;">/</span>issues_controller.<span style="color:#9900CC;">rb</span><br />
63c63<br />
<span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;#{Issue.table_name}.id in (?) and #{Issue.table_name}.updated_on &gt;= ? and &quot;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> Project.<span style="color:#9900CC;">visible_by</span>, issues, cond<span style="color:#006600; font-weight:bold;">&#93;</span><br />
<span style="color:#006600; font-weight:bold;">---</span><br />
<span style="color:#006600; font-weight:bold;">&gt;</span> &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;#{Issue.table_name}.id in (?) and #{Issue.table_name}.updated_on &gt;= ? and &quot;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> Project.<span style="color:#9900CC;">visible_condition</span><span style="color:#006600; font-weight:bold;">&#40;</span>User.<span style="color:#9900CC;">current</span><span style="color:#006600; font-weight:bold;">&#41;</span>, issues, cond<span style="color:#006600; font-weight:bold;">&#93;</span><br />
79c79<br />
<span style="color:#006600; font-weight:bold;">&lt;</span> &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;#{Issue.table_name}.id in (?) and &quot;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> Project.<span style="color:#9900CC;">visible_by</span>, issues<span style="color:#006600; font-weight:bold;">&#93;</span><br />
<span style="color:#006600; font-weight:bold;">---</span><br />
<span style="color:#006600; font-weight:bold;">&gt;</span> &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;#{Issue.table_name}.id in (?) and &quot;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> Project.<span style="color:#9900CC;">visible_condition</span><span style="color:#006600; font-weight:bold;">&#40;</span>User.<span style="color:#9900CC;">current</span><span style="color:#006600; font-weight:bold;">&#41;</span>, issues<span style="color:#006600; font-weight:bold;">&#93;</span><br />
diff <span style="color:#006600; font-weight:bold;">-</span>r redmine<span style="color:#006600; font-weight:bold;">-</span>mylyn<span style="color:#006600; font-weight:bold;">-</span>connector<span style="color:#006600; font-weight:bold;">-</span>2.7.5<span style="color:#006600; font-weight:bold;">/</span>app<span style="color:#006600; font-weight:bold;">/</span>controllers<span style="color:#006600; font-weight:bold;">/</span>mylyn_connector<span style="color:#006600; font-weight:bold;">/</span>projects_controller.<span style="color:#9900CC;">rb</span> redmine<span style="color:#006600; font-weight:bold;">-</span>mylyn<span style="color:#006600; font-weight:bold;">-</span>connector<span style="color:#006600; font-weight:bold;">-</span>2.7.5<span style="color:#006600; font-weight:bold;">-</span>patched<span style="color:#006600; font-weight:bold;">/</span>app<span style="color:#006600; font-weight:bold;">/</span>controllers<span style="color:#006600; font-weight:bold;">/</span>mylyn_connector<span style="color:#006600; font-weight:bold;">/</span>projects_controller.<span style="color:#9900CC;">rb</span><br />
16c16<br />
<span style="color:#006600; font-weight:bold;">&lt;</span> &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">&quot;enabled_modules.name = 'issue_tracking' AND #{Project.visible_by}&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#006600; font-weight:bold;">---</span><br />
<span style="color:#006600; font-weight:bold;">&gt;</span> &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">&quot;enabled_modules.name = 'issue_tracking' AND #{Project.visible_condition(User.current)}&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
diff <span style="color:#006600; font-weight:bold;">-</span>r redmine<span style="color:#006600; font-weight:bold;">-</span>mylyn<span style="color:#006600; font-weight:bold;">-</span>connector<span style="color:#006600; font-weight:bold;">-</span>2.7.5<span style="color:#006600; font-weight:bold;">/</span>app<span style="color:#006600; font-weight:bold;">/</span>controllers<span style="color:#006600; font-weight:bold;">/</span>mylyn_connector<span style="color:#006600; font-weight:bold;">/</span>queries_controller.<span style="color:#9900CC;">rb</span> redmine<span style="color:#006600; font-weight:bold;">-</span>mylyn<span style="color:#006600; font-weight:bold;">-</span>connector<span style="color:#006600; font-weight:bold;">-</span>2.7.5<span style="color:#006600; font-weight:bold;">-</span>patched<span style="color:#006600; font-weight:bold;">/</span>app<span style="color:#006600; font-weight:bold;">/</span>controllers<span style="color:#006600; font-weight:bold;">/</span>mylyn_connector<span style="color:#006600; font-weight:bold;">/</span>queries_controller.<span style="color:#9900CC;">rb</span><br />
18c18<br />
<span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;(#{Query.table_name}.is_public = ? OR #{Query.table_name}.user_id = ?) AND (project_id IS NULL OR &quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> Project.<span style="color:#9900CC;">visible_by</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;)&quot;</span>, <span style="color:#0000FF; font-weight:bold;">true</span>, User.<span style="color:#9900CC;">current</span>.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#93;</span>,<br />
<span style="color:#006600; font-weight:bold;">---</span><br />
<span style="color:#006600; font-weight:bold;">&gt;</span> &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;(#{Query.table_name}.is_public = ? OR #{Query.table_name}.user_id = ?) AND (project_id IS NULL OR &quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> Project.<span style="color:#9900CC;">visible_condition</span><span style="color:#006600; font-weight:bold;">&#40;</span>User.<span style="color:#9900CC;">current</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;)&quot;</span>, <span style="color:#0000FF; font-weight:bold;">true</span>, User.<span style="color:#9900CC;">current</span>.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div></div>
</pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.tommyblue.it/2011/12/14/how-to-fix-redmine-mylyn-connector-server-error-undefined-method-visible_by/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installazione di Gitorious su Ubuntu server 10.04</title>
		<link>http://www.tommyblue.it/2011/06/01/installazione-di-gitorious-su-ubuntu-server-10-04/</link>
		<comments>http://www.tommyblue.it/2011/06/01/installazione-di-gitorious-su-ubuntu-server-10-04/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 14:17:14 +0000</pubDate>
		<dc:creator>TommyBlue</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Informatica]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[gitorious]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://www.tommyblue.it/?p=1160</guid>
		<description><![CDATA[Oggi ho bestemmiato un paio d&#8217;ore per installare Gitorious, progetto che mi ha incuriosito e di cui volevo capirne le potenzialità (in ottica di fargli sostituire l&#8217;ottimo Redmine). Dato che alla fine sono riuscito a farlo funzionare e non ho trovato una guida fatta a modo, ho deciso di mettere nero su bianco ciò che [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-1161" title="Gitorious" src="http://www.tommyblue.it/wp-content/uploads/2011/06/Gitorious.png" alt="" width="95" height="95" />Oggi ho bestemmiato un paio d&#8217;ore per installare <a title="Gitorious" href="http://www.gitorious.org/" target="_blank">Gitorious</a>, progetto che mi ha incuriosito e di cui volevo capirne le potenzialità (in ottica di fargli sostituire l&#8217;ottimo <a title="Remine" href="http://www.redmine.org/" target="_blank">Redmine</a>). Dato che alla fine sono riuscito a farlo funzionare e non ho trovato una guida fatta a modo, ho deciso di mettere nero su bianco ciò che ho fatto.</p>
<p>L&#8217;installazione è stata effettuata su un server virtuale pulito Ubuntu server 10.04 x86_64. Ho provato ad utilizzare <a title="RVM" href="https://rvm.beginrescueend.com/" target="_blank">RVM</a> e ruby 1.9.2 ma non ci sono riuscito&#8230; Ho quindi utilizzato <a title="Ruby Enterprise Edition" href="http://www.rubyenterpriseedition.com/" target="_blank">Ruby Enterprise Edition</a> 1.8.7<span id="more-1160"></span></p>
<p>Per cominciare ho installato un po&#8217; di pacchetti:</p>
<pre>apt-get install build-essential zlib1g-dev tcl-dev libexpat-dev libcurl4-openssl-dev postfix apache2 mysql-server mysql-client apg geoip-bin libgeoip1 libgeoip-dev libaspell-dev aspell sqlite3 libsqlite3-dev imagemagick libpcre3 libpcre3-dev zlib1g zlib1g-dev libyaml-dev libmysqlclient15-dev apache2-dev libonig-dev libmagick++-dev zip unzip memcached git-core git-svn git-doc git-cvs irb sphinxsearch uuid uuid-dev openjdk-6-jre</pre>
<p>Ho scaricato e installato <a title="ActiveMQ" href="http://activemq.apache.org/" target="_blank">ActiveMQ</a> 5.5.0:</p>
<pre>wget http://www.powertech.no/apache/dist/activemq/apache-activemq/5.5.0/apache-activemq-5.5.0-bin.tar.gz
sudo -s
tar xzvf apache-activemq-5.5.0-bin.tar.gz -C /usr/local/
echo "export ACTIVEMQ_HOME=/usr/local/apache-activemq-5.5.0" &gt;&gt; /etc/activemq.conf﻿
echo "export JAVA_HOME=/usr/" &gt;&gt; /etc/activemq.conf
dduser --system --no-create-home activemq
chown -R activemq /usr/local/apache-activemq-5.5.0/data</pre>
<p>Per lanciare ActiveMQ ho utilizzato <a href="http://www.tommyblue.it/wp-content/uploads/2011/06/activemq.txt" target="_blank">questo</a> file, copiato in <em>/etc/init.d</em>:</p>
<pre>wget http://www.tommyblue.it/wp-content/uploads/2011/06/activemq.txt
sudo mv activemq.txt /etc/init.d/activemq
sudo chmod +x /atc/init.d/activemq
sudo update-rc.d activemq defaults
sudo service activemq start</pre>
<p>A questo punto ho scaricato da <a title="REE" href="http://www.rubyenterpriseedition.com/download.html" target="_blank">qui</a> REE e l&#8217;ho installato:</p>
<pre>sudo dpkg -i ﻿﻿ruby-enterprise_1.8.7-2011.03_amd64_ubuntu10.04.deb</pre>
<p>dopodichè ho installato <a title="RubyGems" href="http://rubygems.org/" target="_blank">RubyGems</a>. Come dicevo prima non sono riuscito ad utilizzare RVM proprio a causa di problemi con le gemme. Per far funzionare il tutto ho dovuto installare tutte le gemme da root:</p>
<pre>wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.5.tgz
tar xzf  ﻿rubygems-1.8.5.tgz
cd rubygems-1.8.5/
sudo ruby setup.rb
echo "gem: --no-ri --no-rdoc" &gt; ~/.gemrc</pre>
<p>Installato RubyGems bisogna installare le gemme. <strong>ATTENZIONE</strong>: se fin qui ho più o meno seguito le guide che trovate nella webografia, per le gemme ho fatto tutt&#8217;altro. Infatti per far funzionare Gitorious, che è scritto con Rails 2.3.x, non è possibile installare le gemme <em>as is</em> dato che molte sono ormai incompatibili con Rails 2. Meglio far fare tutto a Bundler o specificare gemma per gemma la versione da installare. Quindi prima cloniamo il repository di Gitorious:</p>
<pre>sudo -s
git clone git://gitorious.org/gitorious/mainline.git /var/www/gitorious
cd /var/www/gitorious
gem install bundler
bundle install
gem install -b -v 1.1 stomp
gem install rmagick passenger stompserver raspell
gem install -v=0.8.7 rake
passenger-install-apache2-module</pre>
<p>Al termine dell&#8217;ultimo passaggio creare il file <em>/etc/apache2/mods-available/passenger.load</em> con quanto suggerito dallo script precedente. Nel mio caso:</p>
<pre>LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.7
PassengerRuby /usr/local/bin/ruby</pre>
<p>Per attivare il modulo:</p>
<pre>a2enmod passenger
a2enmod rewrite
a2enmod ssl
a2enmod expires
service apache2 restart</pre>
<p>Ok, adesso ho copiato i necessari script di avvio:</p>
<pre>cp /var/www/gitorious/doc/templates/ubuntu/git-daemon /etc/init.d/
cp /var/www/gitorious/doc/templates/ubuntu/git-ultrasphinx /etc/init.d/</pre>
<p>In <em>/etc/init.d/git-daemon</em> modificare GIT_DAEMON come segue:</p>
<pre>GIT_DAEMON="/usr/bin/local/ruby /var/www/gitorious/script/git-daemon -d"</pre>
<p>Creare anche <em>/etc/init.d/stomp</em>:</p>
<pre>#!/bin/sh
# Start/stop the stompserver
#
### BEGIN INIT INFO
# Provides:          stomp
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      1
# Short-Description: Stomp
# Description:       Stomp
### END INIT INFO   

test -f /usr/local/bin/stompserver || exit 0    

. /lib/lsb/init-functions    

case "$1" in
start)  log_daemon_msg "Starting stompserver" "stompserver"
    start-stop-daemon --start --name stompserver --startas /usr/local/bin/stompserver --background --user git
    log_end_msg $?
    ;;
stop)  log_daemon_msg "Stopping stompserver" "stompserver"
    start-stop-daemon --stop --name stompserver
    log_end_msg $?
    ;;
restart) log_daemon_msg "Restarting stompserver" "stompserver"
    start-stop-daemon --stop --retry 5 --name stompserver
    start-stop-daemon --start --name stompserver --startas /usr/local/bin/stompserver --background --user git
    log_end_msg $?
    ;;
status)
    status_of_proc /usr/local/bin/stompserver stompserver &amp;&amp; exit 0 || exit $?
    ;;
*)      log_action_msg "Usage: /etc/init.d/stomp {start|stop|restart|status}"
    exit 2
    ;;
esac
exit 0</pre>
<p>e <em>/etc/init.d/git-poller</em>:</p>
<pre>#!/bin/sh
# Start/stop the git poller
#
### BEGIN INIT INFO
# Provides:          git-poller
# Required-Start:    stomp
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      1
# Short-Description: Gitorious poller
# Description:       Gitorious poller
### END INIT INFO    

/bin/su - git -c "cd /var/www/gitorious;RAILS_ENV=production script/poller $@"</pre>
<p>Si possono quindi aggiungere tutti all&#8217;avvio:</p>
<pre>chmod 755 /etc/init.d/git-ultrasphinx /etc/init.d/git-daemon /etc/init.d/stomp /etc/init.d/git-poller
update-rc.d stomp defaults
update-rc.d git-daemon defaults
update-rc.d git-ultrasphinx defaults
update-rc.d git-poller defaults</pre>
<p>Bisogna creare la configurazione di apache. Gitorious utilizza SSL per il login, quindi i VirtualHost sono 2, io ho creato il file <em>/etc/apache2/sites-available/gitorious</em>:</p>
<pre>&lt;VirtualHost *:80&gt;
  ServerName MIODOMINIO
  DocumentRoot /var/www/gitorious/public
&lt;/VirtualHost&gt;
&lt;IfModule mod_ssl.c&gt;
  &lt;VirtualHost _default_:443&gt;
    ServerName MIODOMINIO
    DocumentRoot /var/www/gitorious/public
    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
    SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
    BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
  &lt;/VirtualHost&gt;
&lt;/IfModule&gt;</pre>
<p>e quindi l&#8217;ho attivato:</p>
<pre>a2dissite default
a2ensite gitorious</pre>
<p>Torniamo a Gitorious che abbiamo un po&#8217; lasciato indietro. Serve un utente git che sarà il proprietario dell&#8217;applicazione:</p>
<pre>adduser --system --home /var/www/gitorious/ --no-create-home --group --shell /bin/bash git
chown -R git:git /var/www/gitorious
su - git
cd /var/www/gitorious
mkdir .ssh
touch .ssh/authorized_keys
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
mkdir -p tmp/pids repositories tarballs
cp config/database.sample.yml config/database.yml
cp config/gitorious.sample.yml config/gitorious.yml
cp config/broker.yml.example config/broker.yml</pre>
<p>Modificare <em>config/database.yml</em> lasciando soltanto la sezione production e le sue configurazioni. Inserire un utente MySQL con permessi sul database <em>gitorious_production</em> (se non volete creare a mano questo db utilizzate un utente in grado di creare database). Nel file <em>config/gitorious.yml</em> inserite:</p>
<pre>production:
  cookie_secret: "FRASESEGRETISSIMAELUNGHISSIMA"
  repository_base_path: "/var/www/gitorious/repositories"
  gitorious_client_port: 80
  gitorious_client_host: gitorious.dw
  gitorious_host: gitorious.dw
  archive_cache_dir: "/var/www/gitorious/tarballs"
  archive_work_dir: "/tmp/tarballs-work"
  hide_http_clone_urls: true
  is_gitorious_dot_org: false</pre>
<p>Per il valore di <em>cookie_secret</em> utilizzate l&#8217;output del comando <em>apg -m 64</em>.<br />
Ho avuto dei problemi con ActiveSupport, del tipo:</p>
<pre>uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)</pre>
<p>come suggerito <a href="http://makandra.com/notes/1051-fixing-uninitialized-constant-activesupport-dependencies-mutex-nameerror" target="_blank">qui</a> li ho superati inserendo <em>require &#8216;thread&#8217;</em> in <em>config/boot.rb</em> dopo RAILS_ROOT.</p>
<p>A questo punto si può procedere con la migrazione:</p>
<pre>su - git
cd /var/www/gitorious
export RAILS_ENV=production
rake db:create
rake db:migrate
rake ultrasphinx:bootstrap</pre>
<p>L&#8217;ultimo comando dovrebbe restituire un errore ma comunque crea il file di configurazione, che va editato per evitare l&#8217;errore. Il file è  <em>config/ultrasphinx/production.conf</em> in cui va sostituito <em>base_tags</em> con <em>tags</em>. Effettuata la sostituizione su può lanciare Sphinx con:</p>
<pre>rake ultrasphinx:index RAILS_ENV=production
rake ultrasphinx:daemon:start RAILS_ENV=production</pre>
<p>Per l&#8217;aggiornamento degli indici ho creato il file<em> /etc/cron.d/ultrasphinx</em>:</p>
<pre>* */1 * * *       git     cd /var/www/gitorious &amp;&amp; /usr/local/bin/rake ultrasphinx:index RAILS_ENV=production</pre>
<p>Prima di accedere a Gitorious bisogna creare l&#8217;utente admin lanciando, come <em>git</em>, il comando:</p>
<pre>env RAILS_ENV=production ruby script/create_admin</pre>
<p>Riavviamo i servizi (ed eventualmente il server per essere sicuri che al riavvio Gitorious funzioni correttamente):</p>
<pre>service git-daemon start
service apache2 restart</pre>
<p>Colleghiamoci al sito e, se tutto è andato bene, iniziamo ad utilizzare Gitorious!</p>
<p>Resta un&#8217;ultima cosa da fare per poter pushare correttamente, ovvero creare un link simbolico al file <em>/var/www/gitorious/script/gitorious</em> in una cartella presente nella PATH dell&#8217;utente git, io l&#8217;ho creato in<em> /usr/local/bin</em>:</p>
<pre>﻿﻿﻿ln -s /var/www/gitorious/script/gitorious /usr/local/bin/</pre>
<p>Senza questo passaggio al momento del push ottenevo un singolare quanto criptico errore da git:</p>
<pre>bash: gitorious: comando non trovato</pre>
<h3>﻿Webografia</h3>
<ul>
<li><a href="http://www.silly-science.co.uk/2010/12/12/installing-gitorious-on-ubuntu-10-04-howto/">http://www.silly-science.co.uk/2010/12/12/installing-gitorious-on-ubuntu-10-04-howto/</a></li>
<li><a href="http://www.gitorious.org/gitorious/pages/UbuntuInstallation">http://www.gitorious.org/gitorious/pages/UbuntuInstallation</a></li>
<li><a href="http://cjohansen.no/en/ruby/setting_up_gitorious_on_your_own_server">http://cjohansen.no/en/ruby/setting_up_gitorious_on_your_own_server</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.tommyblue.it/2011/06/01/installazione-di-gitorious-su-ubuntu-server-10-04/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Linux Day 2010 Arezzo</title>
		<link>http://www.tommyblue.it/2010/10/24/linux-day-2010-arezzo/</link>
		<comments>http://www.tommyblue.it/2010/10/24/linux-day-2010-arezzo/#comments</comments>
		<pubDate>Sat, 23 Oct 2010 23:18:11 +0000</pubDate>
		<dc:creator>TommyBlue</dc:creator>
				<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Software Libero]]></category>
		<category><![CDATA[Linux Day]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://www.tommyblue.it/?p=1038</guid>
		<description><![CDATA[Oggi ho partecipato al Linux Day ad Arezzo con il talk &#8220;Sviluppo di applicazioni web con Ruby On Rails 3&#8243;. Distribuisco qui le slides proiettate durante il talk: download]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-medium wp-image-1039" title="Linux Day 2010" src="http://www.tommyblue.it/wp-content/uploads/2010/10/log0ld2k10-185x300.gif" alt="" width="185" height="300" />Oggi ho partecipato al <a href="http://www.linuxdayarezzo.it">Linux Day ad Arezzo</a> con il talk <em><strong>&#8220;Sviluppo di applicazioni web con Ruby On Rails 3&#8243;</strong></em>.</p>
<p>Distribuisco qui le slides proiettate durante il talk: <a href="http://www.tommyblue.it/wp-content/uploads/2010/10/LD2010.pdf">download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tommyblue.it/2010/10/24/linux-day-2010-arezzo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accedere a Redmine con le credenziali di Zimbra</title>
		<link>http://www.tommyblue.it/2010/09/01/accedere-a-redmine-con-le-credenziali-di-zimbra/</link>
		<comments>http://www.tommyblue.it/2010/09/01/accedere-a-redmine-con-le-credenziali-di-zimbra/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 10:10:44 +0000</pubDate>
		<dc:creator>TommyBlue</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Software Libero]]></category>
		<category><![CDATA[Redmine]]></category>
		<category><![CDATA[RubyOnRails]]></category>
		<category><![CDATA[zimbra]]></category>

		<guid isPermaLink="false">http://www.tommyblue.it/?p=977</guid>
		<description><![CDATA[Ultimamente ho abbandonato Trac per passare al più evoluto Redmine, un software per la gestione dei progetti scritto con Ruby On Rails. Tra le possibilità offerte c&#8217;è anche quella di integrare l&#8217;accesso all&#8217;applicazione con un albero LDAP esistente. Nel mio caso mi è stato utile integrarlo con l&#8217;LDAP di Zimbra. I passaggi sono piuttosto facili: [...]]]></description>
			<content:encoded><![CDATA[<p>Ultimamente ho abbandonato Trac per passare al più evoluto <a href="http://www.redmine.org/" target="_blank">Redmine</a>, un software per la gestione dei progetti scritto con Ruby On Rails. Tra le possibilità offerte c&#8217;è anche quella di integrare l&#8217;accesso all&#8217;applicazione con un albero LDAP esistente. Nel mio caso mi è stato utile integrarlo con l&#8217;LDAP di Zimbra.</p>
<p>I passaggi sono piuttosto facili:<br />
intanto bisogna collegarsi all&#8217;amministrazione di Zimbra e creare un utente nel dominio principale (nel mio caso <em>redmine</em>). Personalmente ho disattivato tutte le opzioni (posta, rubrica, documenti, ecc.) per questo utente, tanto serve solamente per il binding a LDAP.<br />
Una volta creato possiamo provare che questo utente possa fare ricerche nell&#8217;albero:</p>
<pre>ldapsearch -b ou=people,dc=tommyblue,dc=it -h zimbra.tommyblue.it -p 389 -D uid=redmine,ou=people,dc=tommyblue,dc=it -w s3cr3t uid</pre>
<p>Se la ricerca funziona avete finito con Zimbra e potete passare a Redmine. Qui bisogna andare in Autenticazione LDAP e inserire i dati in questo modo:</p>
<ul>
<li><strong>Nome:</strong> Zimbra (è solo descrittivo)</li>
<li><strong>Host</strong>: zimbra.tommyblue.it (l&#8217;host con Zimbra)</li>
<li><strong>Porta</strong>: 389</li>
<li><strong>Utente</strong>: uid=redmine,ou=people,dc=tommyblue,dc=it</li>
<li><strong>Password</strong>: s3cr3t</li>
<li><strong>DN Base</strong>: ou=people,dc=tommyblue,dc=it</li>
<li><strong>Creazione utente &#8220;al volo&#8221;</strong>: no</li>
<li><strong>Utente</strong>: uid</li>
<li><strong>Nome</strong>: givenName</li>
<li><strong>Cognome</strong>: sn</li>
<li><strong>Email</strong>: mail</li>
</ul>
<p>Ecco uno screenshot per rendere il tutto più chiaro:</p>
<p><a href="http://www.tommyblue.it/wp-content/uploads/2010/09/Redmine-Zimbra.png" rel="lightbox[977]"><img class="alignnone size-medium wp-image-979" title="Redmine-Zimbra" src="http://www.tommyblue.it/wp-content/uploads/2010/09/Redmine-Zimbra-237x300.png" alt="" width="237" height="300" /></a></p>
<p>Per finire dovete creare un utente in Redmine selezionando come Modalità di Autenticazione quella appena creata e non quella interna.</p>
<p>Ovviamente è possibile replicare il procedimento per qualunque albero LDAP abbiate a disposizione.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tommyblue.it/2010/09/01/accedere-a-redmine-con-le-credenziali-di-zimbra/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Utilizzare più versioni di Ruby con RVM</title>
		<link>http://www.tommyblue.it/2010/05/07/utilizzare-piu-versioni-di-ruby-con-rvm/</link>
		<comments>http://www.tommyblue.it/2010/05/07/utilizzare-piu-versioni-di-ruby-con-rvm/#comments</comments>
		<pubDate>Fri, 07 May 2010 14:04:43 +0000</pubDate>
		<dc:creator>TommyBlue</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Informatica]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Rails 3]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[RubyOnRails]]></category>
		<category><![CDATA[RVM]]></category>

		<guid isPermaLink="false">http://www.tommyblue.it/?p=922</guid>
		<description><![CDATA[Con Ruby Version Manager è possibile avere più versioni (o addirittura patchlevel) di Ruby installate ed effettuare velocemente lo switch tra una e l&#8217;altra. Supponendo che abbiate già installato Rubygems, installare RVM è praticamente immediato: ~# gem install rvm ~# rvm-install A questo punto si può installare una qualsiasi versione di Ruby con: ~# rvm [...]]]></description>
			<content:encoded><![CDATA[<p>Con Ruby Version Manager è possibile avere più versioni (o addirittura <em>patchlevel</em>) di Ruby installate ed effettuare velocemente lo switch tra una e l&#8217;altra.</p>
<p>Supponendo che abbiate già installato Rubygems, installare RVM è praticamente immediato:</p>
<pre>~# gem install rvm
~# rvm-install</pre>
<p>A questo punto si può installare una qualsiasi versione di Ruby con:</p>
<pre>~# rvm install 1.9.2-head</pre>
<p>e switchare tra le versioni con:</p>
<pre>~# rvm use 1.9.2-head
~# ruby -v
ruby 1.9.2dev (2010-05-07 trunk 27656) [x86_64-darwin10.3.0]
~# rvm use default
~# ruby -v
ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]</pre>
<p>Attenzione che ogni nuova installazione ha le sue gemme, quindi sarà necessario installare quelle richieste, nel mio caso, volendo utilizzare Ruby 1.9.2 per provare Rails 3:</p>
<pre>~# rvm use 1.9.2-head
~# gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n
~# gem install rails --pre</pre>
<p><strong>Leggi anche:</strong> <a href="http://www.tommyblue.it/2010/09/22/le-magie-di-rvm/"><em>Le magie di RVM</em></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tommyblue.it/2010/05/07/utilizzare-piu-versioni-di-ruby-con-rvm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deploy di applicazioni Rails con Unicorn e Nginx</title>
		<link>http://www.tommyblue.it/2009/11/14/deploy-di-applicazioni-rails-con-unicorn-e-nginx/</link>
		<comments>http://www.tommyblue.it/2009/11/14/deploy-di-applicazioni-rails-con-unicorn-e-nginx/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 17:15:41 +0000</pubDate>
		<dc:creator>TommyBlue</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[RubyOnRails]]></category>
		<category><![CDATA[Unicorn]]></category>

		<guid isPermaLink="false">http://www.tommyblue.it/?p=705</guid>
		<description><![CDATA[Come avevo promesso avrei dedicato del tempo ad indagare circa le possibilità offerte da Unicorn per il deploy delle applicazioni Ruby On Rails. Di seguito un riepilogo di quel che ho fatto per configurare il nuovo deploy di Kickin&#8217; utilizzando Unicorn, Nginx e Apache. Unicorn L&#8217;installazione di Unicorn si fa &#8220;di tacco&#8221; (per una descrizione [...]]]></description>
			<content:encoded><![CDATA[<p>Come <a href="http://www.tommyblue.it/2009/10/08/unicorn-rack-http-server-for-unix-and-fast-clients/">avevo promesso</a> avrei dedicato del tempo ad indagare circa le possibilità offerte da <a href="http://unicorn.bogomips.org/" target="_blank">Unicorn</a> per il deploy delle applicazioni Ruby On Rails. Di seguito un riepilogo di quel che ho fatto per configurare il nuovo deploy di <a href="http://kickin.kreations.it" target="_blank">Kickin&#8217;</a> utilizzando Unicorn, Nginx e Apache.</p>
<h3>Unicorn</h3>
<p>L&#8217;installazione di Unicorn si fa &#8220;di tacco&#8221; (per una descrizione più dettagliata <a href="http://www.tommyblue.it/2009/10/08/unicorn-rack-http-server-for-unix-and-fast-clients/">leggete il vecchio post</a>), basta un semplice:</p>
<pre>gem install unicorn</pre>
<p>Per le applicazioni anzichè farle rispondere su socket tcp ho deciso di utilizzare le socket Unix (posiziondole in /tmp), quindi il comando completo (da lanciare dentro la root dell&#8217;applicazione Rails) è:</p>
<pre>unicorn_rails -D -E production -l /tmp/kickin.kreations.it.sock</pre>
<p>ovvero lancio unicorn in modalità demone (<strong>-D</strong>), con l&#8217;environment production (<strong>-E production</strong>) e sulla socket /tmp/kickin.kreations.it.sock (<strong>-l /tmp/kickin.kreations.it.sock</strong>). Per la lista completa delle opzioni c&#8217;è il solito <strong>-h</strong> :)</p>
<p><span id="more-705"></span>Per rendere tutto automatizzato ho creato (in stile apache2) la cartella <strong>/etc/unicorn</strong> con dentro le cartelle <strong>sites-available</strong> e <strong>sites-enabled</strong>. Il contenuto di <strong>/etc/unicorn/sites-available/kickin.kreations.it</strong> è:</p>
<pre>#!/bin/bash
cd /var/www/tommyblue/kickin.kreations.it
su tommyblue -c "unicorn_rails -D -E production -l /tmp/kickin.kreations.it.sock"</pre>
<p>Quindi il file <strong>/etc/init.d/unicorn_rails</strong>:</p>
<pre>#! /bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/unicorn_rails
NAME=unicorn_rails
DESC=unicorn_rails
SITES=/etc/unicorn/sites-enabled
test -x $DAEMON || exit 0
set -e
start_instances() {
   for i in `ls $sites`; do
   echo -n "Starting $i"
   $SITES/$i
   done
}
case "$1" in
  start)
    start_instances;
    ;;
  stop)
    echo -n "Stopping $DESC: "
    killall $NAME
    ;;
  *)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop}" &gt;&amp;2
    exit 1
    ;;
esac
exit 0</pre>
<p>Ed ho quindi aggiunto lo script ai runlevel:</p>
<pre>update-rc.d unicorn_rails defaults 99</pre>
<p>Adesso ci si può sbizzarrire a lanciare e fermare i siti</p>
<h3>Nginx</h3>
<p>Installato nginx (<strong>apt-get install nginx</strong>) si passa a configurarlo. Io ho eliminato il sito di default e ho creato solo i files che mi interessavano (tanto la porta 8080 è chiusa dall&#8217;esterno quindi non ho problemi riguardo al visitare siti &#8220;imprevisti&#8221;). Ecco <strong>/etc/nginx/sites-available/kickin.kreations.it</strong>:</p>
<pre>upstream backend {
  server unix:/tmp/kickin.kreations.it.sock;
}
server {
  listen   8080;
  server_name  kickin.kreations.it;
  access_log  /var/log/nginx/kickin.kreations.it.access.log;
  location / {
    proxy_pass http://backend;
    proxy_redirect off;
    proxy_set_header        Host    $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    root   /var/www/nginx-default;
    index  index.html index.htm;
    }
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
  root   /var/www/nginx-default;
  }
}</pre>
<p>Come si vede dalla configurazione il backend utilizzato è la socket unix creata con unicorn e nginx risponde sulla porta 8080. Collegandosi al sito sulla porta 8080 (supponendo che il vostro server abbia tale porta accessibile dall&#8217;esterno) potete già constatare la riuscita del deploy. Se poi, diversamente dal mio caso, non avete apache che risponde sulla 80, vi basterà far rispondere nginx su tale porta e il gioco è fatto.</p>
<h3>Apache</h3>
<p>Se invece è apache che risponde sulla porta 80 è necessario questo ultimo passaggio. Innanzitutto bisogna attivare mod_proxy con:</p>
<pre>a2enmod proxy</pre>
<p>e quindi effettuare il reload di apache. Quindi si passa alla configurazione del sito, ecco <strong>/etc/apache2/sites-available/kickin.kreations.it</strong> (ho eliminato le righe non rilevanti):</p>
<pre>&lt;VirtualHost *:80&gt;
  ServerName kickin.kreations.it
  ProxyRequests off
  ProxyPreserveHost On
  &lt;Proxy *&gt;
    Order deny,allow
    Allow from all
  &lt;/Proxy&gt;
  ProxyPass / http://127.0.0.1:8080/
  ProxyPassReverse / http://127.0.0.1:8080/
&lt;/VirtualHost&gt;</pre>
<p>Una volta attivato il sito (con <strong>a2ensite</strong>), <a href="http://kickin.kreations.it" target="_blank">http://kickin.kreations.it</a> è disponibile e funzionante!</p>
<h3>Conclusioni</h3>
<p>Sebbene effettuare il deploy con Unicorn non sia ancorà così agevole (e, a quanto dicono gli sviluppatori, ancora neanche troppo stabile, la versione è la 0.94.0) il risultato è veramente strabiliante. Non ho ancora provato dei test intensivi, ma la sensazione è di applicazioni molto più reattive e addirittura la generazione di un pdf che con Passenger impiegava circa 2 minuti con Unicorn viene generato in una <strong>ventina di secondi</strong>!</p>
<p>Termino segnalando <a href="http://rainbows.rubyforge.org/" target="_blank">Rainbows! Unicorn for sleepy apps and slow clients</a>, che proverò a breve :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tommyblue.it/2009/11/14/deploy-di-applicazioni-rails-con-unicorn-e-nginx/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Unicorn: Rack HTTP server for Unix and fast clients</title>
		<link>http://www.tommyblue.it/2009/10/08/unicorn-rack-http-server-for-unix-and-fast-clients/</link>
		<comments>http://www.tommyblue.it/2009/10/08/unicorn-rack-http-server-for-unix-and-fast-clients/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 10:16:28 +0000</pubDate>
		<dc:creator>TommyBlue</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Software Libero]]></category>
		<category><![CDATA[Passenger]]></category>
		<category><![CDATA[RubyOnRails]]></category>
		<category><![CDATA[Unicorn]]></category>
		<category><![CDATA[Webrick]]></category>

		<guid isPermaLink="false">http://www.tommyblue.it/?p=635</guid>
		<description><![CDATA[Ho appena scoperto Unicorn, un server HTTP per applicazioni Rack (quindi anche Ruby on Rails) pensato per Kernel Unix o Unix-like e connessioni veloci a bassa latenza. Come suggerito dal sito client lenti dovrebbero essere serviti non da Unicorn ma da un proxy che si interfacci con Unicorn attraverso una connessione veloce ed effettui il [...]]]></description>
			<content:encoded><![CDATA[<p>Ho appena scoperto <a href="http://unicorn.bogomips.org/" target="_blank">Unicorn</a>, un server HTTP per applicazioni <a title="Rack provides a minimal interface between webservers supporting Ruby and Ruby frameworks" href="http://rack.rubyforge.org/" target="_blank">Rack</a> (quindi anche <a href="http://rubyonrails.org/" target="_blank">Ruby on Rails</a>) pensato per Kernel Unix o Unix-like e connessioni veloci a bassa latenza.<br />
Come suggerito dal sito client lenti dovrebbero essere serviti non da Unicorn ma da un proxy che si interfacci con Unicorn attraverso una connessione veloce ed effettui il buffering dei dati per poi gestire la connessione col client lento (ganzo! Ora devo scoprire come si fa&#8230;)</p>
<p>Installare Unicorn è semplicissimo, basta un:</p>
<pre>gem install unicorn</pre>
<p>dopodichè, se si tratta di un&#8217;applicazione Rails, basta andare nella RAILS_ROOT e lanciare:</p>
<pre>unicorn_rails</pre>
<p>Se invece si tratta di un&#8217;applicazione non Rails il comando è:</p>
<pre>unicorn</pre>
<p>In entrambi i casi Unicorn fa il binding della porta 8080 su tutte le interfacce (il comportamento è comunque configurabile).</p>
<p>L&#8217;impressione generale è una velocità molto maggiore sia di Webrick che di Passenger. Un confronto al volo su una pagina con un tabellone da un migliaio di righe dice:</p>
<pre>Webrick =&gt; 6131ms
Unicorn =&gt; 5698ms</pre>
<p>Quindi circa <strong>8%</strong> in meno.</p>
<p>Prossimamente approfondirò l&#8217;argomento :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tommyblue.it/2009/10/08/unicorn-rack-http-server-for-unix-and-fast-clients/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Come localizzare un&#8217;applicazione Rails</title>
		<link>http://www.tommyblue.it/2009/08/28/come-localizzare-unapplicazione-rails/</link>
		<comments>http://www.tommyblue.it/2009/08/28/come-localizzare-unapplicazione-rails/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 16:39:44 +0000</pubDate>
		<dc:creator>TommyBlue</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Informatica]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[localization]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://www.tommyblue.it/?p=552</guid>
		<description><![CDATA[Un&#8217;applicazione web che si rispetti deve potersi adattare alla lingua di colui che ne usufruisce. Dalla versione 2.2 di Ruby On Rails rendere un&#8217;applicazione multilingua è diventato estremamente semplice grazie al framework I18n. In pratica tutte le stringhe che in qualche modo verranno visualizzate nelle viste sono sostituite da appositi placeholder che Rails, a runtime, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.tommyblue.it/wp-content/uploads/2009/08/i18n-flags.jpg" rel="lightbox[552]"><img class="alignleft size-full wp-image-553" title="i18n-flags" src="http://www.tommyblue.it/wp-content/uploads/2009/08/i18n-flags.jpg" alt="i18n-flags" width="200" height="121" /></a>Un&#8217;applicazione web che si rispetti deve potersi adattare alla lingua di colui che ne usufruisce. Dalla versione 2.2 di Ruby On Rails rendere un&#8217;applicazione multilingua è diventato estremamente semplice grazie al <a href="http://guides.rubyonrails.org/i18n.html" target="_blank">framework I18n</a>. In pratica tutte le stringhe che in qualche modo verranno visualizzate nelle viste sono sostituite da appositi placeholder che Rails, a runtime, carica in maniera differente a seconda della localizzazione dell&#8217;utente.</p>
<p>Il primo passo è definire la localizzazione di default in <em>conf/environment.rb</em>:</p>
<pre>config.i18n.default_locale = :it</pre>
<p>Le stringhe di localizzazione vengono caricate da appositi file yaml nella cartella <em>conf/locales/</em>, quindi, utilizzando la lingua italiana, dobbiamo creare il file <em>conf/locales/it.yml</em> in questo modo:</p>
<pre>it:
    hello_world: "Ciao Mondo!"</pre>
<p>e analogamente il file con le traduzioni per ogni lingua che vogliamo.</p>
<p>Adesso le stringhe che devono essere localizzate sono fondamentalmente di due tipi:</p>
<ol>
<li>Le stringhe nelle viste</li>
<li>Le stringhe che vengono visualizzate nelle viste ma sono generate al di fuori di esse, ad esempio i <em>flash</em> nei controller<em><br />
</em></li>
</ol>
<p>Ecco come localizzare le stringhe nelle viste:</p>
<pre>&lt;%=t "hello_world" %&gt;</pre>
<p>Ovvero si utilizza un nuovo tag di stampa il cui contenuto è il placeholder che dovrà essere sostituito. Se invece ci troviamo in una situazione del genere:</p>
<pre>&lt;%= link_to "Hello, World!", "/somewhere" %&gt;</pre>
<p>la soluzione è quella di ricorrere direttamente alla classe <strong>I18n</strong>:</p>
<pre>&lt;%= link_to I18n.t('hello_world'), "/somewhere" %&gt;</pre>
<p>In questo stesso modo si possono localizzare tutte le stringhe al di fuori delle viste, ovvero il caso 2 nella lista precedente:</p>
<pre>class ExampleController &lt; ApplicationController
  def index
    flash[:notice] = I18n.t('hello_world')
  end
end</pre>
<p>A questo punto manca solo un modo per modificare la localizzazione al volo.<br />
La variabile che contiene la localizzazione attiva è <strong>I18n.locale</strong> ed è quindi necessario modificarla quando si vuole cambiare localizzazione.<br />
Un esempio per farlo è utilizzare un apposito metodo in <strong>app/controllers/application_controller.rb</strong>:</p>
<pre>class ApplicationController &lt; ActionController::Base
  before_filter :set_locale
  private
    def set_locale
      I18n.locale = params[:locale] unless params[:locale].nil?
    end
end</pre>
<p>In questo modo basta un qualsiasi link col parametro <strong>locale</strong> (ad esempio <em>/example/index?locale=en</em>) per modificare la lingua.</p>
<p>Un difetto di questa procedura è che ogni link deve contenere il parametro <strong>locale</strong>, altrimenti viene caricata la lingua di default. Una soluzione può essere quella di mettere in sessione l&#8217;ultima lingua indicata e quindi caricare la lingua dalla sessione ad ogni pagina. Il metodo può inoltre essere modificato per verificare che la localizzazione effettivamente esista.</p>
<pre>def set_locale
  # Set session[:locale] if params[:locale] exists and is an available localization
  unless params[:locale].nil?
    session[:locale] = params[:locale] if I18n.available_locales.include? params[:locale].to_sym
  end
  # Set the locale if previously set in the session, otherwise use the default one
  I18n.locale = session[:locale] unless session[:locale].nil?
end</pre>
<p>Una bottoniera carina per gestire il cambio di lingua può essere fatta inserendo nel layout questo codice:</p>
<pre>&lt;div id="flags"&gt;
   &lt;a href="?locale=it"&lt;%= " class=\"active\"" if I18n.locale.to_s == "it"%&gt;&gt;&lt;img src="/images/flags/it_IT.gif" alt="Italiano" title="Italiano"&gt;&lt;/a&gt;
   &lt;a href="?locale=en"&lt;%= " class=\"active\"" if I18n.locale.to_s == "en"%&gt;&gt;&lt;img src="/images/flags/en_EN.gif" alt="English" title="English"&gt;&lt;/a&gt;
 &lt;/div&gt;</pre>
<p>nel foglio di stile questo codice:</p>
<pre>div#flags {
 margin: 10px;
}
div#flags a img {
 padding: 4px;
}
div#flags a.active img{
 background-image: url('/images/active_flag.png');
 background-repeat: no-repeat;
 background-position: center center;
}</pre>
<p>ed utilizzando queste immagini: <img class="size-full wp-image-555 alignnone" title="active_flag" src="http://www.tommyblue.it/wp-content/uploads/2009/08/active_flag.png" alt="active_flag" width="40" height="30" /><img class="alignnone size-full wp-image-556" title="en_EN" src="http://www.tommyblue.it/wp-content/uploads/2009/08/en_EN.gif" alt="en_EN" width="24" height="24" /><img class="alignnone size-full wp-image-557" title="it_IT" src="http://www.tommyblue.it/wp-content/uploads/2009/08/it_IT.gif" alt="it_IT" width="24" height="24" /></p>
<p>Il risultato è questo, con la lingua attiva contornata da un alone celeste:</p>
<p><img class="alignnone size-full wp-image-558" title="rails_localization_flags" src="http://www.tommyblue.it/wp-content/uploads/2009/08/rails_localization_flags.png" alt="rails_localization_flags" width="79" height="49" /></p>
<p>È sufficiente cliccare su una bandiera per attivare una diversa lingua. Su <a href="http://www.deviantart.com/#order=9&amp;q=flags+pack" target="_blank">Deviant Art</a> trovate decine di <em>flags pack</em>, sbizzarritevi :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tommyblue.it/2009/08/28/come-localizzare-unapplicazione-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No such file or directory &#8211; /nonexistent</title>
		<link>http://www.tommyblue.it/2009/06/10/no-such-file-or-directory-nonexistent/</link>
		<comments>http://www.tommyblue.it/2009/06/10/no-such-file-or-directory-nonexistent/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 09:13:47 +0000</pubDate>
		<dc:creator>TommyBlue</dc:creator>
				<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Memoria usiliaria]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://www.tommyblue.it/?p=502</guid>
		<description><![CDATA[Anche questo chissà quante volte mi è successo e continuo a non ricordarmelo! :&#124; Quindi: se Ruby On Rails subito dopo il deploy con Phusion Passenger (aka mod_rails) vi saluta con un bel Error message: No such file or directory - /nonexistent Exception class: Errno::ENOENT basta impostare www-data come proprietario di config/environment.rb: chown www-data ./config/environment.rb [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.tommyblue.it/wp-content/uploads/2009/06/passenger_error.gif" rel="lightbox[502]"><img class="alignleft size-full wp-image-503" title="Passenger error" src="http://www.tommyblue.it/wp-content/uploads/2009/06/passenger_error.gif" alt="Passenger error" width="238" height="284" /></a>Anche questo chissà quante volte mi è successo e continuo a non ricordarmelo! :|</p>
<p>Quindi: se <a href="http://rubyonrails.org/" target="_blank">Ruby On Rails</a> subito dopo il deploy con <a href="http://www.modrails.com/" target="_blank">Phusion Passenger (aka mod_rails)</a> vi saluta con un bel</p>
<pre>Error message:
    No such file or directory - /nonexistent
Exception class:
    Errno::ENOENT</pre>
<p>basta impostare <strong>www-data</strong> come proprietario di <strong>config/environment.rb</strong>:</p>
<pre>chown www-data ./config/environment.rb</pre>
<p><strong>ps. Se mancano delle &#8216;r&#8217; o delle &#8216;i&#8217; è colpa di questa tastiera del cacchio, non comprate mai Kraun!!!!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tommyblue.it/2009/06/10/no-such-file-or-directory-nonexistent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aggiornare un&#8217;applicazione RubyOnRails</title>
		<link>http://www.tommyblue.it/2009/02/11/aggiornare-unapplicazione-rubyonrails/</link>
		<comments>http://www.tommyblue.it/2009/02/11/aggiornare-unapplicazione-rubyonrails/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 13:07:49 +0000</pubDate>
		<dc:creator>TommyBlue</dc:creator>
				<category><![CDATA[Memoria usiliaria]]></category>
		<category><![CDATA[Riflessioni]]></category>
		<category><![CDATA[Software Libero]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://www.tommyblue.it/?p=333</guid>
		<description><![CDATA[Aggiornare un&#8217;applicazione esistente all&#8217;ultima versione possibile di RoR è una cosa abbastanza semplice, anche se spesso bisogna poi fare i conti con qualche stringa ormai obsoleta rimasta in qualche file (ma, anche qui, niente di difficile da risolvere). Ricordiamoci di scongelare l&#8217;applicazione se lo fosse: rake rails:unfreeze Iniziamo guardando le possibili opzioni di aggiornamento disponibili [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-334" title="bruce_on_rails" src="http://www.tommyblue.it/wp-content/uploads/2009/02/bruce_on_rails.jpg" alt="bruce_on_rails" width="250" height="185" />Aggiornare un&#8217;applicazione esistente all&#8217;ultima versione possibile di RoR è una cosa abbastanza semplice, anche se spesso bisogna poi fare i conti con qualche stringa ormai obsoleta rimasta in qualche file (ma, anche qui, niente di difficile da risolvere).</p>
<p>Ricordiamoci di <em>scongelare</em> l&#8217;applicazione se lo fosse:</p>
<div class="codecolorer-container text railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rake rails:unfreeze</div></div>
<p>Iniziamo guardando le possibili opzioni di aggiornamento disponibili andando nella propria applicazione e lanciando:</p>
<div class="codecolorer-container text railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rake -T rails:update</div></div>
<p>L&#8217;output dovrebbe più o meno essere questo:</p>
<div class="codecolorer-container text railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rake rails:update &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# Update both configs, scripts and public/javascripts from Rails<br />
rake rails:update:configs &nbsp; &nbsp; &nbsp;# Update config/boot.rb from your current rails install<br />
rake rails:update:javascripts &nbsp;# Update your javascripts from your current rails install<br />
rake rails:update:scripts &nbsp; &nbsp; &nbsp;# Add new scripts to the application script/ directory</div></div>
<p>A questo punto basta eseguire in sequenza questi comandi e il gioco è fatto!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tommyblue.it/2009/02/11/aggiornare-unapplicazione-rubyonrails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

