<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Taknado - Home</title>
  <id>tag:www.taknado.com,2008:mephisto/</id>
  <generator version="0.7.3" uri="http://mephistoblog.com">Mephisto Noh-Varr</generator>
  <link href="http://www.taknado.com/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://www.taknado.com/" rel="alternate" type="text/html"/>
  <updated>2007-10-30T12:46:38Z</updated>
  <entry xml:base="http://www.taknado.com/">
    <author>
      <name>Eugene</name>
    </author>
    <id>tag:www.taknado.com,2007-10-30:31</id>
    <published>2007-10-30T12:45:00Z</published>
    <updated>2007-10-30T12:46:38Z</updated>
    <category term="English bloggie"/>
    <category term="rails actioncontroller"/>
    <link href="http://www.taknado.com/2007/10/30/poking-in-actioncontroller" rel="alternate" type="text/html"/>
    <title>Poking in ActionController</title>
<summary type="html">&lt;p&gt;I have an &#8216;accept&#8217; action in one of the controllers and when I was trying to run a functional test against it I got:&lt;/p&gt;


&lt;code class=&quot;console&quot;&gt;
ActionController::UnknownAction in 'ContributorRequestsController for moderator allow to accept a request'
No action responded to accept
&lt;/code&gt;

	&lt;p&gt;And of course it worked fine when I&#8217;ve actually started the server and invoked it from browser.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;I have an &#8216;accept&#8217; action in one of the controllers and when I was trying to run a functional test against it I got:&lt;/p&gt;


&lt;code class=&quot;console&quot;&gt;
ActionController::UnknownAction in 'ContributorRequestsController for moderator allow to accept a request'
No action responded to accept
&lt;/code&gt;

	&lt;p&gt;And of course it worked fine when I&#8217;ve actually started the server and invoked it from browser.&lt;/p&gt;
&lt;p&gt;I&#8217;ve realized that the reason probably was some name clashing or something, but it only appeared in the tests. So I&#8217;ve decided to have some debugging fun and I think the outcome is the case when code extracts speak louder than words:&lt;/p&gt;


	&lt;p&gt;ActionController::Base:&lt;/p&gt;


&lt;code class=&quot;ruby&quot;&gt;
def perform_action
  if self.class.action_methods.include?(action_name) 
    ...
  else
    raise UnknownAction, &quot;No action responded to #{action_name}&quot;, caller
  end
end

def self.action_methods
  @action_methods ||= Set.new(public_instance_methods - hidden_actions)
end

def hidden_actions
  write_inheritable_attribute(:hidden_actions, ActionController::Base.public_instance_methods) unless read_inheritable_attribute(:hidden_actions)
  read_inheritable_attribute(:hidden_actions)
end
&lt;/code&gt;

	&lt;p&gt;If your action is named as one of the ActionController::Base.public_instance_methods then it won&#8217;t be invoked. While that&#8217;s reasonable, I wondered what that reserved &#8216;accept&#8217; method did. I&#8217;ve failed to find it in the rails and rspec sources and finally simply did a search for &#8216;def accept&#8217; against the project and found it in lib/authenticated_test_helper.rb which is generated by acts_as_authenticated plugin.&lt;/p&gt;


&lt;code class=&quot;ruby&quot;&gt;
def accept(accept)
  @request.env[&quot;HTTP_ACCEPT&quot;] = accept
end
&lt;/code&gt;
          </content>  </entry>
  <entry xml:base="http://www.taknado.com/">
    <author>
      <name>Eugene</name>
    </author>
    <id>tag:www.taknado.com,2007-10-01:26</id>
    <published>2007-10-01T09:27:00Z</published>
    <updated>2007-10-01T09:46:13Z</updated>
    <category term="English bloggie"/>
    <category term="NetBeans JRockit"/>
    <link href="http://www.taknado.com/2007/10/1/netbeans-bea-jrockit" rel="alternate" type="text/html"/>
    <title>NetBeans + BEA JRockit</title>
<content type="html">
            &lt;p&gt;NetBeans Ryby &lt;span class=&quot;caps&quot;&gt;IDE&lt;/span&gt; was cool. On my PC at work. But when I&#8217;ve got a new laptop and switched to working on it, it appeared to be dead slow when editing &lt;span class=&quot;caps&quot;&gt;RHTML&lt;/span&gt; files. I&#8217;ve tried to figure out the reason (tried different builds, settings, etc&#8230;) and finally realized that I&#8217;ve had &lt;a href=&quot;http://www.bea.com/framework.jsp?CNT=index.htm&amp;amp;#38;FP=/content/products/weblogic/jrockit/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;BEA&lt;/span&gt; JRockit &lt;span class=&quot;caps&quot;&gt;JVM&lt;/span&gt;&lt;/a&gt; on my PC and &lt;span class=&quot;caps&quot;&gt;SUN JVM&lt;/span&gt; on the laptop. So I&#8217;ve installed &lt;a href=&quot;http://www.bea.com/framework.jsp?CNT=index.htm&amp;amp;#38;FP=/content/products/weblogic/jrockit/&quot;&gt;JRockit&lt;/a&gt; and now it seems to work great again.&lt;/p&gt;


	&lt;p&gt;So the moral is that NetBeans appears to work faster on AMD64&#215;2/Ubuntu laptop with &lt;a href=&quot;http://www.bea.com/framework.jsp?CNT=index.htm&amp;amp;#38;FP=/content/products/weblogic/jrockit/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;BEA&lt;/span&gt; JRockit&lt;/a&gt;. Perhaps not just for me&#8230;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.taknado.com/">
    <author>
      <name>Eugene</name>
    </author>
    <id>tag:www.taknado.com,2007-08-31:20</id>
    <published>2007-08-31T11:00:00Z</published>
    <updated>2007-08-31T11:15:09Z</updated>
    <category term="&#1041;&#1083;&#1086;&#1075; &#1085;&#1072; &#1088;&#1091;&#1089;&#1089;&#1082;&#1086;&#1084;"/>
    <category term="&#1055;&#1077;&#1088;&#1077;&#1074;&#1086;&#1076;"/>
    <category term="Rails"/>
    <category term="REST"/>
    <link href="http://www.taknado.com/2007/8/31/rest-on-rails" rel="alternate" type="text/html"/>
    <title>&#1055;&#1077;&#1088;&#1077;&#1074;&#1086;&#1076; &#1089;&#1077;&#1088;&#1080;&#1080; &#1089;&#1090;&#1072;&#1090;&#1077;&#1081; &#1087;&#1088;&#1086; REST on Rails</title>
<content type="html">
            &lt;p&gt;Когда я искал инфу о &lt;span class=&quot;caps&quot;&gt;REST&lt;/span&gt;, то нашел на мой взгляд хороший &lt;a href=&quot;http://www.softiesonrails.com/tags/rest&quot;&gt;туториал (101) из 5-ти частей&lt;/a&gt;, автором которого является &lt;a href=&quot;http://jeffcohenonline.com/&quot;&gt;Jeff Cohen&lt;/a&gt;. Сам автор предложил опубликовать ссылки на переводы туториала на другие языки и я решил попробовать перевести его на русский. Я далеко не переводчик, и не филолог/лингвист, поэтому перевод наверняка изобилует разнообразными ошибками. Если есть желание принять участие в редактировании &#8211; пишите. И конечно, всегда лучше читать подобные вещи в оригинале (там  с картинками и прибаутками), но тем не менее вот:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;http://www.taknado.com/2007/7/30/rest-1&quot;&gt;Часть 1. Ресурсы.&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;http://www.taknado.com/2007/7/31/rest-2&quot;&gt;Часть 2. Миллионы &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt;.&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;http://www.taknado.com/2007/8/1/rest-3&quot;&gt;Часть 3. Проектирование согласно &lt;span class=&quot;caps&quot;&gt;REST&lt;/span&gt;.&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;http://www.taknado.com/2007/8/8/rest-4&quot;&gt;Часть 4. Маршрутизация.&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;http://www.taknado.com/2007/8/31/rest-5&quot;&gt;Часть 5. Ответ.&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;P.S. Большое спасибо Антону (aka Tonic) за помощь с переводом.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.taknado.com/">
    <author>
      <name>Eugene</name>
    </author>
    <id>tag:www.taknado.com,2007-08-16:17</id>
    <published>2007-08-16T11:39:00Z</published>
    <updated>2007-09-27T11:00:15Z</updated>
    <category term="English bloggie"/>
    <category term="Command Line"/>
    <category term="Rails"/>
    <category term="Tips"/>
    <link href="http://www.taknado.com/2007/8/16/rails-windows-command-line-tips" rel="alternate" type="text/html"/>
    <title>Rails + Windows Command Line Tips</title>
<summary type="html">&lt;p&gt;We do lot&#8217;s of things from console when using Rails and it can be a little painful on Windows. However, we can try to make our lives better.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;We do lot&#8217;s of things from console when using Rails and it can be a little painful on Windows. However, we can try to make our lives better.&lt;/p&gt;
&lt;p&gt;To begin with, I must confess in being a great lamer. I always used Windows (Update: Finally on Ubuntu!) (except some crazy attempts including a night session of trying to run MacOSx86 on VmWare, qemu and kqemu under Linux on a processor that doesn&#8217;t support &lt;span class=&quot;caps&quot;&gt;SSE2&lt;/span&gt;), never used things like Far manager (the tool used by all crazy Windows guys, well, at least in Russia), never wrote bat files (except the ones in the University that were considered to be viruses by &lt;a href=&quot;http://www.kaspersky.com/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;AVP&lt;/span&gt;&lt;/a&gt; for some reason), never managed to remember all those tricky keyboard shortcuts, nothing.&lt;/p&gt;


	&lt;p&gt;But once started to use Rails I began to love The Console. Really, lot&#8217;s of things can be done easier and faster. But there are several things I don&#8217;t like about the Windows console (cmd.exe).&lt;/p&gt;


	&lt;p&gt;First of all, I use gems documentation a lot. The one that can be accessed from the browser on the 8808 port (by default) when you run gem_server. It&#8217;s cool. The only thing I hated about it is that I had to run it every day and that its console window was hanging about the desktop. So I&#8217;ve found a nice tool called &lt;a href=&quot;http://www.ntwind.com/software/utilities/hstart.html&quot;&gt;Hidden Start&lt;/a&gt; that allows to run console applications in the background without any windows. So I&#8217;ve simply added it to the Startup folder and now I can access RDoc gems documentation instantly!&lt;/p&gt;


	&lt;p&gt;The next thing I do very often is starting the console session to run tests, rake tasks or other things against my Rails application. The thing I hated is that I had to change the current directory (home directory that is opened by default when one starts cmd.exe) to the directory of the application, which always took a while cause I&#8217;ve had to change the drive and type the long path to the application. I wanted just to open a console and type a command without changing the directory. It appeared that one can change the default cmd directory by hacking the registry, but I didn&#8217;t want that cause I have several applications that I want to use console with. So I created a shortcut for cmd that opens the console window and sets the current directory (I&#8217;ve found the parameters somewhere on the net):&lt;/p&gt;


&lt;code class=&quot;console&quot;&gt;
%windir%\system32\cmd.exe /k &quot;cd /d d:\really_long_path_to_my_rails_project&quot; 
&lt;/code&gt;

	&lt;p&gt;The last thing is the Rails Application Server. I currently use Mongrel, but it doesn&#8217;t really matter. Every day I had to open the console window, change the directory (Shit! Again!) and run ruby script/console, which I also hated of course. This time a simple bat file saved my hair (at least for a while):&lt;/p&gt;


&lt;code class=&quot;console&quot;&gt;
cd /d d:/really_long_path_to_my_rails_project
ruby script/server
&lt;/code&gt;

	&lt;p&gt;I&#8217;ve added the above mentioned 2 files to my quick launch panel and now I feel happier! But as stated, I&#8217;m a lamer, so I&#8217;ll be grateful to hear ideas on how to make it better.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.taknado.com/">
    <author>
      <name>Eugene</name>
    </author>
    <id>tag:www.taknado.com,2007-07-30:8</id>
    <published>2007-07-30T10:32:00Z</published>
    <updated>2007-07-30T10:38:38Z</updated>
    <category term="English bloggie"/>
    <category term="Override"/>
    <category term="Rails"/>
    <category term="Rake"/>
    <link href="http://www.taknado.com/2007/7/30/overriding-rake-tasks" rel="alternate" type="text/html"/>
    <title>Overriding Rake Tasks</title>
<summary type="html">&lt;p&gt;It seems that I&#8217;m lucky cause the project I&#8217;m currently working on forces me to deal with non-typical problems again and again. This time I need to override one of the default Rails Rake tasks behaviour. For some reason I thought that I&#8217;ll simply be able to do it somehow, but it appeared that Rake doesn&#8217;t allow that and I&#8217;ve ended up with another plugin :)&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;It seems that I&#8217;m lucky cause the project I&#8217;m currently working on forces me to deal with non-typical problems again and again. This time I need to override one of the default Rails Rake tasks behaviour. For some reason I thought that I&#8217;ll simply be able to do it somehow, but it appeared that Rake doesn&#8217;t allow that and I&#8217;ve ended up with another plugin :)&lt;/p&gt;
&lt;p&gt;I won&#8217;t describe why I needed to override Rake tasks right now, I&#8217;m going to post another article about it latter, let&#8217;s just take it as a matter of course for now.&lt;/p&gt;


	&lt;p&gt;First of all I&#8217;ve tried to simply define a new task with the same name as the existing one and thought that it will work, but Rake adds the new task to the queue in this case and runs both (the new one after the original one).&lt;/p&gt;


	&lt;p&gt;Then I&#8217;ve tried to read more about Rake and found out that one can add &#8220;prerequisites&#8221; for the tasks (even for exisitng ones) like this:&lt;/p&gt;



&lt;code class=&quot;ruby&quot;&gt;
task :test =&amp;gt; ['pre_test_task1', 'pre_test_task2']
&lt;/code&gt;


	&lt;p&gt;While that&#8217;s very helpfull, it doesn&#8217;t solve my problem. As usual I&#8217;ve googled for a solution and found &lt;a href=&quot;http://matthewbass.com/2007/03/07/overriding-existing-rake-tasks/&quot;&gt;Matthew Bass&#8217;s blog post&lt;/a&gt;. Actually Mattew described a working solution, but I didn&#8217;t like the way it looked. To override a task one have to add the new tasks to the Rakefile like this (we&#8217;re overriding Rails &#8220;test&#8221; task):&lt;/p&gt;



&lt;code class=&quot;ruby&quot;&gt;
remove_task :test
task :test do
  #new task code here
end
&lt;/code&gt;


	&lt;p&gt;I didn&#8217;t like the idea of adding new tasks to the Rakefile and the &#8220;remove_task&#8221; method call before each task. So I&#8217;ve spent a couple of hours   messing with Rake sources and finally written an &#8220;override_task&#8221; method that actually deleted existing task with the given name and defined a new one. It can be used like this:&lt;/p&gt;



&lt;code class=&quot;ruby&quot;&gt;
override_task :test do
  #new task code here
end
&lt;/code&gt;


	&lt;p&gt;You can put this in you app&#8217;s lib/tasks as usual, or add it to one of your plugins&#8217; tasks. It works with a namespace too of course:&lt;/p&gt;



&lt;code class=&quot;ruby&quot;&gt;
namespace :db do
  override_task :migrate do
    #new migration code here 
  end
end
&lt;/code&gt;


	&lt;p&gt;Then, I thought if it could be made as a plugin. In order to make it work, the code written should be loaded before the tasks and it means that Rakefile should be modified to load it. I&#8217;ve recently messed with &lt;a href=&quot;http://jarmark.org/projects/app-config/&quot;&gt;app_config plugin by Daniel Owsiański&lt;/a&gt; and noticed the way it adds a line to environment.rb during installation. I&#8217;ve simply copied the idea and the plugin was ready! During installation it adds a line to the Rakefile that loads the plugin itself.&lt;/p&gt;


	&lt;p&gt;To play with it do the usual&lt;/p&gt;



&lt;code class=&quot;console&quot;&gt;
script/plugin install http://tools.assembla.com/svn/rails_plugins/override_rake_task
&lt;/code&gt;
          </content>  </entry>
  <entry xml:base="http://www.taknado.com/">
    <author>
      <name>Eugene</name>
    </author>
    <id>tag:www.taknado.com,2007-07-26:5</id>
    <published>2007-07-26T13:48:00Z</published>
    <updated>2007-11-21T12:35:40Z</updated>
    <category term="English bloggie"/>
    <category term="Rails"/>
    <category term="Rake"/>
    <category term="SVN"/>
    <link href="http://www.taknado.com/2007/7/26/rake-task-to-display-svn-commits-by-user" rel="alternate" type="text/html"/>
    <title>Rake Task to Display SVN Commits by User</title>
<summary type="html">&lt;p&gt;At my current job I&#8217;m being asked to send a list of trac tickets I&#8217;ve been working on in the previous 2 weeks. After reading &lt;a href=&quot;http://www.rails.cz/articles/2006/11/01/layout-with-svn-revision&quot;&gt;this post&lt;/a&gt; I figured out that it can be easily done with Rake (well, as everything else you can dream about).&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;At my current job I&#8217;m being asked to send a list of trac tickets I&#8217;ve been working on in the previous 2 weeks. After reading &lt;a href=&quot;http://www.rails.cz/articles/2006/11/01/layout-with-svn-revision&quot;&gt;this post&lt;/a&gt; I figured out that it can be easily done with Rake (well, as everything else you can dream about).&lt;/p&gt;
&lt;p&gt;Since we&#8217;re using an svn hook that adds notes to the related trac tickets on commit, each revision associated with a ticket has its number in the comments. So all I (Rake task) have to do is to collect all my commit commets, pull ticket numbers from them (typical commit comment can look like this: &#8220;refs #786&#8221;) and display a list, ordered by date.&lt;/p&gt;


	&lt;p&gt;I didn&#8217;t play with command line svn client much previously, but when I&#8217;ve started to write the task I&#8217;ve figured out that we can get the svn log in xml using the &#8220;&#8212;xml&#8221; option. Even better!&lt;/p&gt;


	&lt;p&gt;So I&#8217;ve ended up with this:&lt;/p&gt;



&lt;code class=&quot;ruby&quot;&gt;
namespace :svn do
  namespace :log do
    desc 'Displays commints by user in the specified period of time. Usage: rake svn:log:by_user USER=username PASSWORD=pass [URL=repo_url] PERIOD=period_option. Where valid period_options: m - current month, 2w - previous 2 working weeks (monday - friday)'
    task :by_user =&amp;gt; :environment do

      url = ENV['URL'].to_s
      password = ENV['PASSWORD'].to_s
      period = ['m', '2w'].include?(ENV['PERIOD']) ? ENV['PERIOD'] : '2w'
      #USER parameter is mandatory
      raise 'use rake:svn:log:by_user USER=svn_username' unless user = ENV['USER']

      case period
        when 'm'
          start_date = Time.now.beginning_of_month.gmtime
          end_date = Time.now.gmtime
        when '2w'
          start_date = (Time.now.beginning_of_week - 2.weeks).gmtime
          end_date = Time.now.beginning_of_week.gmtime
      end

      #datetime format used by svn log
      TF = '%Y-%m-%d %H:%M:%S +0000'
      #we'll use this var to store commits for each day
      days = {}

      require 'rexml/document' 

      log = REXML::Document.new(`svn log #{url} --xml -r &quot;{#{start_date.strftime(TF)}}:{#{end_date.strftime(TF)}}&quot; --username #{user} --password #{password}`)

      log.root.each_element do |log_entry|

      #save each revision entry to a hash
      revision = {:number =&amp;gt; log_entry.attributes['revision']}
      log_entry.each_element { |log_detail| revision[log_detail.name.to_sym] = log_detail.text } 

      #is it my revision?
      if revision[:author] == user
        day = Time.parse(revision[:date]).strftime('%y.%m.%d')
        #for each day we want a list of trac tickets affected or revision number
        #trac tickets numbers are included in the comment like this: #687
        #so we'll try to find such numbers using regexp
        #if there are no tickets numbers we'll simply use revision number like this: [1235]
        tickets = revision[:msg].to_s.scan(/#\d+/)
        tickets &amp;lt;&amp;lt; &quot;[#{revision[:number]}]&quot; if tickets.empty?
        (days[day] ||= []) &amp;lt;&amp;lt; tickets.join(', ')
        end

      end

      #and we simply output all commits day by day
      days.keys.sort.each do |day|
        puts &quot;#{day} | #{days[day].join(', ')}&quot; 
      end

    end
  end
end
&lt;/code&gt;


	&lt;p&gt;The task takes 4 parameters: &lt;span class=&quot;caps&quot;&gt;USER&lt;/span&gt; (mandatory) &#8211; well, obvious, &lt;span class=&quot;caps&quot;&gt;PASSWORD&lt;/span&gt; (mandatory), &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt; (optional) &#8211; can be provided if rails app is not a working copy of repository you&#8217;d like to get a log from and &lt;span class=&quot;caps&quot;&gt;PERIOD&lt;/span&gt; &#8211; &#8220;m&#8221; to use the revisions made in this month only and &#8220;2w&#8221; (default) to use revisions made in the previous 2 working weeks.  So I can run it like this:&lt;/p&gt;



&lt;code class=&quot;console&quot;&gt;rake svn:log:by_user USER=eugene.bolshakov PASSWORD=secret PERIOD=m&lt;/code&gt;


	&lt;p&gt;and get something like this:&lt;/p&gt;



&lt;code class=&quot;console&quot;&gt;
...
07.07.23 | [2256], [2264], [2265]
07.07.24 | #787, #801, #783
07.07.25 | #786, #823
07.07.26 | [2346]
...
&lt;/code&gt;


	&lt;p&gt;The numbers with sharp are ticket numbers and those in square brackets are the revision numbers. They are displayed if the revision is not related to any trac ticket. Yeah, I know it could be done easier with xpath, but my knowledge of it is poor :(&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.taknado.com/">
    <author>
      <name>Eugene</name>
    </author>
    <id>tag:www.taknado.com,2007-07-25:3</id>
    <published>2007-07-25T14:31:00Z</published>
    <updated>2007-11-21T12:27:01Z</updated>
    <category term="English bloggie"/>
    <category term="Rails"/>
    <category term="Rake"/>
    <category term="Session Expiry"/>
    <link href="http://www.taknado.com/2007/7/25/rake-task-to-clear-expired-session-files" rel="alternate" type="text/html"/>
    <title>Rake Task to Clear Expired Session Files</title>
<summary type="html">&lt;p&gt;Perhaps some guys who came to Rails from &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; expected session expiry to be handled automatically. But in Rails we have to deal with it ourselves. There&#8217;s an &lt;a href=&quot;http://www.rorsecurity.info/2007/04/10/ruby-on-rails-sessions-introduction-and-expiry/&quot;&gt;awesome article on the topic&lt;/a&gt;. The main idea is that we need to clear expired sessions which were not accessed for some time and the ones which were created a long time ago. I&#8217;ve tried to find a ready-made script for this purpose, but found the ones that deal with database based sessions only, so decided to write it myself.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;Perhaps some guys who came to Rails from &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; expected session expiry to be handled automatically. But in Rails we have to deal with it ourselves. There&#8217;s an &lt;a href=&quot;http://www.rorsecurity.info/2007/04/10/ruby-on-rails-sessions-introduction-and-expiry/&quot;&gt;awesome article on the topic&lt;/a&gt;. The main idea is that we need to clear expired sessions which were not accessed for some time and the ones which were created a long time ago. I&#8217;ve tried to find a ready-made script for this purpose, but found the ones that deal with database based sessions only, so decided to write it myself.&lt;/p&gt;
&lt;code class=&quot;ruby&quot;&gt;
require 'find'

namespace :tmp do
  namespace :sessions do
    desc 'Clear expired sessions'
    task :clear_expired =&amp;gt; :environment do
      ctime = (ENV['ctime'] || 120).to_i
      atime = (ENV['atime'] ||  30).to_i
      Find.find(RAILS_ROOT + &quot;/tmp/sessions/&quot;) do |path|
        if FileTest.directory?(path)
          if File.basename(path)[0] == ?.
            Find.prune
          else
            next
          end
        else
          File.delete(path) if File.ctime(path) &amp;lt; ctime.minutes.ago or File.atime(path) &amp;lt; atime.minutes.ago
        end
      end
    end
  end
en
&lt;/code&gt;


	&lt;p&gt;It can be run with 2 optional parameters: &#8220;atime&#8221;, which defines the time in minutes that will be compared against the last access time of a session file and &#8220;ctime&#8221; which defines the time in minutes that will be compared against the creation time of a session file. The default values are: ctime = 120 (minutes) and atime = 20 (miuntes) which means that the session files not accessed in the last 20 minutes and created earlier than 2 hours ago will be removed when the script runs.&lt;/p&gt;


	&lt;p&gt;You can run it like this (I&#8217;m overriding default time parameters in the example):&lt;/p&gt;



&lt;code class=&quot;console&quot;&gt;
rake tmp:sessions:clear_expired atime=15 ctime=60
&lt;/code&gt;


	&lt;p&gt;Of course you&#8217;ll set up a cron to run the script periodiacally and clear expired sessions for you, but please note that the actuall maximum session lifetime will be atime + the time between 2 script runs.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.taknado.com/">
    <author>
      <name>Eugene</name>
    </author>
    <id>tag:www.taknado.com,2007-07-25:2</id>
    <published>2007-07-25T08:06:00Z</published>
    <updated>2007-11-21T12:26:02Z</updated>
    <category term="English bloggie"/>
    <category term="Configuration"/>
    <category term="Plugin"/>
    <category term="Rails"/>
    <link href="http://www.taknado.com/2007/7/25/custom-configuration-info-in-rails" rel="alternate" type="text/html"/>
    <title>Custom Configuration Info in Rails</title>
<summary type="html">&lt;p&gt;I think most applications deal with some kind of configuration parameters like admin emails, directory paths or whatever. Sometimes having a bunch of constants in environment.rb is fine, but when you have several developers working on a project and each of them may have their own values and can add new parameters you need a clean solution to handle that.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;I think most applications deal with some kind of configuration parameters like admin emails, directory paths or whatever. Sometimes having a bunch of constants in environment.rb is fine, but when you have several developers working on a project and each of them may have their own values and can add new parameters you need a clean solution to handle that.&lt;/p&gt;
&lt;p&gt;The common practise is to have an &#8220;example&#8221; config file under version control (like database.example.yml in mephisto) which is used by all developers to create their local files with custom values. That works OK until someone adds a new parameter to the example file and some careless developer (me) doesn&#8217;t notice it in the svn logs, forgets to update his local file and gets a broken application. So I thought that I need a file under version control with default values which is actually used by the application and an ability to have another file with local values that will override the default.&lt;/p&gt;


	&lt;p&gt;I&#8217;ve googled for a ready-made solution and found &lt;a href=&quot;http://kpumuk.info/ruby-on-rails/flexible-application-configuration-in-ruby-on-rails/lang-pref/en/&quot;&gt;this one&lt;/a&gt; which I liked, but as I&#8217;ve just said I also wanted to override the default settings in a local file and also wanted yml file to be parsed with &lt;span class=&quot;caps&quot;&gt;ERB&lt;/span&gt; so that I could use Ruby in it (for example if I needed to use &lt;span class=&quot;caps&quot;&gt;RAILS&lt;/span&gt;_ROOT to define some path). And so I&#8217;ve ended up with my first rails plugin :)&lt;/p&gt;


	&lt;p&gt;The plugin allows you to have a config.yml file with a &#8220;common&#8221; section that contains all configuration parameters with their default values and a section for each Rails environment (like development, test, production or your custom one) where you can override the values from the common section. Just put this file under version control, update it with new parameters and all developers will have it with the next update. If someone needs his own specific values, he can simply create a config.local.yml file and override any value there, again having a &#8220;common&#8221; section and a section for each environment. Nothing is mandatory (files, sections) &#8211; you just have what you really need.&lt;/p&gt;


	&lt;p&gt;An example of a config file:&lt;/p&gt;



&lt;code class=&quot;ruby&quot;&gt;
common:
  admin_email: admin@domain.com
  xml_rpc_url: http://domain.com:8000/
  media_path: &amp;lt;%= RAILS_ROOT %&amp;gt;/tmp/media

development:
  xml_rpc_url: http://localhost:8000/

test:
  xml_rpc_url: http://localhost:8008/
&lt;/code&gt;


	&lt;p&gt;Then, in the application you can use the config parameters like this:&lt;/p&gt;



&lt;code class=&quot;ruby&quot;&gt;Conf.xml_rpc_url&lt;/code&gt;


	&lt;p&gt;So it means that you&#8217;ve got a Conf object which holds all the configuration parameters defined. It doesn&#8217;t allow to change the values in the application code, &lt;span class=&quot;caps&quot;&gt;BTW&lt;/span&gt; (so that a typo in a if statement won&#8217;t cause weird errors :)).&lt;/p&gt;


	&lt;p&gt;You can give it a try if you like:&lt;/p&gt;



&lt;code class=&quot;console&quot;&gt;script/plugin install http://tools.assembla.com/svn/rails_plugins/app_config&lt;/code&gt;


	&lt;p&gt;Comments and suggestions are welcome of course ;)&lt;/p&gt;


	&lt;p&gt;Update: I&#8217;ve renamed the configuration variable from Config to Conf.&lt;/p&gt;
          </content>  </entry>
</feed>
