<?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>Lasse Bunk&#039;s weblog</title>
	<atom:link href="http://lassebunk.dk/feed/" rel="self" type="application/rss+xml" />
	<link>http://lassebunk.dk</link>
	<description>Ruby on Rails, programming, and SEO</description>
	<lastBuildDate>Mon, 11 Mar 2013 19:19:40 +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>Sublime Text: Convert Ruby 1.8 to 1.9 style hash syntax</title>
		<link>http://lassebunk.dk/2013/03/11/sublime-text-convert-ruby-1-8-to-1-9-style-hash-syntax/</link>
		<comments>http://lassebunk.dk/2013/03/11/sublime-text-convert-ruby-1-8-to-1-9-style-hash-syntax/#comments</comments>
		<pubDate>Mon, 11 Mar 2013 18:57:11 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Sublime Text]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=2802</guid>
		<description><![CDATA[How to automatically replace and convert Ruby 1.8 to 1.9 style hash syntax using Sublime Text without any plugins or gems.]]></description>
			<content:encoded><![CDATA[<p><a href="http://ruby-lang.org">Ruby</a> 1.9 and 2.0 has a new hash syntax. In Ruby 1.8 it was:</p>
<pre class="brush: ruby; title: ; notranslate">
hash = { :one =&gt; &quot;first value&quot;, :two =&gt; &quot;second value&quot; }
</pre>
<p>In Ruby 1.9 and 2.0, this can now be written as:</p>
<pre class="brush: ruby; title: ; notranslate">
hash = { one: &quot;first value&quot;, two: &quot;second value&quot; }
</pre>
<p>Saving three characters per key.</p>
<p>If you&#8217;re using <a href="http://www.sublimetext.com/">Sublime Text</a>, it&#8217;s really easy to do this conversion automatically.</p>
<p>Here&#8217;s how to do it – use it at your own risk, and <strong>take a backup first</strong>:</p>
<p><img src="http://lassebunk.dk/media/2013/03/sublime-text-replace-ruby-hash-syntax.png" alt="" title="sublime-text-replace-ruby-hash-syntax" width="470" height="113" class="alignnone size-full wp-image-2825" /></p>
<ol>
<li>Go to <em>Find</em> &rarr; <em>Find in Files</em>&#8230;</li>
<li>Enable <em>Regular expressions</em> – make sure the <code>.*</code> button is activated</li>
<li>In the <em>Find</em> box: <code>:([a-z_\d]+) =></code></li>
<li>In the <em>Replace</em> box: <code>\1:</code></li>
<li>Click the <em>Replace</em> button. This will replace matches in all of your files in Sublime Text. It will also go through non-Ruby files so it might be a good idea to set a <em>Where</em> file pattern to <code>*.rb</code> or <code>*.html.erb</code>. As I said, <em>use at your own risk</em>, and take a backup first.</li>
<p>Enjoy.</p>
<p>
<a href="http://twitter.com/lassebunk" onclick="abtest.trackGoal(21, this);">Follow me on Twitter</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2013/03/11/sublime-text-convert-ruby-1-8-to-1-9-style-hash-syntax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Examples of Ruby on Rails</title>
		<link>http://lassebunk.dk/2012/12/31/examples-of-ruby-on-rails/</link>
		<comments>http://lassebunk.dk/2012/12/31/examples-of-ruby-on-rails/#comments</comments>
		<pubDate>Sun, 30 Dec 2012 23:35:52 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[Introduction]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=2712</guid>
		<description><![CDATA[Basic set of examples to read if you want to learn Ruby on Rails.]]></description>
			<content:encoded><![CDATA[<p>When I want to learn a new programming language or framework, I usually first try to find some examples to look at. Many times I have found it hard to find a single page with some good examples on how a language works. Not a tutorial, just examples. Here is a basic set of examples I would find nice to read if I wanted to learn about the <a href="http://rubyonrails.org">Ruby on Rails</a> web application development framework. Find more resources for learning the framework at the bottom of the post.</p>
<h2>New Rails project</h2>
<p>In the shell:</p>
<pre class="brush: bash; title: ; notranslate">
$ rails new example_project
$ cd example_project
</pre>
<h2>Models</h2>
<p>In <em>app/models/post.rb</em>:</p>
<pre class="brush: ruby; title: ; notranslate">
class Post &lt; ActiveRecord::Base
  has_many :comments, :dependent =&gt; :destroy # post.comments with autodelete
  validates_presence_of :title, :content
end
</pre>
<p>In <em>app/models/comment.rb</em>:</p>
<pre class="brush: ruby; title: ; notranslate">
class Comment &lt; ActiveRecord::Base
  belongs_to :post # comment.post
  validates_presence_of :text
end
</pre>
<h2>Controllers</h2>
<p>In <em>app/controllers/posts_controller.rb</em>:</p>
<pre class="brush: ruby; title: ; notranslate">
class PostsController &lt; ApplicationController
  def index
    @posts = Post.all
  end

  def show
    @post = Post.find(params[:id])
  end

  def new
    @post = Post.new
  end

  def create
    @post = Post.new(params[:post])

    if @post.save
      redirect_to @post, :notice =&gt; &quot;The post was created successfully.&quot;
    else
      render :new
    end
  end

  def edit
    @post = Post.find(params[:id])
  end

  def update
    @post = Post.find(params[:id])

    if @post.update_attributes(params[:post])
      redirect_to @post, :notice =&gt; &quot;The post was updated successfully.&quot;
    else
      render :edit
    end
  end

  def destroy
    @post = Post.find(params[:id])
    @post.destroy

    redirect_to posts_path, :notice =&gt; &quot;The post was deleted successfully.&quot;
  end
end
</pre>
<h2>Views</h2>
<p>In <em>app/views/posts/index.html.erb</em>:</p>
<pre class="brush: ruby; title: ; notranslate">
&lt;h1&gt;All posts&lt;/h1&gt;

&lt;ul&gt;
  &lt;% @posts.each do |post| %&gt;
    &lt;li&gt;&lt;%= link_to post.title, post %&gt;&lt;/li&gt;
  &lt;% end %&gt;
&lt;/ul&gt;

&lt;p&gt;
  &lt;%= link_to &quot;New post&quot;, new_post_path %&gt;
  &lt;%= link_to &quot;Back to homepage&quot;, root_path %&gt;
&lt;/p&gt;
</pre>
<p>In <em>app/views/posts/show.html.erb</em>:</p>
<pre class="brush: ruby; title: ; notranslate">
&lt;h1&gt;&lt;%= @post.title %&gt;&lt;/h1&gt;

&lt;p&gt;
  Created: &lt;%= @post.created_at %&gt;
&lt;/p&gt;

&lt;p&gt;
  &lt;%= link_to &quot;Delete post&quot;, @post, :method =&gt; :delete %&gt;
&lt;/p&gt;

&lt;p&gt;
  &lt;%= @post.content %&gt;
&lt;/p&gt;

&lt;h2&gt;Comments&lt;/h2&gt;
&lt;% @post.comments.each do |comment| %&gt;
  &lt;p&gt;
    &lt;%= comment.text %&gt;
  &lt;/p&gt;
&lt;% end %&gt;

&lt;%= link_to &quot;Back to posts&quot;, posts_path %&gt;
</pre>
<p>In <em>app/views/posts/new.html.erb</em>:</p>
<pre class="brush: ruby; title: ; notranslate">
&lt;h1&gt;New post&lt;/h1&gt;

&lt;%= form_for @post do |f| %&gt;
  &lt;p&gt;
    &lt;%= f.label :title %&gt;&lt;br /&gt;
    &lt;%= f.text_field :title %&gt;
  &lt;/p&gt;

  &lt;p&gt;
    &lt;%= f.label :content %&gt;&lt;br /&gt;
    &lt;%= f.text_area :content %&gt;
  &lt;/p&gt;

  &lt;p&gt;
    &lt;%= f.submit &quot;Create post&quot; %&gt;
  &lt;/p&gt;
&lt;% end %&gt;
</pre>
<h2>View layouts</h2>
<p>In <em>app/views/layouts/application.html.erb</em>:</p>
<pre class="brush: ruby; title: ; notranslate">
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Rails example&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;% if flash[:notice] %&gt;
      &lt;p&gt;&lt;%= flash[:notice] %&gt;&lt;/p&gt;
    &lt;% end %&gt;
    &lt;%= yield %&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
<h2>View partials</h2>
<p>In <em>app/views/shared/_example_partial.html.erb</em>:</p>
<pre class="brush: ruby; title: ; notranslate">
&lt;p&gt;
  Content of example variable: &lt;%= example_variable %&gt;
&lt;/p&gt;
</pre>
<p>In another view:</p>
<pre class="brush: ruby; title: ; notranslate">
&lt;%= render &quot;shared/example_partial&quot;, :example_variable =&gt; &quot;Example content&quot; %&gt;
</pre>
<h2>Rendering other formats</h2>
<p>In <em>app/controllers/posts_controller.rb</em>:</p>
<pre class="brush: ruby; title: ; notranslate">
class PostsController &lt; ApplicationController
  def index
    @posts = Post.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render :json =&gt; @posts }
    end
  end
end
</pre>
<p>In the browser:<br />
<code>http://localhost:3000/posts.json</code></p>
<h2>Database migrations</h2>
<p>In the shell:</p>
<pre class="brush: bash; title: ; notranslate">
$ rails generate model post title:string content:text
</pre>
<p>In <em>db/migrate/20121228215855_create_posts.rb</em>:</p>
<pre class="brush: ruby; title: ; notranslate">
class CreatePosts &lt; ActiveRecord::Migration
  def change
    create_table :posts do |t|
      t.string :title
      t.text :content

      t.timestamps
    end
  end
end
</pre>
<p>In the shell:</p>
<pre class="brush: bash; title: ; notranslate">
$ rails generate model comment post_id:integer text:text
</pre>
<p>In <em>db/migrate/20121228220327_create_comments.rb</em>:</p>
<pre class="brush: ruby; title: ; notranslate">
class CreateComments &lt; ActiveRecord::Migration
  def change
    create_table :comments do |t|
      t.integer :post_id
      t.text :text

      t.timestamps
    end

    add_index :comments, :post_id
  end
end
</pre>
<p>Then, in the shell:</p>
<pre class="brush: bash; title: ; notranslate">
$ rake db:migrate
</pre>
<h2>Routing</h2>
<p>In <em>config/routes.rb</em>:</p>
<pre class="brush: ruby; title: ; notranslate">
ExampleProject::Application.routes.draw do
  resources :posts do # /posts, /posts/123, etc. =&gt; PostsController
    resources :comments # /posts/123/comments, /posts/123/comments/345, etc. =&gt; CommentsController
  end

  match &quot;contact&quot; =&gt; &quot;home#contact&quot; # /contact =&gt; HomeController#contact

  root :to =&gt; &quot;home#index&quot; # / =&gt; HomeController#index
end
</pre>
<h2>Plugins</h2>
<p>In <em>Gemfile</em>:</p>
<pre class="brush: ruby; title: ; notranslate">
# To use jQuery
gem 'jquery-rails'

# To use Jbuilder templates for JSON
gem 'jbuilder'

# Deploy with Capistrano
gem 'capistrano'
</pre>
<p>In the shell:</p>
<pre class="brush: bash; title: ; notranslate">
$ bundle install
</pre>
<h2>Rails development server</h2>
<p>In the shell:</p>
<pre class="brush: bash; title: ; notranslate">
$ rails server
</pre>
<p>To see posts:<br />
<code>http://localhost:3000/posts</code></p>
<p>To see a single post:<br />
<code>http://localhost:3000/posts/123</code></p>
<p>To edit a post:<br />
<code>http://localhost:3000/posts/123/edit</code></p>
<h2>See also</h2>
<ul>
<li><a href="http://lassebunk.dk/2011/09/05/what-is-ruby-on-rails-an-introduction/">What is Ruby on Rails (an introduction)</a> – a general introduction to Ruby on Rails</li>
<li><a href="http://rubyonrails.org">Ruby on Rails official site</a> – the official site with info on Ruby on Rails</li>
<li><a href="http://guides.rubyonrails.org">Ruby on Rails official guides</a> – introductory guides to get started</li>
<li><a href="http://railscasts.com">RailsCasts</a> – a lot of useful screencasts about Ruby on Rails</li>
<li><a href="http://tryruby.org">TryRuby</a> – an interactive shell where you can try the Ruby language</li>
<li><a href="http://en.wikipedia.org/wiki/Ruby_%28programming_language%29">Ruby on Wikipedia</a> – Wikipedia article on the Ruby language</li>
</ul>
<p>
<a href="http://twitter.com/lassebunk" onclick="abtest.trackGoal(21, this);">Follow me on Twitter</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2012/12/31/examples-of-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Creating a public symlink using Capistrano</title>
		<link>http://lassebunk.dk/2012/10/23/creating-a-public-symlink-using-capistrano/</link>
		<comments>http://lassebunk.dk/2012/10/23/creating-a-public-symlink-using-capistrano/#comments</comments>
		<pubDate>Tue, 23 Oct 2012 18:15:04 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Symlink]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=2685</guid>
		<description><![CDATA[How to create a public symlink that's shared between releases using Capistrano.]]></description>
			<content:encoded><![CDATA[<p>So, I have a folder containing static sitemap files for my site. These sitemaps are generated and saved in my <code>public/sitemap</code> folder. However, I want to keep these sitemap files between deployments.</p>
<p>What I need is a symlink from <code>public/sitemap</code> that&#8217;s pointing to <code>shared/sitemap</code>.</p>
<p>I use <a href="https://github.com/capistrano/capistrano">Capistrano</a> for my deployments, so I need the following task (I renamed my <code>sitemap</code> namespace and folder to better reflect other needs you might have):</p>
<pre class="brush: ruby; title: ; notranslate">
after &quot;deploy:update_code&quot;, &quot;my_namespace:symlink&quot;

namespace :my_namespace do
  desc &quot;Create symlink&quot;
  task :symlink do
    run &quot;rm -rf #{release_path}/public/my_folder&quot;
    run &quot;mkdir -p #{shared_path}/my_folder&quot;
    run &quot;ln -nfs #{shared_path}/my_folder #{release_path}/public/my_folder&quot;
  end
end
</pre>
<p>This will remove any existing <code>public/my_folder</code> folder (e.g. if it was deployed from your development repository), create the <code>shared/my_folder</code> folder (if it doesn&#8217;t exist), and at last create the symlink from <code>public/my_folder</code> to <code>shared/my_folder</code>.</p>
<p>As easy as that :-) Hope you can use it.</p>
<p>
<a href="http://twitter.com/lassebunk" onclick="abtest.trackGoal(21, this);">Follow me on Twitter</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2012/10/23/creating-a-public-symlink-using-capistrano/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Translate your Ruby on Rails models and database tables using acts_as_translatable</title>
		<link>http://lassebunk.dk/2012/05/15/translate-your-ruby-on-rails-models-and-database-tables-using-acts_as_translatable/</link>
		<comments>http://lassebunk.dk/2012/05/15/translate-your-ruby-on-rails-models-and-database-tables-using-acts_as_translatable/#comments</comments>
		<pubDate>Tue, 15 May 2012 15:32:39 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Fields]]></category>
		<category><![CDATA[I18n]]></category>
		<category><![CDATA[Localization]]></category>
		<category><![CDATA[Models]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Translation]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=2648</guid>
		<description><![CDATA[Ruby on Rails plugin for easy translation of models and database tables.]]></description>
			<content:encoded><![CDATA[<p><a href="https://github.com/lassebunk/acts_as_translatable">acts_as_translatable</a> is a plugin for easy translation of your Ruby on Rails models and database tables.</p>
<h2>Installation</h2>
<p>In your Gemfile:</p>
<pre class="brush: ruby; title: ; notranslate">
gem 'acts_as_translatable'
</pre>
<p>Install the new gem:</p>
<pre class="brush: bash; title: ; notranslate">
bundle install
</pre>
<h2>Example</h2>
<p>Generate translations for a category model with name and description fields, with default locale set to ‘en’ (English):</p>
<pre class="brush: bash; title: ; notranslate">
$ rails generate acts_as_translatable en category name description
</pre>
<p>This will create the necessary migration. Then run:</p>
<pre class="brush: bash; title: ; notranslate">
$ rake db:migrate
</pre>
<p>Then add to <strong>app/models/category.rb</strong>:</p>
<pre class="brush: ruby; title: ; notranslate">
class Category &lt; ActiveRecord::Base
  acts_as_translatable_on :name, :description
  ...
end
</pre>
<p>And play around with I18n:</p>
<pre class="brush: ruby; title: ; notranslate">
I18n.locale = &quot;en&quot;
Category.first.update_attribute :name, &quot;English name&quot;

I18n.locale = &quot;de&quot;
Category.first.update_attribute :name, &quot;Deutsche Name&quot;
</pre>
<p>Also try in combination with my <a href="https://github.com/lassebunk/translate_acts_as_translatable_models">translate_acts_as_translatable_models</a> plugin to automatically translate your acts_as_translatable enabled models.</p>
<p>Have fun! Please send comments and suggestions to <a href="mailto:lassebunk@gmail.com">lassebunk@gmail.com</a>, and issues at <a href="https://github.com/lassebunk/acts_as_translatable/issues">GitHub</a>, please :)</p>
<p>
<a href="http://twitter.com/lassebunk" onclick="abtest.trackGoal(21, this);">Follow me on Twitter</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2012/05/15/translate-your-ruby-on-rails-models-and-database-tables-using-acts_as_translatable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Translate your Ruby on Rails YAML files using Bing</title>
		<link>http://lassebunk.dk/2012/05/09/translate-your-ruby-on-rails-yaml-files-using-bing/</link>
		<comments>http://lassebunk.dk/2012/05/09/translate-your-ruby-on-rails-yaml-files-using-bing/#comments</comments>
		<pubDate>Tue, 08 May 2012 22:44:06 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Bing]]></category>
		<category><![CDATA[I18n]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Translation]]></category>
		<category><![CDATA[YAML]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=2639</guid>
		<description><![CDATA[This plugin allows you to simply translate your Ruby on Rails YAML files into any language using Bing.]]></description>
			<content:encoded><![CDATA[<p>I have created a plugin named <a href="https://github.com/lassebunk/bing_translate_yaml">bing_translate_yaml</a> that allows you to simply translate your <a href="http://rubyonrails.org">Ruby on Rails</a> <a href="http://yaml.org/">YAML</a> files into any language using <a href="http://www.bing.com/">Bing</a>. The plugin takes your YAML files from the <strong>config/locales</strong> folder and converts them to any language of your choice.</p>
<p>In your <strong>Gemfile</strong>:</p>
<pre class="brush: ruby; title: ; notranslate">
gem 'bing_translate_yaml'
</pre>
<p>Then run:</p>
<pre class="brush: bash; title: ; notranslate">
$ bundle install
</pre>
<p>Make sure you have your translation files in e.g.:</p>
<pre class="brush: bash; title: ; notranslate">
config/locales/en.yml (English)
config/locales/de.yml (German)
config/locales/es.yml (Spanish)
</pre>
<p>Then run:</p>
<pre class="brush: bash; title: ; notranslate">
$ rake translate from=en to=es
</pre>
<p>This will create (or update) the following file:</p>
<pre class="brush: bash; title: ; notranslate">
config/locales/es.yml
</pre>
<p>Simple as cake! Enjoy :-)</p>
<p>
<a href="http://twitter.com/lassebunk" onclick="abtest.trackGoal(21, this);">Follow me on Twitter</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2012/05/09/translate-your-ruby-on-rails-yaml-files-using-bing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating your own WordPress plugin database migration framework</title>
		<link>http://lassebunk.dk/2012/01/14/wordpress-plugin-database-migration-framework/</link>
		<comments>http://lassebunk.dk/2012/01/14/wordpress-plugin-database-migration-framework/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 22:58:42 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[Migration]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=2413</guid>
		<description><![CDATA[How to create a database migration framework for WordPress that automatically migrates changes to your plugin database structure.]]></description>
			<content:encoded><![CDATA[<p>So, how do you migrate changes to your database structure from one version to another (like you may know it from <a href="http://guides.rubyonrails.org/migrations.html">Ruby on Rails</a>) when you are writing a WordPress plugin? Here&#8217;s one way to do it.</p>
<p>Let&#8217;s assume that the database migration should take place when the plugin is activated. Assuming your plugin is named <strong>myplugin</strong>, put this code in the <strong>myplugin.php</strong> file:</p>
<pre class="brush: php; title: ; notranslate">
register_activation_hook(__FILE__, 'myplugin_install');
</pre>
<p>This makes WordPress execute the <code>myplugin_install()</code> method when the user activates your plugin.</p>
<p>Next, add this method:</p>
<pre class="brush: php; title: ; notranslate">
function myplugin_install() {
  myplugin_migrate();
}
</pre>
<p>And our migration method:</p>
<pre class="brush: php; title: ; notranslate">
function myplugin_migrate() {
  global $wpdb;

  $migs = myplugin_migrations();

  $current_migration = get_option('myplugin_current_migration', 0);
  $needed_migration = count($migs);

  for ($i = $current_migration; $i &lt; $needed_migration; $i++) {
    $mig = $migs[$i];
    $wpdb-&gt;query($mig);
  }

  if ($current_migration == 0) {
    add_option('myplugin_current_migration', $needed_migration);
  } else {
    update_option('myplugin_current_migration', $needed_migration);
  }
}
</pre>
<p>What this does is that it runs through database statements (queries) returned from the <code>myplugin_migrations()</code> method. Let&#8217;s implement the actual migrations – add this method:</p>
<pre class="brush: php; title: ; notranslate">
function myplugin_migrations() {
  global $wpdb;

  $migs = array();

  // Create example table
  $migs[] = '
  CREATE TABLE '.$wpdb-&gt;prefix.'myplugin_examples (
    id int(11) NOT NULL AUTO_INCREMENT,
    name varchar(255) NOT NULL,
    PRIMARY KEY (id)
  )';

  // Add examples
  $migs[] = &quot;INSERT INTO &quot;.$wpdb-&gt;prefix.&quot;myplugin_examples SET name='First example'&quot;;
  $migs[] = &quot;INSERT INTO &quot;.$wpdb-&gt;prefix.&quot;myplugin_examples SET name='Second example'&quot;;

  // Return the migrations
  return $migs;
}
</pre>
<p>That would create an example table and insert some values.</p>
<p>Now imagine that two months later you need a <strong>description</strong> field in your <strong>examples</strong> table. What do you do? It&#8217;s as easy as adding one line of code to the migrations:</p>
<pre class="brush: php; title: ; notranslate">
// Add description field to examples
$migs[] = &quot;ALTER TABLE &quot;.$wpdb-&gt;prefix.&quot;myplugin_examples ADD description VARCHAR( 255 ) NOT NULL&quot;;
</pre>
<p>Deactivate and activate the plugin, and you table now has an extra field. Easy as cake! :)</p>
<p>Share your thoughts, opinions, and suggestions below.</p>
<p>
<a href="http://twitter.com/lassebunk" onclick="abtest.trackGoal(21, this);">Follow me on Twitter</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2012/01/14/wordpress-plugin-database-migration-framework/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to split test themes using A/B Test for WordPress (video)</title>
		<link>http://lassebunk.dk/2012/01/14/split-test-ab-test-wordpress-themes/</link>
		<comments>http://lassebunk.dk/2012/01/14/split-test-ab-test-wordpress-themes/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 18:01:31 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[A/B Test for WordPress]]></category>
		<category><![CDATA[A/B testing]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[Multivariate testing]]></category>
		<category><![CDATA[Split testing]]></category>
		<category><![CDATA[Themes]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=2386</guid>
		<description><![CDATA[How to use the A/B Test for WordPress plugin to split test your WordPress themes.]]></description>
			<content:encoded><![CDATA[<p>In this presentation I&#8217;m demonstrating how to use the <a href="/plugins/abtest/">A/B Test for WordPress</a> plugin to split test <a href="http://wordpress.org">WordPress</a> themes on your site:</p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/GniZ0mkz3mU" frameborder="0" allowfullscreen></iframe></p>
<p>Visit the plugin page: <a href="/plugins/abtest/">A/B Test for WordPress</a></p>
<p>
<a href="http://twitter.com/lassebunk" onclick="abtest.trackGoal(21, this);">Follow me on Twitter</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2012/01/14/split-test-ab-test-wordpress-themes/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Split testing button colors using A/B Test for WordPress (video)</title>
		<link>http://lassebunk.dk/2012/01/14/split-test-button-colors-ab-test-wordpress/</link>
		<comments>http://lassebunk.dk/2012/01/14/split-test-button-colors-ab-test-wordpress/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 17:31:57 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[A/B Test for WordPress]]></category>
		<category><![CDATA[A/B testing]]></category>
		<category><![CDATA[Multivariate testing]]></category>
		<category><![CDATA[Split testing]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=2366</guid>
		<description><![CDATA[How to use A/B Test for WordPress to split test the colors of a button linking to a product page.]]></description>
			<content:encoded><![CDATA[<p>In this presentation I&#8217;m demonstrating how to use the <a href="/plugins/abtest/">A/B Test for WordPress</a> plugin to split test button colors on your <a href="http://wordpress.org">WordPress</a> site:</p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/Ia15LQJGG9A" frameborder="0" allowfullscreen></iframe></p>
<p>Visit the plugin page: <a href="/plugins/abtest/">A/B Test for WordPress</a></p>
<p>
<a href="http://twitter.com/lassebunk" onclick="abtest.trackGoal(21, this);">Follow me on Twitter</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2012/01/14/split-test-button-colors-ab-test-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using the A/B Test for WordPress plugin to split test between themes</title>
		<link>http://lassebunk.dk/2012/01/14/abtest-wordpress-plugin-split-test-themes/</link>
		<comments>http://lassebunk.dk/2012/01/14/abtest-wordpress-plugin-split-test-themes/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 14:30:21 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[A/B Test for WordPress]]></category>
		<category><![CDATA[A/B testing]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[Multivariate testing]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Split testing]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=2289</guid>
		<description><![CDATA[How to use the A/B Test for WordPress plugin to split test between your WordPress themes.]]></description>
			<content:encoded><![CDATA[<p>I recently created the <a href="/plugins/abtest/">A/B Test for WordPress</a> plugin which enables the <a href="http://wordpress.org">WordPress</a> blog or site owner to easily split test content, stylesheets, javascripts, and, what we&#8217;ll be discussing today, themes.</p>
<p>Let&#8217;s say you have a blog and you have been using the standard WordPress Twenty Eleven theme for a while but now you saw this great looking theme that&#8217;s just a must have. How do you find out if this new theme will make your site perform better or worse, and how will it affect outbound link clicks to your new book at Amazon? Let&#8217;s find out :-)</p>
<p>WordPress comes with the Twenty Eleven theme, so we&#8217;ll split test between this and another theme. Let&#8217;s install the free <a href="http://wordpress.org/extend/themes/adventure-journal">Adventure Journal</a> theme:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.53.48-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.53.48-PM-450x256.png" alt="" title="Screen Shot 2012-01-14 at 3.53.48 PM" width="450" height="256" class="alignnone size-medium wp-image-2308" /></a></p>
<p>For information on how to install themes, visit <a href="http://codex.wordpress.org/Using_Themes">Using Themes</a> on the WordPress site.</p>
<p>Then <a href="/plugins/abtest/">intall the plugin</a> and activate it in <strong>Plugins</strong>:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.36.21-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.36.21-PM-450x146.png" alt="" title="Screen Shot 2012-01-14 at 3.36.21 PM" width="450" height="146" class="alignnone size-medium wp-image-2299" /></a></p>
<p>Click the <strong>A/B Testing</strong> link right below <strong>Settings</strong>:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.41.42-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.41.42-PM.png" alt="" title="Screen Shot 2012-01-14 at 3.41.42 PM" width="280" height="132" class="alignnone size-full wp-image-2301" /></a></p>
<p>Click <strong>Create new experiment</strong>:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.42.47-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.42.47-PM.png" alt="" title="Screen Shot 2012-01-14 at 3.42.47 PM" width="275" height="194" class="alignnone size-full wp-image-2302" /></a></p>
<p>Enter <strong>&#8220;Split testing my theme&#8221;</strong> as <strong>Name</strong> and select <strong>Theme</strong> as <strong>Experiment type</strong>:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.46.10-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.46.10-PM.png" alt="" title="Screen Shot 2012-01-14 at 3.46.10 PM" width="381" height="234" class="alignnone size-full wp-image-2304" /></a></p>
<p>Click <strong>Create experiment</strong>.</p>
<p>Click <strong>Edit</strong> below <strong>Experiment 1</strong>:<br />
<a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.48.11-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.48.11-PM.png" alt="" title="Screen Shot 2012-01-14 at 3.48.11 PM" width="438" height="250" class="alignnone size-full wp-image-2305" /></a></p>
<p>Select the <strong>Adventure Journal</strong> theme:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.56.51-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.56.51-PM.png" alt="" title="Screen Shot 2012-01-14 at 3.56.51 PM" width="372" height="242" class="alignnone size-full wp-image-2311" /></a></p>
<p>Click <strong>Update variation</strong>.</p>
<p>Do the same for <strong>Variation 2</strong> where you select <strong>Twenty Eleven</strong> as the theme.</p>
<p>Click <strong>Back to experiments</strong> at the bottom of the page:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.58.53-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-3.58.53-PM.png" alt="" title="Screen Shot 2012-01-14 at 3.58.53 PM" width="250" height="64" class="alignnone size-full wp-image-2312" /></a></p>
<p>Now we&#8217;re going into <strong>Debug mode</strong> to test our variations. About the Debug mode:</p>
<p><em>&#8220;Normally, when a user first sees a variation to an experiment, this variation is locked for this user so that – in this session – she always sees the same variation.<br />
If you want to test your experiments without this variation lock taking place for you (and only you), you can enable debug mode. Also, when entering debug mode, all tracking will be disabled for your session.&#8221;</em></p>
<p>Click <strong>Enter debug mode</strong> in the top right corner of the screen:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.02.28-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.02.28-PM.png" alt="" title="Screen Shot 2012-01-14 at 4.02.28 PM" width="261" height="87" class="alignnone size-full wp-image-2316" /></a></p>
<p>Debug mode is now <strong>on</strong>:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.03.06-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.03.06-PM.png" alt="" title="Screen Shot 2012-01-14 at 4.03.06 PM" width="255" height="61" class="alignnone size-full wp-image-2317" /></a></p>
<p>Now go to the <strong>front page</strong> of your site, and you&#8217;ll see one of the themes being displayed:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.03.48-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.03.48-PM-450x212.png" alt="" title="Screen Shot 2012-01-14 at 4.03.48 PM" width="450" height="212" class="alignnone size-medium wp-image-2318" /></a></p>
<p>Now click <strong>Refresh</strong> a couple of times, and you&#8217;ll see that the theme changes:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.05.10-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.05.10-PM-450x218.png" alt="" title="Screen Shot 2012-01-14 at 4.05.10 PM" width="450" height="218" class="alignnone size-medium wp-image-2319" /></a></p>
<p>Neat, eh? :-)</p>
<p>Back into the <strong>admin</strong> interface, click <strong>Exit debug mode</strong>:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.06.45-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.06.45-PM.png" alt="" title="Screen Shot 2012-01-14 at 4.06.45 PM" width="262" height="102" class="alignnone size-full wp-image-2322" /></a></p>
<p>We&#8217;ll now set up a link and track when this link is clicked. We&#8217;ll use a link to a book on Amazon to simulate an author site with a &#8220;Buy my book&#8221; link.</p>
<p>Click <strong>Split testing my theme</strong> and scroll down to <strong>Goals</strong>:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.08.52-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.08.52-PM.png" alt="" title="Screen Shot 2012-01-14 at 4.08.52 PM" width="410" height="228" class="alignnone size-full wp-image-2323" /></a></p>
<p>Click <strong>Get tracking code</strong> right below <strong>Goal 1</strong> and you&#8217;ll see this screen:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.09.52-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.09.52-PM-450x197.png" alt="" title="Screen Shot 2012-01-14 at 4.09.52 PM" width="450" height="197" class="alignnone size-medium wp-image-2324" /></a></p>
<p>Select the <strong>javascript</strong> code below <strong>To track a link</strong> and copy it to the clipboard using <strong>CMD + C</strong> (on a Mac) or <strong>CTRL + C</strong> (on a PC):</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.11.54-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.11.54-PM-450x56.png" alt="" title="Screen Shot 2012-01-14 at 4.11.54 PM" width="450" height="56" class="alignnone size-medium wp-image-2327" /></a></p>
<p>We&#8217;ll now create a <strong>widget</strong> with our link to Amazon.</p>
<p>Click <strong>Appearance</strong> and then <strong>Widgets</strong> in the menu to the left:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.13.39-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.13.39-PM.png" alt="" title="Screen Shot 2012-01-14 at 4.13.39 PM" width="238" height="122" class="alignnone size-full wp-image-2329" /></a></p>
<p>Insert a widget by dragging a <strong>Text</strong> box from the <strong>Available Widgets</strong> box:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.16.21-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.16.21-PM.png" alt="" title="Screen Shot 2012-01-14 at 4.16.21 PM" width="272" height="80" class="alignnone size-full wp-image-2331" /></a></p>
<p>Onto the <strong>Main Sidebar</strong> on the right:<br />
<a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.17.50-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.17.50-PM-450x409.png" alt="" title="Screen Shot 2012-01-14 at 4.17.50 PM" width="450" height="409" class="alignnone size-medium wp-image-2332" /></a></p>
<p>Enter <strong>&#8220;Buy my book&#8221;</strong> as <strong>Title</strong> and insert this code below:<br />
<code><br />
&lt;a href=&quot;http://www.amazon.com/WordPress-Power-Guide-Blogging-ebook/dp/B004UW29IK/ref=sr_1_1?ie=UTF8&amp;qid=1326554345&amp;sr=8-1&quot; onclick=&quot;abtest.trackGoal(1, this);&quot;&gt;Buy my book on Amazon&lt;/a&gt;<br />
</code></p>
<p>Like this:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.21.28-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.21.28-PM-450x171.png" alt="" title="Screen Shot 2012-01-14 at 4.21.28 PM" width="450" height="171" class="alignnone size-medium wp-image-2335" /></a></p>
<p>Notice how we&#8217;re using the <code>onclick=&quot;abtest.trackGoal(1, this);&quot;</code> code? That&#8217;s what&#8217;s tracking our link when we click it.</p>
<p>Click <strong>Save</strong>.</p>
<p>Now go back onto the <strong>front page</strong> and you&#8217;ll see that the widget has been inserted into your site:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.23.03-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.23.03-PM.png" alt="" title="Screen Shot 2012-01-14 at 4.23.03 PM" width="343" height="104" class="alignnone size-full wp-image-2336" /></a></p>
<p>So far so good.</p>
<p>Try clicking the <strong>link</strong>.<br />
You have now tracked a goal completion!</p>
<p>Back into the <strong>admin</strong> interface, click on the <strong>experiment</strong> and you&#8217;ll see that it has tracked a goal completion:</p>
<p><a href="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.27.45-PM.png"><img src="http://lassebunk.dk/media/2012/01/Screen-Shot-2012-01-14-at-4.27.45-PM-450x77.png" alt="" title="Screen Shot 2012-01-14 at 4.27.45 PM" width="450" height="77" class="alignnone size-medium wp-image-2337" /></a></p>
<p>Nice! Now you just need to wait and see which theme performs better.</p>
<p>For more info, installation instructions, and tutorials, visit the <a href="/plugins/abtest/">A/B Test for WordPress</a> plugin page.</p>
<p>Also, please feel free to <a href="/contact/">contact me</a> if you have any questions.</p>
<p>
<a href="http://twitter.com/lassebunk" onclick="abtest.trackGoal(21, this);">Follow me on Twitter</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2012/01/14/abtest-wordpress-plugin-split-test-themes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introduction to the A/B Test for WordPress plugin (video)</title>
		<link>http://lassebunk.dk/2012/01/14/ab-test-for-wordpress/</link>
		<comments>http://lassebunk.dk/2012/01/14/ab-test-for-wordpress/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 00:28:48 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[A/B Test for WordPress]]></category>
		<category><![CDATA[A/B testing]]></category>
		<category><![CDATA[Multivariate testing]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Split testing]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=2235</guid>
		<description><![CDATA[A/B testing plugin for WordPress that makes it easy to A/B test any WordPress blog or site.]]></description>
			<content:encoded><![CDATA[<p><a href="/plugins/abtest/">A/B Test for WordPress</a> is a <a href="http://wordpress.org">WordPress</a> <a href="http://wordpress.org/extend/plugins/">plugin</a> that makes it easy to A/B split test your WordPress blog or site.</p>
<p><a href="/plugins/abtest/">Visit the plugin page</a> for more information, download, tutorials, and videos.</p>
<p>Here is a video introduction:</p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/4VRxXj2e3_I" frameborder="0" allowfullscreen></iframe></p>
<p>&rarr; <a href="http://downloads.wordpress.org/plugin/abtest.zip">Download the plugin</a> (or <a href="/plugins/abtest/">see more information</a>)</p>
<p>Please feel free to <a href="/contact/">contact me</a> if you have any questions.</p>
<p>
<a href="http://twitter.com/lassebunk" onclick="abtest.trackGoal(21, this);">Follow me on Twitter</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2012/01/14/ab-test-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
