<?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></description>
	<lastBuildDate>Sat, 31 Mar 2012 06:11:10 +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>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? system cmd end end &#160; if defined?&#40;ThinkingSphinx&#41; if [...]]]></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"><span class="kw3">require</span> <span class="st0">'daemon_controller'</span>
&nbsp;
<span class="kw1">def</span> before_start
  <span class="kw1">if</span> <span class="kw1">not</span> ThinkingSphinx.<span class="me1">define_indexes</span>?
    config = <span class="re2">ThinkingSphinx::Configuration</span>.<span class="me1">instance</span>
    cmd = <span class="st0">&quot;#{config.bin_path}#{config.indexer_binary_name} --config <span class="es0">\&quot;</span>#{config.config_file}<span class="es0">\&quot;</span> --all&quot;</span>
    cmd <span class="sy0">&lt;&lt;</span> <span class="st0">&quot; --rotate&quot;</span> <span class="kw1">if</span> ThinkingSphinx.<span class="me1">sphinx_running</span>?
    <span class="kw3">system</span> cmd
  <span class="kw1">end</span>
<span class="kw1">end</span>
&nbsp;
<span class="kw1">if</span> <span class="kw1">defined</span>?<span class="br0">&#40;</span>ThinkingSphinx<span class="br0">&#41;</span>
  <span class="kw1">if</span> <span class="kw1">not</span> ThinkingSphinx.<span class="me1">sphinx_running</span>? 
    conf_instance = <span class="re2">ThinkingSphinx::Configuration</span>.<span class="me1">instance</span>
    <span class="re1">@controller</span> = DaemonController.<span class="me1">new</span><span class="br0">&#40;</span>
      <span class="re3">:identifier</span> <span class="sy0">=&gt;</span> <span class="st0">'Sphinx search server'</span>,
      <span class="re3">:start_command</span> <span class="sy0">=&gt;</span> <span class="st0">&quot;#{conf_instance.bin_path}#{conf_instance.searchd_binary_name} --pidfile --config <span class="es0">\&quot;</span>#{conf_instance.config_file}<span class="es0">\&quot;</span>&quot;</span>,
      <span class="re3">:before_start</span> <span class="sy0">=&gt;</span> method<span class="br0">&#40;</span><span class="re3">:before_start</span><span class="br0">&#41;</span>,
      <span class="re3">:ping_command</span> <span class="sy0">=&gt;</span> <span class="kw3">lambda</span> <span class="br0">&#123;</span> TCPSocket.<span class="me1">new</span><span class="br0">&#40;</span>conf_instance.<span class="me1">configuration</span>.<span class="me1">searchd</span>.<span class="me1">address</span>, conf_instance.<span class="me1">configuration</span>.<span class="me1">searchd</span>.<span class="me1">port</span><span class="br0">&#41;</span> <span class="br0">&#125;</span>,
      <span class="re3">:pid_file</span> <span class="sy0">=&gt;</span> conf_instance.<span class="me1">configuration</span>.<span class="me1">searchd</span>.<span class="me1">pid_file</span>,
      <span class="re3">:log_file</span> <span class="sy0">=&gt;</span> conf_instance.<span class="me1">configuration</span>.<span class="me1">searchd</span>.<span class="me1">log</span><span class="br0">&#41;</span>
      <span class="re1">@controller</span>.<span class="me1">start</span>
  <span class="kw1">end</span>
<span class="kw1">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>4</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; # add class methods from ModuleB base.extend&#40;ModuleB&#41; end end &#160; module [...]]]></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"><span class="kw1">module</span> Taggable 
  <span class="kw1">def</span> <span class="kw2">self</span>.<span class="me1">included</span><span class="br0">&#40;</span>base<span class="br0">&#41;</span>
    base.<span class="me1">extend</span><span class="br0">&#40;</span>ClassMethods<span class="br0">&#41;</span>
  <span class="kw1">end</span>
  <span class="kw1">module</span> <span class="kw1">module</span> ClassMethods
    <span class="co1">#methods here</span>
  <span class="kw1">end</span>
<span class="kw1">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"><span class="kw1">module</span> ModuleA
  <span class="kw1">def</span> <span class="kw2">self</span>.<span class="me1">included</span><span class="br0">&#40;</span>base<span class="br0">&#41;</span>
    <span class="co1"># add class methods from ModuleB</span>
    base.<span class="me1">extend</span><span class="br0">&#40;</span>ModuleB<span class="br0">&#41;</span>
  <span class="kw1">end</span>
<span class="kw1">end</span>
&nbsp;
<span class="kw1">module</span> ModuleB
  <span class="kw1">def</span> act_as_hello
    <span class="kw3">p</span> <span class="st0">&quot;hello from module B&quot;</span>
  <span class="kw1">end</span>
<span class="kw1">end</span>
&nbsp;
<span class="kw1">class</span> ClassC
 <span class="co1">#class body here</span>
<span class="kw1">end</span>
&nbsp;
<span class="co1"># include moduleA in classC</span>
ClassC.<span class="me1">send</span><span class="br0">&#40;</span>:<span class="kw1">include</span>, ModuleA<span class="br0">&#41;</span>
&nbsp;
<span class="kw1">class</span> ClassD <span class="sy0">&lt;</span> ClassC
  act_as_hello
<span class="kw1">end</span>
&nbsp;
classD = ClassD.<span class="me1">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">ClassC.<span class="me1">send</span><span class="br0">&#40;</span>:<span class="kw1">include</span>, ModuleA<span class="br0">&#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"><span class="kw1">def</span> <span class="kw2">self</span>.<span class="me1">included</span><span class="br0">&#40;</span>base<span class="br0">&#41;</span>
  <span class="co1"># add class methods from ModuleB to ClassC</span>
  base.<span class="me1">extend</span><span class="br0">&#40;</span>ModuleB<span class="br0">&#41;</span>
<span class="kw1">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"><span class="kw1">class</span> ClassD <span class="sy0">&lt;</span> ClassC
  act_as_hello
<span class="kw1">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>

