<?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>MyFunnyDev &#187; rails</title>
	<atom:link href="http://michalkuklis.com/blog/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://michalkuklis.com/blog</link>
	<description>web, coding and beyond</description>
	<lastBuildDate>Fri, 25 Jun 2010 05:51:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>auto escaping html in Rails to protect from XSS</title>
		<link>http://michalkuklis.com/blog/2009/07/29/auto-escaping-html-in-rails-to-protect-from-xss/</link>
		<comments>http://michalkuklis.com/blog/2009/07/29/auto-escaping-html-in-rails-to-protect-from-xss/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 01:24:02 +0000</pubDate>
		<dc:creator>Michał Kuklis</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://michalkuklis.com/blog/?p=233</guid>
		<description><![CDATA[Tonight I found a plugin to auto escape html in order to protect from XSS attacks. I&#8217;m not sure why rails doesn&#8217;t do it out of the box (you have to use h() helper). Anyway the plugin is called xss_terminate and it can be found here. The cool thing about it is that now you [...]]]></description>
			<content:encoded><![CDATA[<p>Tonight I found a plugin to auto escape html in order to protect from XSS attacks. I&#8217;m not sure why rails doesn&#8217;t do it out of the box (you have to use h() helper). Anyway the plugin is called xss_terminate and it can be found <a href="http://github.com/look/xss_terminate/tree/master">here</a>. The cool thing about it is that now you can forget about h() <img src='http://michalkuklis.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://michalkuklis.com/blog/2009/07/29/auto-escaping-html-in-rails-to-protect-from-xss/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>daemon_controller + Thinking Sphinx</title>
		<link>http://michalkuklis.com/blog/2009/07/22/daemon_controller-thinking-sphinx/</link>
		<comments>http://michalkuklis.com/blog/2009/07/22/daemon_controller-thinking-sphinx/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 06:13:02 +0000</pubDate>
		<dc:creator>Michał Kuklis</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://michalkuklis.com/blog/?p=220</guid>
		<description><![CDATA[I&#8217;ve created simple rails initiator in order to start Sphinx through daemon_controller based on the Thinking Sphinx configuration. I hope it will help somebody.

require 'daemon_controller'
&#160;
def before_start
  if not ThinkingSphinx.define_indexes?
    config = ThinkingSphinx::Configuration.instance
    cmd = &#34;#{config.bin_path}#{config.indexer_binary_name} --config \&#34;#{config.config_file}\&#34; --all&#34;
    cmd &#60;&#60; &#34; --rotate&#34; if ThinkingSphinx.sphinx_running?
  [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve created simple rails initiator in order to start <a href="http://sphinxsearch.com/">Sphinx</a> through <a href="http://blog.phusion.nl/2008/08/25/daemon_controller-a-library-for-robust-daemon-management/">daemon_controller</a> based on the <a href="http://freelancing-god.github.com/ts/en/">Thinking Sphinx</a> configuration. I hope it will help somebody.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'daemon_controller'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> before_start
  <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">not</span> ThinkingSphinx.<span style="color:#9900CC;">define_indexes</span>?
    config = <span style="color:#6666ff; font-weight:bold;">ThinkingSphinx::Configuration</span>.<span style="color:#9900CC;">instance</span>
    cmd = <span style="color:#996600;">&quot;#{config.bin_path}#{config.indexer_binary_name} --config <span style="color:#000099;">\&quot;</span>#{config.config_file}<span style="color:#000099;">\&quot;</span> --all&quot;</span>
    cmd <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot; --rotate&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> ThinkingSphinx.<span style="color:#9900CC;">sphinx_running</span>?
    <span style="color:#CC0066; font-weight:bold;">system</span> cmd
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">defined</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>ThinkingSphinx<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">not</span> ThinkingSphinx.<span style="color:#9900CC;">sphinx_running</span>? 
    conf_instance = <span style="color:#6666ff; font-weight:bold;">ThinkingSphinx::Configuration</span>.<span style="color:#9900CC;">instance</span>
    <span style="color:#0066ff; font-weight:bold;">@controller</span> = DaemonController.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>
      <span style="color:#ff3333; font-weight:bold;">:identifier</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Sphinx search server'</span>,
      <span style="color:#ff3333; font-weight:bold;">:start_command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;#{conf_instance.bin_path}#{conf_instance.searchd_binary_name} --pidfile --config <span style="color:#000099;">\&quot;</span>#{conf_instance.config_file}<span style="color:#000099;">\&quot;</span>&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:before_start</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> method<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:before_start</span><span style="color:#006600; font-weight:bold;">&#41;</span>,
      <span style="color:#ff3333; font-weight:bold;">:ping_command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span> TCPSocket.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>conf_instance.<span style="color:#9900CC;">configuration</span>.<span style="color:#9900CC;">searchd</span>.<span style="color:#9900CC;">address</span>, conf_instance.<span style="color:#9900CC;">configuration</span>.<span style="color:#9900CC;">searchd</span>.<span style="color:#9900CC;">port</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#ff3333; font-weight:bold;">:pid_file</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> conf_instance.<span style="color:#9900CC;">configuration</span>.<span style="color:#9900CC;">searchd</span>.<span style="color:#9900CC;">pid_file</span>,
      <span style="color:#ff3333; font-weight:bold;">:log_file</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> conf_instance.<span style="color:#9900CC;">configuration</span>.<span style="color:#9900CC;">searchd</span>.<span style="color:#9900CC;">log</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@controller</span>.<span style="color:#9900CC;">start</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://michalkuklis.com/blog/2009/07/22/daemon_controller-thinking-sphinx/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The Rails Initialization Process</title>
		<link>http://michalkuklis.com/blog/2009/07/22/the-rails-initialization-process/</link>
		<comments>http://michalkuklis.com/blog/2009/07/22/the-rails-initialization-process/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 05:08:32 +0000</pubDate>
		<dc:creator>Michał Kuklis</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://michalkuklis.com/blog/?p=213</guid>
		<description><![CDATA[I found really nice description of rails initialization process here.
]]></description>
			<content:encoded><![CDATA[<p>I found really nice description of rails initialization process <a href="http://www.railsguts.com/initialization.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://michalkuklis.com/blog/2009/07/22/the-rails-initialization-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ruby maxins in rails plugins</title>
		<link>http://michalkuklis.com/blog/2009/07/20/ruby-maxins-in-rails-plugins/</link>
		<comments>http://michalkuklis.com/blog/2009/07/20/ruby-maxins-in-rails-plugins/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 01:16:46 +0000</pubDate>
		<dc:creator>Michał Kuklis</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://michalkuklis.com/blog/?p=175</guid>
		<description><![CDATA[Very often when looking at the code in rails plugins you can run into this:

module Taggable 
  def self.included&#40;base&#41;
    base.extend&#40;ClassMethods&#41;
  end
  module module ClassMethods
    #methods here
  end
end

This is a part of a bigger pattern which is shown below:

module ModuleA
  def self.included&#40;base&#41;
    [...]]]></description>
			<content:encoded><![CDATA[<p>Very often when looking at the code in rails plugins you can run into this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> Taggable 
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">included</span><span style="color:#006600; font-weight:bold;">&#40;</span>base<span style="color:#006600; font-weight:bold;">&#41;</span>
    base.<span style="color:#9900CC;">extend</span><span style="color:#006600; font-weight:bold;">&#40;</span>ClassMethods<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">module</span> <span style="color:#9966CC; font-weight:bold;">module</span> ClassMethods
    <span style="color:#008000; font-style:italic;">#methods here</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This is a part of a bigger pattern which is shown below:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ModuleA
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">included</span><span style="color:#006600; font-weight:bold;">&#40;</span>base<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#008000; font-style:italic;"># add class methods from ModuleB</span>
    base.<span style="color:#9900CC;">extend</span><span style="color:#006600; font-weight:bold;">&#40;</span>ModuleB<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">module</span> ModuleB
  <span style="color:#9966CC; font-weight:bold;">def</span> act_as_hello
    <span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#996600;">&quot;hello from module B&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> ClassC
 <span style="color:#008000; font-style:italic;">#class body here</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># include moduleA in classC</span>
ClassC.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:include</span>, ModuleA<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> ClassD <span style="color:#006600; font-weight:bold;">&lt;</span> ClassC
  act_as_hello
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
classD = ClassD.<span style="color:#9900CC;">new</span></pre></div></div>

<p>The pattern is used often when developing plugins with ActiveRecord. What we gain by inheriting from ClassC  (<b>class ClassD < ClassC</b>) are instance methods from ModuleA. This is done by:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">ClassC.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:include</span>, ModuleA<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Moreover since ModuleA is included in ClassC, ModuleA&#8217;s initializer <strong>def self.included(base)</strong> will be invoked at the time  ModuleA is mixed with ClassC. The invocation will call <b>base.extend(ModuleB)</b>. In this case <b>base</b> represents ClassC which will be extended by adding class methods from ModuleB. The ModuleA&#8217;s init method is shown again below:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">included</span><span style="color:#006600; font-weight:bold;">&#40;</span>base<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#008000; font-style:italic;"># add class methods from ModuleB to ClassC</span>
  base.<span style="color:#9900CC;">extend</span><span style="color:#006600; font-weight:bold;">&#40;</span>ModuleB<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>At the end our ClassD has now access to all class methods defined in ModuleB.  <strong>act_as_hello</strong> will be called during ClassD initialization:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> ClassD <span style="color:#006600; font-weight:bold;">&lt;</span> ClassC
  act_as_hello
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://michalkuklis.com/blog/2009/07/20/ruby-maxins-in-rails-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>capistrano recipes for ubuntu</title>
		<link>http://michalkuklis.com/blog/2009/07/19/capistrano-recipes-for-ubuntu/</link>
		<comments>http://michalkuklis.com/blog/2009/07/19/capistrano-recipes-for-ubuntu/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 03:25:22 +0000</pubDate>
		<dc:creator>Michał Kuklis</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://michalkuklis.com/blog/?p=172</guid>
		<description><![CDATA[Few nice capistrano recipes which may help you automate Ubuntu Server setup:

ubuntu-machine
slicehost

]]></description>
			<content:encoded><![CDATA[<p>Few nice capistrano recipes which may help you automate Ubuntu Server setup:</p>
<ul>
<li><a href="http://suitmymind.github.com/ubuntu-machine/">ubuntu-machine</a></li>
<li><a href="http://github.com/josh/slicehost/tree/master">slicehost</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://michalkuklis.com/blog/2009/07/19/capistrano-recipes-for-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
