<?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"
	>

<channel>
	<title>42</title>
	<atom:link href="http://www.42.mach7x.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.42.mach7x.com</link>
	<description>Thoughts and tips about programming with Ruby on Rails</description>
	<pubDate>Mon, 23 Jun 2008 09:03:06 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Ruby on Rails email scheduling using runner and cron</title>
		<link>http://www.42.mach7x.com/2008/06/11/ruby-on-rails-email-scheduling-using-runner-and-cron/</link>
		<comments>http://www.42.mach7x.com/2008/06/11/ruby-on-rails-email-scheduling-using-runner-and-cron/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 13:50:01 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<category><![CDATA[ruby on rails]]></category>

		<category><![CDATA[crontab]]></category>

		<category><![CDATA[email scheduling]]></category>

		<category><![CDATA[observer]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=37</guid>
		<description><![CDATA[Problem
You want to send emails from a Ruby on Rails application, when there is a specific condition on a database table. If the database table gets modified by another application outside Rails you cannot use an observer model.
Solution
We already assume that:

You are using a database
You have a model named voicemail (id, number_id, audio, created_at, updated_at)
You [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You want to send emails from a Ruby on Rails application, when there is a specific condition on a database table. If the database table gets modified by another application outside Rails you cannot use an observer model.</p>
<p><strong>Solution</strong><br />
We already assume that:</p>
<ul>
<li>You are using a database</li>
<li>You have a model named voicemail (id, number_id, audio, created_at, updated_at)</li>
<li>You have a model named number (id, voicemail_email_set, voicemail_email, &#8230;.)</li>
<li>A mail server to use (smtp in our case)</li>
<li>Another application (voice application) populates the voicemail table but with empty updated_at values</li>
</ul>
<p>So the steps we have to follow are:</p>
<ol>
<li>Change the settings in your config/environment.rb file to use the settings for your mail server, and make sure you restart your application after the changes:
<pre class="code">ActionMailer::Base.smtp_settings = {
  :address        => "yourmailserver.com",
  :port           =>  25,
  :domain         => "your.domain.com",
  :authentication => :login,
  :user_name      => "your_smtp_username",
  :password       => "your_smtp_password",
  :raise_delivery_errors  => true}</pre>
</li>
<li>Create your mailer model (ie voicemail_mailer.rb), in app/models:
<pre class="code">class VoicemailMailer < ActionMailer::Base
   # We need the open-uri to be able to open url *** if the file to attach is in an http location ***
  require 'open-uri'

  def sent(email_to,email_from,email_subject,email_body,voicemail_to_send)
    # Check to see if we have a file for the email body message
    @subject    = email_subject
    @body       = email_body
    @recipients = email_to
    @from       = email_from
    @sent_on    = Time.now

    # Split the file in directory and filename
    file_path = File.split(voicemail_to_send)
    file_dir  = file_path[0]
    file_name = file_path[1]

    # Get the file
    tmp_file = open(voicemail_to_send).read

    part( :content_type => &#8220;application/wav&#8221;,
          :disposition => &#8220;attachment; filename=#{file_name}&#8221;,
          :transfer_encoding => &#8220;base64&#8243;) do |attachment|
            attachment.body = tmp_file
    end
  end
end
</pre>
</li>
<li>Create your email scheduler in file lib/email_scheduler.rb:
<pre class="code">#!/usr/bin/env /path_to_your_app/script/runner

# get all the voicemails that have not been sent yet
voicemails_to_email = VoiceMail.find(:all, :conditions => 'updated_at is null')

# For all the voicemails we have, send them and update the field date_sent
for vm2email in voicemails_to_email do
  # Get the number for the voicemail
  number = Number.find(vm2email.number_id)

  # check to see if the send to email is set for the number
  if number.voicemail_email_set
    # Get number details (email_to,email_from etc)
    email_to          = number.voicemail_email
    voicemail_to_send = vm2email.audio
    # Set other details
    email_from      = 'Service@yourdomain.com'
    email_subject   = 'Please find attached your voicemail message'
    email_body      = "Received on: #{Time.now} \n for number: #{number.phone_no}"

    # Now send the email
    VoicemailMailer.deliver_sent(email_to,email_from,email_subject,email_body,voicemail_to_send)

    # And update the record's date_sent field
    vm2email.updated_at = Time.now
    vm2email.save
  end
end
</li>
<li>Create a task in your crontab that runs the scheduler (every five minutes):
<pre class="code">0,5,10,15,20,25,30,35,40,45,50,55 * * * * path_to_your_ror_app/lib/email_scheduler.rb</pre>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2008/06/11/ruby-on-rails-email-scheduling-using-runner-and-cron/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Rails 2 new ways</title>
		<link>http://www.42.mach7x.com/2008/05/28/rails-2-new-ways/</link>
		<comments>http://www.42.mach7x.com/2008/05/28/rails-2-new-ways/#comments</comments>
		<pubDate>Wed, 28 May 2008 12:21:28 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
		
		<category><![CDATA[ruby on rails]]></category>

		<category><![CDATA[migrations]]></category>

		<category><![CDATA[Rails]]></category>

		<category><![CDATA[Ruby On Rails 2]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=36</guid>
		<description><![CDATA[Problem
To get used to the new ways of working with Rails 2.
Solution
Here are some of the new ways of doing things in Rails 2.

Create a scaffold and migration on one step:
./script/generate scaffold product fied1_name:string field2_name:string field3_name:float
  Make sure that you don&#8217;t have any previous migration(ie manually created) for the same model, as the generator [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
To get used to the new ways of working with Rails 2.</p>
<p><strong>Solution</strong><br />
Here are some of the new ways of doing things in Rails 2.</p>
<ol>
<li>Create a scaffold and migration on one step:
<pre class="code">./script/generate scaffold product fied1_name:string field2_name:string field3_name:float</pre>
<p>  Make sure that you don&#8217;t have any previous migration(ie manually created) for the same model, as the generator will stop and won&#8217;t overwrite the previous migration.
  </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2008/05/28/rails-2-new-ways/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Upgrading Ruby on Rails application from 1.2.3 to 2.0.2</title>
		<link>http://www.42.mach7x.com/2008/05/24/upgrading-ruby-on-rails-application-from-123-to-202/</link>
		<comments>http://www.42.mach7x.com/2008/05/24/upgrading-ruby-on-rails-application-from-123-to-202/#comments</comments>
		<pubDate>Sat, 24 May 2008 12:47:24 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
		
		<category><![CDATA[ruby on rails]]></category>

		<category><![CDATA[1.2.3]]></category>

		<category><![CDATA[2.0.2]]></category>

		<category><![CDATA[environment.rb]]></category>

		<category><![CDATA[gem]]></category>

		<category><![CDATA[secret_key]]></category>

		<category><![CDATA[session]]></category>

		<category><![CDATA[upgrading]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=35</guid>
		<description><![CDATA[Problem
Upgrading an existing Ruby on Rails application from 1.2.3, to 2.0.2, presents few problems. I will try and keep a record of the ones I encounter along the way, here.
Solution

Change the config/environment.rb to let the application know to use the 2.0.2 gem rail version,
    change the following line from:
RAILS_GEM_VERSION = '1.2.3' unless [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
Upgrading an existing Ruby on Rails application from 1.2.3, to 2.0.2, presents few problems. I will try and keep a record of the ones I encounter along the way, here.</p>
<p><strong>Solution</strong></p>
<ol>
<li>Change the config/environment.rb to let the application know to use the 2.0.2 gem rail version,</li>
<p>    change the following line from:</p>
<pre class="code">RAILS_GEM_VERSION = '1.2.3' unless defined? RAILS_GEM_VERSION</pre>
<p>    to:</p>
<pre class="code">RAILS_GEM_VERSION = "2.0.2" unless defined? RAILS_GEM_VERSION</pre>
<li>Run the following to generate the secret key for the application:</li>
<pre class="code">rake secret</pre>
<li>Copy the magic key in a new section in your config/environment.rb as in:</li>
<pre class="code">...

    # config.log_level = :debug

    # Your secret key for verifying cookie session data integrity.
    # If you change this key, all old sessions will become invalid!
    # Make sure the secret is at least 30 characters and all random,
    # no regular words or you'll be exposed to dictionary attacks.
    config.action_controller.session = {
      :session_key =&gt; '_yourapplication_session',
      :secret      =&gt; 'long_string_generated_from_rake_secret'
    }</pre>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2008/05/24/upgrading-ruby-on-rails-application-from-123-to-202/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Dreamhost passenger (mod_rails) announced</title>
		<link>http://www.42.mach7x.com/2008/05/13/dreamhost-passenger-mod_rails-announced/</link>
		<comments>http://www.42.mach7x.com/2008/05/13/dreamhost-passenger-mod_rails-announced/#comments</comments>
		<pubDate>Tue, 13 May 2008 22:09:57 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<category><![CDATA[ruby on rails]]></category>

		<category><![CDATA[Dreamhost]]></category>

		<category><![CDATA[mod_rails]]></category>

		<category><![CDATA[Passenger]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=34</guid>
		<description><![CDATA[Today, there was an announcement about Dreamhost, having the new Passenger (mod_rails) feature ready for use with Ruby on Rails applications.
The full announcement is here.
It should be changing the way Rails applications are deployed, making it much easier.
]]></description>
			<content:encoded><![CDATA[<p>Today, there was an announcement about Dreamhost, having the new Passenger (mod_rails) feature ready for use with Ruby on Rails applications.<br />
The full announcement is <a href="http://www.dreamhoststatus.com/2008/05/13/new-feature-passenger-mod_rails/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.dreamhoststatus.com');">here</a>.</p>
<p>It should be changing the way Rails applications are deployed, making it much easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2008/05/13/dreamhost-passenger-mod_rails-announced/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Google Analytics UID</title>
		<link>http://www.42.mach7x.com/2008/05/08/google-analytics-uid/</link>
		<comments>http://www.42.mach7x.com/2008/05/08/google-analytics-uid/#comments</comments>
		<pubDate>Thu, 08 May 2008 12:33:34 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<category><![CDATA[drupal]]></category>

		<category><![CDATA[google analytics]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=33</guid>
		<description><![CDATA[Problem
You want to find out your UID for a specific domain that you have set up with google analytics.
Solution
When you first create the tracking code for your website, it&#8217;s quite obvious how to get the UID for that specific website.
If you decide later on to change your site, from drupal to wordrpess for example, it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You want to find out your UID for a specific domain that you have set up with google analytics.</p>
<p><strong>Solution</strong><br />
When you first create the tracking code for your website, it&#8217;s quite obvious how to get the UID for that specific website.<br />
If you decide later on to change your site, from drupal to wordrpess for example, it&#8217;s not quite clear where to get this UID, to use it with the new tracking plugin in the new site (which still uses the same domain name).<br />
After some searching it turns out that to be able to find it you have to do the following:</p>
<ol>
<li>Log in to your Google Analytics Account</li>
<li>Click on the &#8216;Edit&#8217; link under Settings for the domain you want to find the UID</li>
<li>In the new page click on the link &#8216;Check Status&#8217; after Receiving Data at the top</li>
<li>Your UID should be in the text box with something like _uacct = &#8220;UA-xxxxxxx-x&#8221;;</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2008/05/08/google-analytics-uid/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ruby incorrect encoding of pound sign(£)</title>
		<link>http://www.42.mach7x.com/2008/05/07/ruby-incorrect-encoding-of-pound-sign/</link>
		<comments>http://www.42.mach7x.com/2008/05/07/ruby-incorrect-encoding-of-pound-sign/#comments</comments>
		<pubDate>Wed, 07 May 2008 15:38:15 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<category><![CDATA[ruby on rails]]></category>

		<category><![CDATA[£ sign]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[url encoding]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=32</guid>
		<description><![CDATA[Problem
You want to pass the £ sign to an http service, but the ruby CGI.escape encodes it incorrectly.
Solution
After using ruby&#8217;s CGI.escape for the string as:
sms_msg_tmp=CGI.escape(sms_code)
then replace the encoding with the pound sign encoding as in:
sms_msg=sms_msg_tmp.gsub('%C2%A3','%A3')
It should then pass the correct value for the £ sign.
]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You want to pass the £ sign to an http service, but the ruby CGI.escape encodes it incorrectly.</p>
<p><strong>Solution</strong><br />
After using ruby&#8217;s CGI.escape for the string as:</p>
<pre class="code">sms_msg_tmp=CGI.escape(sms_code)</pre>
<p>then replace the encoding with the pound sign encoding as in:</p>
<pre class="code">sms_msg=sms_msg_tmp.gsub('%C2%A3','%A3')</pre>
<p>It should then pass the correct value for the £ sign.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2008/05/07/ruby-incorrect-encoding-of-pound-sign/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Disabling rails web site when using mongrel,Apache,capistrano 1.4.1</title>
		<link>http://www.42.mach7x.com/2008/05/07/disabling-rails-web-site-when-using-mongrelapachecapistrano-141/</link>
		<comments>http://www.42.mach7x.com/2008/05/07/disabling-rails-web-site-when-using-mongrelapachecapistrano-141/#comments</comments>
		<pubDate>Wed, 07 May 2008 14:01:46 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
		
		<category><![CDATA[ruby on rails]]></category>

		<category><![CDATA[apache]]></category>

		<category><![CDATA[capistrano]]></category>

		<category><![CDATA[maintenance]]></category>

		<category><![CDATA[mongrel]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=31</guid>
		<description><![CDATA[Problem
You want to disable your rails web site for maintenance, but your application uses an older capistrano version than the one currently installed.
Solution
According to the RubyOnRails Cookbook recipe 13.12, it should only be a case of running cap disable_web (enable_web).
But in the meantime you have upgraded your capistrano version to version 2, and started using [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You want to disable your rails web site for maintenance, but your application uses an older capistrano version than the one currently installed.</p>
<p><strong>Solution</strong><br />
According to the RubyOnRails Cookbook recipe 13.12, it should only be a case of running cap disable_web (enable_web).<br />
But in the meantime you have upgraded your capistrano version to version 2, and started using mongrel server as well.<br />
So if you are using virtual severs and proxy with mongrel, the first thing to do is add the following in your Apache configuration file:</p>
<pre class="code">RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [R]</pre>
<p>If you needed to make the above change then you will have to restart apache in your server.</p>
<p>Then in your local pc you can run the following:</p>
<pre class="code">export REASON="Maintenance for MySQL upgrade"
export UNTIL="Sat May 10 15:30:00 2008"
cap _1.4.1_ disable_web (to put it in maintenance)
cap _1.4.1_ enable_web (to restart it again)</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2008/05/07/disabling-rails-web-site-when-using-mongrelapachecapistrano-141/feed/</wfw:commentRss>
		</item>
		<item>
		<title>git: fatal error: `chdir&#8217; failed: permission denied.</title>
		<link>http://www.42.mach7x.com/2008/04/24/git-fatal-error-chdir-failed-permission-denied/</link>
		<comments>http://www.42.mach7x.com/2008/04/24/git-fatal-error-chdir-failed-permission-denied/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 13:20:30 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<category><![CDATA[ruby on rails]]></category>

		<category><![CDATA[git]]></category>

		<category><![CDATA[heroku]]></category>

		<category><![CDATA[Mandriva]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=30</guid>
		<description><![CDATA[Problem
Trying to use the heroku gem to clone a project and do local modifications I got the following error:
git: fatal error: `chdir' failed: permission denied.
Solution
It turns out that in Mandriva, when using:
sudo urpmi git
what gets installed is the &#8216;GNU Interactive Tools&#8217; that has nothing to do with the git version control system.
So make sure you [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
Trying to use the heroku gem to clone a project and do local modifications I got the following error:</p>
<pre class="code">git: fatal error: `chdir' failed: permission denied.</pre>
<p><strong>Solution</strong><br />
It turns out that in Mandriva, when using:</p>
<pre class="code">sudo urpmi git</pre>
<p>what gets installed is the &#8216;GNU Interactive Tools&#8217; that has nothing to do with the git version control system.<br />
So make sure you first uninstall the git installed:</p>
<pre class="code">sudo rpm -e git</pre>
<p>and then install the Git - Fast version control system, by doing:</p>
<pre class="code">sudo urpmi git-core</pre>
<p>You should then be able to clone a heroku application:</p>
<pre class="code">heroku clone myapp</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2008/04/24/git-fatal-error-chdir-failed-permission-denied/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ext.ux.grid has no properties error</title>
		<link>http://www.42.mach7x.com/2008/04/23/extuxgrid-has-no-properties-error/</link>
		<comments>http://www.42.mach7x.com/2008/04/23/extuxgrid-has-no-properties-error/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 15:43:23 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
		
		<category><![CDATA[ruby on rails]]></category>

		<category><![CDATA[ExtJS]]></category>

		<category><![CDATA[ext_scaffold]]></category>

		<category><![CDATA[heroku]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=29</guid>
		<description><![CDATA[Problem
Trying to use ExtJS with RubyOnRails on Heroku, gives the following error and a blank page in Firebug.
Ext.ux.grid has no properties
...
Line 141
Solution
In Heroku, you will probably have to manually upload the files from the ExtJS library, as well as the ext_scaffold plugin.
When you do that, two files that ext_scaffold needs, and which they should be [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
Trying to use ExtJS with RubyOnRails on Heroku, gives the following error and a blank page in Firebug.</p>
<pre class="code">Ext.ux.grid has no properties
...
Line 141</pre>
<p><strong>Solution</strong><br />
In Heroku, you will probably have to manually upload the files from the ExtJS library, as well as the ext_scaffold plugin.<br />
When you do that, two files that ext_scaffold needs, and which they should be located in ext_scaffold/assets/javascripts should be copied to public/javascripts.<br />
The files are:</p>
<pre class="code">ext_datetime.js
ext_searchfield.js</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2008/04/23/extuxgrid-has-no-properties-error/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Converting Paradox tables to MySQL sql in Linux</title>
		<link>http://www.42.mach7x.com/2008/04/21/converting-paradox-tables-to-mysql-in-linux/</link>
		<comments>http://www.42.mach7x.com/2008/04/21/converting-paradox-tables-to-mysql-in-linux/#comments</comments>
		<pubDate>Mon, 21 Apr 2008 13:11:07 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<category><![CDATA[exporting]]></category>

		<category><![CDATA[MySQL]]></category>

		<category><![CDATA[paradox]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=28</guid>
		<description><![CDATA[Problem
You want to convert some legacy tables created in Paradox (.db, .px) to another format so you can use it in MySQL.
Solution
Download the px tools from here.
Follow the instructions, in the INSTALL file after you untar the file.
You should have to do the usual three step linux installation:
configure
make
sudo make install
Afterwards to make sure that the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You want to convert some legacy tables created in Paradox (.db, .px) to another format so you can use it in MySQL.</p>
<p><strong>Solution</strong><br />
Download the px tools from <a href="http://jan.kneschke.de/projects/pxtools/" onclick="javascript:pageTracker._trackPageview ('/outbound/jan.kneschke.de');">here</a>.</p>
<p>Follow the instructions, in the INSTALL file after you untar the file.<br />
You should have to do the usual three step linux installation:</p>
<pre class="code">configure
make
sudo make install</pre>
<p>Afterwards to make sure that the .db file is a paradox file run:</p>
<pre class="code">pxinfo -f  path/to/paradox/db/file.db</pre>
<p>The program should read the header and report back with something along the lines:</p>
<pre class="code">File-Version: Paradox 7.x
Filetype: indexed .DB
....</pre>
<p>To export each Paradox db file to an sql statement run the following:</p>
<pre class="code">pxsqldump -d mysql -f path/to/paradox/file.db > path/to/mysql/exported/file.sql</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2008/04/21/converting-paradox-tables-to-mysql-in-linux/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
