<?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>Kolodvor</title>
	<atom:link href="http://www.kolodvor.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kolodvor.net</link>
	<description>ruby, rails, javascript, jquery, ...</description>
	<lastBuildDate>Mon, 16 Jan 2012 15:24:32 +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>Divisible</title>
		<link>http://www.kolodvor.net/2011/03/26/divisible/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=divisible</link>
		<comments>http://www.kolodvor.net/2011/03/26/divisible/#comments</comments>
		<pubDate>Sat, 26 Mar 2011 07:59:01 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.kolodvor.net/?p=283</guid>
		<description><![CDATA[I just published my first ruby gem on rubygems.org. It is a simple gem that is useful in case you need to find out if one number is divisible by another. Usage 9.divisible_by(3) # => true 10.divisible_by(3) # => false &#8230; <a href="http://www.kolodvor.net/2011/03/26/divisible/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just published <a href="https://rubygems.org/gems/divisible">my first ruby gem</a> on <a href="https://rubygems.org/">rubygems.org</a>. It is a simple gem that is useful in case you need to find out if one number is divisible by another.</p>
<h3>Usage</h3>
<pre class="code">
  9.divisible_by(3) # => true
  10.divisible_by(3) # => false
  12.divisible_by(3) # => true
  12.divisible_by(4) # => true
  15.divisible_by(4) # => false
</pre>
<p>Same can be done with</p>
<pre class="code">
  Divisible.check(9, 3) # => true
  Divisible.check(10, 3) # => false
  Divisible.check(12, 3) # => true
  Divisible.check(12, 4) # => true
  Divisible.check(15, 4) # => false
</pre>
<h3>Installation</h3>
<pre class="code">
  gem install divisible
</pre>
<p>For more info go to <a href="https://github.com/vlado/divisible">https://github.com/vlado/divisible</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2011/03/26/divisible/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Number of workdays between two dates</title>
		<link>http://www.kolodvor.net/2010/08/01/number-of-workdays-between-two-dates/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=number-of-workdays-between-two-dates</link>
		<comments>http://www.kolodvor.net/2010/08/01/number-of-workdays-between-two-dates/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 21:55:34 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.kolodvor.net/?p=274</guid>
		<description><![CDATA[It is pretty simple to get number of work days between two dates. For example we can get the number of workdays in this month. start_date = Date.civil(2010, 8, 1) end_date = Date.civil(2010, 8, 31) workdays = (start_date..end_date).select { &#124;day&#124; &#8230; <a href="http://www.kolodvor.net/2010/08/01/number-of-workdays-between-two-dates/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It is pretty simple to get number of work days between two dates. For example we can get the number of workdays in this month.</p>
<pre class="code">
  start_date = Date.civil(2010, 8, 1)
  end_date = Date.civil(2010, 8, 31)
  workdays = (start_date..end_date).select { |day| ![0, 6].include?(day.wday) }.size
</pre>
<p><span id="more-274"></span></p>
<p>Please note that this doesn&#8217;t include any check for holidays, you&#8217;ll need to figure that yourself (if you have need for that at all). </p>
<p>For more info see <a href="http://ruby-doc.org/ruby-1.9/classes/Array.html#M000724">Array#select</a> and <a href="http://ruby-doc.org/ruby-1.9/classes/Date.html#M001468">Date#wday</a> methods.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2010/08/01/number-of-workdays-between-two-dates/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MarkItUp: Rails plugin that turns any textarea into a markup editor</title>
		<link>http://www.kolodvor.net/2010/07/05/markitup-rails-plugin-that-turns-any-textarea-into-a-markup-editor/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=markitup-rails-plugin-that-turns-any-textarea-into-a-markup-editor</link>
		<comments>http://www.kolodvor.net/2010/07/05/markitup-rails-plugin-that-turns-any-textarea-into-a-markup-editor/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 16:14:09 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[markitup]]></category>
		<category><![CDATA[markup]]></category>
		<category><![CDATA[mark_it_up]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[textarea]]></category>

		<guid isPermaLink="false">http://www.kolodvor.net/?p=254</guid>
		<description><![CDATA[I recently published a plugin that helps you turn any textarea into a markup editor. It is based on excellent markItUp! jQuery plugin. Example The most simple usage with preset defaults &#60;html&#62; &#60;head&#62; &#60;%= javascript_include_tag "path/to/jquery" %&#62; &#60;%= mark_it_up '#miu_test' &#8230; <a href="http://www.kolodvor.net/2010/07/05/markitup-rails-plugin-that-turns-any-textarea-into-a-markup-editor/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently published a plugin that helps you turn any textarea into a markup editor. It is based on excellent <a href="http://markitup.jaysalvat.com">markItUp! jQuery plugin</a>.</p>
<h3>Example</h3>
<p>The most simple usage with preset defaults</p>
<pre class="code">
&lt;html&gt;
&lt;head&gt;
  &lt;%= javascript_include_tag "path/to/jquery" %&gt;
  &lt;%= mark_it_up '#miu_test' %&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;%= form_tag do %&gt;
    &lt;%= text_area_tag "miu_test" %&gt;
  &lt;% end %&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>You can see a lot more cool examples in action on <a href="http://markitup.cingel.hr/">markitup.cingel.hr</a>.</p>
<p>More info</p>
<p><a href="http://markitup.cingel.hr/">markitup.cingel.hr</a><br />
<a href="http://github.com/cingel/mark_it_up">github.com/cingel/mark_it_up</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2010/07/05/markitup-rails-plugin-that-turns-any-textarea-into-a-markup-editor/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Simple Search Rails plugin</title>
		<link>http://www.kolodvor.net/2010/06/26/simple-search-rails-plugin/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=simple-search-rails-plugin</link>
		<comments>http://www.kolodvor.net/2010/06/26/simple-search-rails-plugin/#comments</comments>
		<pubDate>Sat, 26 Jun 2010 08:31:11 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[simple]]></category>

		<guid isPermaLink="false">http://kolodvor.net/?p=234</guid>
		<description><![CDATA[SimpleSearch brings simple search to ActiveRecord. It ads simple_search named scope that accepts query as parameter. The idea is that you provide the query and plugin does the rest (splits query to keywords and compose where statement). This can be &#8230; <a href="http://www.kolodvor.net/2010/06/26/simple-search-rails-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>SimpleSearch brings simple search to ActiveRecord. It ads <span class="code">simple_search</span> named scope that accepts query as parameter.</p>
<p>The idea is that you provide the query and plugin does the rest (splits query to keywords and compose where statement).</p>
<p>This can be very useful in case you just want to filter list of records by some query, you have autocomplete field, &#8230; or something similar.</p>
<p><span id="more-234"></span></p>
<h3>Example</h3>
<p><strong>View</strong></p>
<pre class="code">
  &lt;% form_tag request.path, :method => 'get' do %>
    &lt;%= text_field_tag :query, params[:query] %>
  &lt;% end %>
</pre>
<p><strong>Model</strong></p>
<pre class="code">
  class User < ActiveRecord::Base
    acts_as_simply_searchable
  end

  # Columns: id, login, email, crypted_password, salt
</pre>
<p><strong>Controller</strong></p>
<pre class="code">
  class UsersController < ApplicationController
    def index
      @users = User.simple_search(params[:query]).all
    end
  end
</pre>
<p><strong>Query examples</strong></p>
<p>Simple query</p>
<pre class="code">
  User.simple_search("vlado")
  # => SELECT * FROM "users" WHERE (users.id LIKE '%vlado%' OR users.login LIKE '%vlado%' OR users.email LIKE '%vlado%' OR users.crypted_password LIKE '%vlado%' OR users.salt LIKE '%vlado%')
</pre>
<p>You can also provide <span class="code">:columns => :column1, :column2, ...</span> option to limit search only to those columns</p>
<pre class="code">
  class User < ActiveRecord::Base
    acts_as_simply_searchable :columns => :login, :email
  end
</pre>
<p></p>
<pre class="code">
  User.simple_search("vlado")
  # => SELECT * FROM "users" WHERE (users.login LIKE '%vlado%' OR users.email LIKE '%vlado%')
</pre>
<p>More complex query</p>
<pre class="code">
  User.simple_search("vlado, cingel")
  # will search for users matching 'vlado' and 'cingel' keywords
  # => SELECT * FROM "users" WHERE ((users.login LIKE '%vlado%' OR users.email LIKE '%vlado%') AND (users.login LIKE '%cingel%' OR users.email LIKE '%cingel%'))
</pre>
<p><strong>NOTE: With proper use of indexes this plugin can work quite well in most cases, but in case you have a large and complex database it is usually much better idea to use some search daemon like <a href="http://freelancing-god.github.com/ts/en/">Thinking Sphinx</a>.</strong></p>
<h3>More info</h3>
<p><a href="http://github.com/cingel/simple_search">http://github.com/cingel/simple_search</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2010/06/26/simple-search-rails-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flood</title>
		<link>http://www.kolodvor.net/2010/06/22/flood/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=flood</link>
		<comments>http://www.kolodvor.net/2010/06/22/flood/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 20:47:23 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://kolodvor.net/?p=183</guid>
		<description><![CDATA[My neighbourhood was hit by flood today. We managed to prevent the water from entering the house, but it was a great reminder how powerful mother nature really is If you wanna see more, click here.]]></description>
			<content:encoded><![CDATA[<p>My neighbourhood was hit by flood today. We managed to prevent the water from entering the house, but it was a great reminder how powerful mother nature really is <img src='http://www.kolodvor.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span id="more-183"></span></p>
<p><a href="http://www.kolodvor.net/2010/06/22/flood/img_0229/" rel="attachment wp-att-219"><img src="http://kolodvor.net/wp-content/uploads/2010/06/IMG_0229-580x435.jpg" alt="" title="IMG_0229" width="580" height="435" class="alignnone size-medium wp-image-219" /></a></p>
<p>If you wanna see more, <a href="http://www.facebook.com/album.php?aid=183867&#038;id=730353231&#038;l=b1fd1c32b6">click here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2010/06/22/flood/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create new app with specific Rails version</title>
		<link>http://www.kolodvor.net/2010/02/25/create-new-app-with-specific-rails-version/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=create-new-app-with-specific-rails-version</link>
		<comments>http://www.kolodvor.net/2010/02/25/create-new-app-with-specific-rails-version/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 11:09:50 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails3]]></category>
		<category><![CDATA[version]]></category>

		<guid isPermaLink="false">http://kolodvor.net/?p=153</guid>
		<description><![CDATA[I recently installed Rails 3 beta release but I needed to create new app with the 2.3.5. version. I was searching for a way to do that and I found this rails _2.3.5_ appname Unfortunately this will produce an error &#8230; <a href="http://www.kolodvor.net/2010/02/25/create-new-app-with-specific-rails-version/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently installed Rails 3 beta release but I needed to create new app with the 2.3.5. version. I was searching for a way to do that and I found this</p>
<pre class="code">
  rails _2.3.5_ appname
</pre>
<p>Unfortunately this will produce an error similar to this</p>
<pre class="code">
  /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:827:in `report_activate_error': RubyGem version error: railties(3.0.0.beta not = 2.3.5) (Gem::LoadError)
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:261:in `activate'
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:68:in `gem'
	from /usr/local/bin/rails3:18
</pre>
<p>To fix this first run</p>
<p><span id="more-153"></span></p>
<pre class="code">
  which rails
</pre>
<p>and you will get a path to your rails executable, in my case this is <code>/usr/local/bin/rails</code>.</p>
<p>Then copy <code>rails</code> to <code>rails3</code>.</p>
<pre class="code">
  sudo cp /usr/local/bin/rails /usr/local/bin/rails3
</pre>
<p>Then open this file in your text editor (TextMate in my case).</p>
<pre class="code">
  mate /usr/local/bin/rails
</pre>
<p>and replace two last lines so that your file now looks like </p>
<pre class="code">
  require 'rubygems'

  version = ">= 0"

  if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
    version = $1
    ARGV.shift
  end

  gem 'rails', version
  load 'rails'
</pre>
<p>Thats it, now you can create your app with specific Rails version with</p>
<pre class="code">
  rails _2.3.5_ appname
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2010/02/25/create-new-app-with-specific-rails-version/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>View man documentation in Preview</title>
		<link>http://www.kolodvor.net/2010/02/12/view-man-documentation-in-preview/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=view-man-documentation-in-preview</link>
		<comments>http://www.kolodvor.net/2010/02/12/view-man-documentation-in-preview/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 08:12:12 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[OS X]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[preview]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://kolodvor.net/?p=134</guid>
		<description><![CDATA[If you are on OSX you can easily open man documentation using Preview. Just replace ls with command you would like to see documentation for. man -t "ls" &#124; open -f -a /Applications/Preview.app/ If you plan to do this often, &#8230; <a href="http://www.kolodvor.net/2010/02/12/view-man-documentation-in-preview/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you are on OSX you can easily open man documentation using Preview. Just replace <code>ls</code> with command you would like to see documentation for.</p>
<pre class="code">
 man -t "ls" | open -f -a /Applications/Preview.app/
</pre>
<p><span id="more-134"></span></p>
<p>If you plan to do this often, you can make your life much easier by putting this inside your <code>.bash_profile</code>.</p>
<pre class="code">
 pman ()
 {
   man -t "${1}" | open -f -a /Applications/Preview.app/
 }
</pre>
<p>Now you can use following to view documentation in Preview</p>
<pre class="code">
 pman ls
</pre>
<p>Credit goes to <a href="http://wiseheartdesign.com/articles/2010/02/12/my-current-toolset/">John W. Long</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2010/02/12/view-man-documentation-in-preview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby library for parsing, validating and formatting phone numbers</title>
		<link>http://www.kolodvor.net/2010/01/04/ruby-library-for-parsing-validating-and-formatting-phone-numbers/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ruby-library-for-parsing-validating-and-formatting-phone-numbers</link>
		<comments>http://www.kolodvor.net/2010/01/04/ruby-library-for-parsing-validating-and-formatting-phone-numbers/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 16:19:39 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[phone numbers]]></category>

		<guid isPermaLink="false">http://kolodvor.net/?p=107</guid>
		<description><![CDATA[Tomislav Car has just released Phone, Ruby library for phone number parsing, validation and formatting. It should save you a lot of time if you need any of the following: * you have area where users input phone numbers in &#8230; <a href="http://www.kolodvor.net/2010/01/04/ruby-library-for-parsing-validating-and-formatting-phone-numbers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/carr">Tomislav Car</a> has just released <a href="http://github.com/carr/phone">Phone</a>, Ruby library for phone number parsing, validation and formatting. It should save you a lot of time if you need any of the following:</p>
<p>* you have area where users input phone numbers in many different formats<br />
* output phone numbers in specific format<br />
* you need to send SMS messages from your app<br />
* &#8230;</p>
<p><span id="more-107"></span></p>
<p>You can initialize new Phone object with <code>Phone.new</code></p>
<pre class="code">
  Phone.new('5125486', '91', '385')
</pre>
<p>or</p>
<pre class="code">
  Phone.new(:number => '5125486', :area_code => '91', :country_code => '385')
</pre>
<p>Parsing is done using <code>Phone.parse</code> method</p>
<pre class="code">
    Phone.parse '091/512-5486', :country_code => '385'
    Phone.parse '(091) 512 5486', :country_code => '385'
</pre>
<p>It is smart to set default contry code first so you don&#8217;t have to provide it as option every time</p>
<pre class="code">
    Phone.default_country_code = '385'
    Phone.parse '091/512-5486'
    Phone.parse '(091) 512 5486'
</pre>
<p><span style="text-decoration:line-through">Fow now, Phone works only for Croatian, Slovenian, Bosnian and Serbian phone numbers, but Tomislav is collecting data to support other countries.</span></p>
<p><a href="http://github.com/carr/phone">Go check it out</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2010/01/04/ruby-library-for-parsing-validating-and-formatting-phone-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set focus on first field with Prototype</title>
		<link>http://www.kolodvor.net/2010/01/02/set-focus-on-first-field-with-prototype/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=set-focus-on-first-field-with-prototype</link>
		<comments>http://www.kolodvor.net/2010/01/02/set-focus-on-first-field-with-prototype/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 14:32:02 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Prototype]]></category>
		<category><![CDATA[focus]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[selectors]]></category>

		<guid isPermaLink="false">http://kolodvor.net/?p=91</guid>
		<description><![CDATA[If you are using jQuery see this post. To set focus on first text field with Prototype I prefer something like this var firstField = $$('input:text:visible').first(); if (firstField) firstField.focus(); but you can also try with Form.focusFirstElement or Form.findFirstElement]]></description>
			<content:encoded><![CDATA[<p>If you are using <a href="http://www.jquery.com">jQuery</a> see <a href="http://kolodvor.net/2008/01/17/set-focus-on-first-field-with-jquery">this</a> post.</p>
<p>To set focus on first text field with Prototype I prefer something like this</p>
<pre class="code">
  var firstField = $$('input:text:visible').first();
  if (firstField)
    firstField.focus();
</pre>
<p>but you can also try with <a href="http://api.prototypejs.org/dom/form.html#focusfirstelement-class_method">Form.focusFirstElement</a> or <a href="http://api.prototypejs.org/dom/form.html#findfirstelement-class_method">Form.findFirstElement</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2010/01/02/set-focus-on-first-field-with-prototype/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rails, CSRF and Ajax requests</title>
		<link>http://www.kolodvor.net/2010/01/02/rails-csrf-and-ajax-requests/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rails-csrf-and-ajax-requests</link>
		<comments>http://www.kolodvor.net/2010/01/02/rails-csrf-and-ajax-requests/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 00:36:03 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[csrf]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[forgery]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[protection]]></category>
		<category><![CDATA[token]]></category>

		<guid isPermaLink="false">http://kolodvor.net/?p=64</guid>
		<description><![CDATA[Rails protects controller actions from CSRF (Cross-Site Request Forgery) attacks with a token based on a random string stored in the session. The token parameter is named authenticity_token by default and will be embedded in all forms and Ajax requests &#8230; <a href="http://www.kolodvor.net/2010/01/02/rails-csrf-and-ajax-requests/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Rails protects controller actions from <a href="http://en.wikipedia.org/wiki/Cross-site_request_forgery">CSRF</a> (Cross-Site Request Forgery) attacks with a token based on a random string stored in the session. The token parameter is named <code>authenticity_token</code> by default and will be embedded  in all forms and Ajax requests generated by Rails.</p>
<p>You should also add this token to all Ajax request that you hand coded. As suggested in <a href="http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html#M000514">Rails documentation</a> you can add this line in <code>head</code> section.</p>
<pre class="code">
  &lt;%= javascript_tag "window._token = '#{form_authenticity_token}'" %&gt;;
</pre>
<p>and then add authenticity_token to parameters option of Ajax requests</p>
<pre class="code">
  new Ajax.Request('/some/url', {
    parameters: "foo=bar&#038;authenticity_token="+_token
  });
</pre>
<h3>Remote forgery protection plugin</h3>
<p>This can get tedious if you have a lot of Ajax requests so I wrote a simple <a href="http://github.com/vlado/remote_forgery_protection">plugin</a> that adds authenticity token to all Ajax requests automatically.</p>
<p>You can install it with</p>
<pre class="code">
  script/plugin install git://github.com/vlado/remote_forgery_protection.git
</pre>
<p>Now all you have to do is add this line inside <code>head</code> section of you&#8217;re layout</p>
<pre class="code">
  &lt;%= remote_forgery_protection %&gt;
</pre>
<p>and all non GET Ajax request will have authenticity_token parameter automatically included.</p>
<p><span id="more-64"></span></p>
<p><span style="text-decoration:line-through">Magic is done by wrapping Ajax.Base using <a href="http://api.prototypejs.org/language/function.html#wrap-instance_method">Function#wrap</a> method so this will work only if you are using <a href="http://prototypejs.org">Prototype</a>.<br />
I plan to add support for other libraries (if there is interest) in the future so keep in touch.</span></p>
<p>Remote forgery protection currently supports <a href="http://www.prototypejs.org">Prototype</a>, <a href="http://www.jquery.com">jQuery</a> and <a href="http://www.extjs.com">ExtJS</a>. Let me know if you would like to see it working with some other library</p>
<p>Plugin page: <a href="http://github.com/vlado/remote_forgery_protection">http://github.com/vlado/remote_forgery_protection</a></p>
<p>More info:<br />
<a href="http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html">api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html</a><br />
<a href="http://isc.sans.org/diary.html?storyid=1750">isc.sans.org/diary.html?storyid=1750</a><br />
<a href="http://en.wikipedia.org/wiki/Cross-site_request_forgery">en.wikipedia.org/wiki/Cross-site_request_forgery</a><br />
<a href="http://opensoul.org/2008/10/24/ajax-and-request-forgery-protection">opensoul.org/2008/10/24/ajax-and-request-forgery-protection</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2010/01/02/rails-csrf-and-ajax-requests/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

