<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Startika Ruby Blog - Blog</title>
  <id>tag:blog.startika.com,2008:mephisto/</id>
  <generator uri="http://mephistoblog.com" version="0.7.3">Mephisto Noh-Varr</generator>
  <link href="http://blog.startika.com/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://blog.startika.com/" rel="alternate" type="text/html"/>
  <updated>2008-05-10T17:52:40Z</updated>
  <entry xml:base="http://blog.startika.com/">
    <author>
      <name>labria</name>
    </author>
    <id>tag:blog.startika.com,2008-05-10:125</id>
    <published>2008-05-10T17:51:00Z</published>
    <updated>2008-05-10T17:52:40Z</updated>
    <link href="http://blog.startika.com/2008/5/10/ajaxy-rails-docs" rel="alternate" type="text/html"/>
    <title>Ajaxy rails docs.</title>
<content type="html">
            &lt;p&gt;I don&#8217;t know if i&#8217;m the only one with the problem, but i just couldn&#8217;t get the &#8220;doc:rails&#8221; rake task to work with the &lt;a href=&quot;http://github.com/breakpointer/ajax-rdoc/&quot;&gt;jaxdoc&lt;/a&gt; RDoc template. I finished by running rdoc by hand to create the docs, here&#8217;s the &lt;a href=&quot;http://pastie.caboo.se/194856&quot;&gt;code&lt;/a&gt;
Tell me if I forgot to exclude something.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://blog.startika.com/">
    <author>
      <name>labria</name>
    </author>
    <id>tag:blog.startika.com,2008-03-27:115</id>
    <published>2008-03-27T23:18:00Z</published>
    <updated>2008-03-27T23:20:56Z</updated>
    <link href="http://blog.startika.com/2008/3/27/sharing-sessions-between-rails-apps" rel="alternate" type="text/html"/>
    <title>Sharing sessions between Rails apps.</title>
<content type="html">
            &lt;p&gt;Sometimes (in my case 2 times) you may have more than one application running off the same database, partially sharing model code. In the first case I had 4 apps (one main and four satellites) running this way, but the userbase was not shared between them (most users didn&#8217;t actually know of the other apps), so common sessions were not needed. In the second case (a distrbuted file sharing network) users floated between the main site and satellites and I wanted to include flash[:notices] while redirecting them. As you know, flash messages are kept in the session, so i needed all the apps to share the session data for the user.&lt;/p&gt;


	&lt;p&gt;There are 2 things you need to do to share sessions (this applies when using subdomains, i&#8217;m not sure if it&#8217;s doable with totally different domains).&lt;/p&gt;


First: make all the apps use the same session key and secret by editing the environment.rb file: 
&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;  config.action_controller.session = {&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;sy&quot;&gt;:session_key&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;_your_session&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;,&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;sy&quot;&gt;:secret&lt;/span&gt;      =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;some_long_string_of_letters_and_numbers&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  }&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

This is done so all your apps recognize each others session data.

Second, you need to alter the session_domain option of ActionController (in one of your initializers files):
&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;co&quot;&gt;ActionController&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;CgiRequest&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;DEFAULT_SESSION_OPTIONS&lt;/span&gt;.update(&lt;span class=&quot;sy&quot;&gt;:session_domain&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;.yourdomain.com&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

This one is to make the subdomains recognize the main domain&#8217;s cookies.

	&lt;p&gt;My problem, however, was that this setup worked only one way. I could set session variables in the main app and read from the satellite, but not the other way. As  found out later, the problem is that the rails2 default session store is CookieStore. And cookies written by the top level domain can&#8217;t be altered by subdomains. To fix this i had to migrate to the ActiveRecord session store.&lt;/p&gt;


	&lt;p&gt;After a few hours of setting all of this up and testing, I decided that all of this was too much pain and security issues to be used in production, so I&#8217;ll just have another way of sending messages between the apps. But I also thought that someone may find this info useful (the CookieStore problem wasn&#8217;t evident to me), so I wanted to share it =)&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://blog.startika.com/">
    <author>
      <name>labria</name>
    </author>
    <id>tag:blog.startika.com,2008-02-26:110</id>
    <published>2008-02-26T23:07:00Z</published>
    <updated>2008-02-26T23:10:14Z</updated>
    <link href="http://blog.startika.com/2008/2/26/ssl-client-certificate-login-pt-4" rel="alternate" type="text/html"/>
    <title>SSL client certificate login pt.4</title>
<content type="html">
            &lt;p&gt;Well, I made some progress and now the whole thing is a rails plugin, based on the restful_authentication one. You can get it here: git://github.com/labria/restful-authentication.git&lt;/p&gt;


	&lt;p&gt;The readme has all the info. If something is missing, not working or anything else, please tell me, it&#8217;s my first rails plugin ever. By the way if you even bother testing it or looking at the code, please leave me a comment.&lt;/p&gt;


Things to do yet:
	&lt;ul&gt;
	&lt;li&gt;remove some hard-coded stuff.&lt;/li&gt;
		&lt;li&gt;make certificate delivery more natural (if I happen to find a way to do it)&lt;/li&gt;
		&lt;li&gt;dunno, I think much more will come up…&lt;/li&gt;
	&lt;/ul&gt;
          </content>  </entry>
  <entry xml:base="http://blog.startika.com/">
    <author>
      <name>labria</name>
    </author>
    <id>tag:blog.startika.com,2008-02-25:105</id>
    <published>2008-02-25T17:03:00Z</published>
    <updated>2008-02-25T17:04:02Z</updated>
    <link href="http://blog.startika.com/2008/2/25/ssl-client-certificate-login-pt-3" rel="alternate" type="text/html"/>
    <title>SSL client certificate login pt.3</title>
<content type="html">
            &lt;p&gt;Well, I made it, kinda&#8230;&lt;/p&gt;


	&lt;p&gt;The code is still a awful mess, but it works. Some portions of the code and setup are dictated by my setup involving a nginx server. With apache it should be simpler, with lighttpd it wouldn&#8217;t work at all, as far as I know.&lt;/p&gt;


	&lt;p&gt;Anyway, this is the way it works. You go to the site with http and register. The modified restful_authentication plugin instantly generates your client certificate. You get by clicking a link in the p12 format. The signing (self-signed) certificate is generated with the first user certificate (i&#8217;ll move this to a rake task later). After installing the certificate you can go to the site with https (before installing it nginx would reject you and redirect you to the non-https version of the login page). Now, if you log out and go to the session/new page, your certificate gets checked and, if your user is found (he should be), you get logged in automagically. Not much, but it&#8217;s all it does.&lt;/p&gt;


Now, about the code. There is not much code, really. Everything works from a combination of the modded restful_authentication plugin and the QuickCert library. If someone will actually find the whole thing useful, i&#8217;ll repackage it as a restful_authentication plugin fork, with some rake tasks and generators, and stuff. The nginx server is configured to use a self-signed certificate for the &lt;span class=&quot;caps&quot;&gt;SSL&lt;/span&gt; connection, and the app generated certificate to check client certificates, this way:
&lt;pre&gt;&lt;code&gt;server {
    listen       443;
    server_name  ssltest.startika.com;
    ssl                  on;
    ssl_certificate      /u/stuff/CA/demoCA/private/server.crt;
    ssl_certificate_key  /u/stuff/CA/demoCA/private/server.key;
    ssl_client_certificate /u/apps/ssltest/current/cert/CA/cacert.pem;
    ssl_verify_client on;
    ssl_verify_depth 2;
    ssl_session_timeout  5m;
    error_page 496 http://ssltest.startika.com/session/new;
    error_page 495 http://ssltest.startika.com/session/new;
    error_page 497 http://ssltest.startika.com/session/new;
    ssl_protocols  SSLv2 SSLv3 TLSv1;
    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    ssl_prefer_server_ciphers   on;
    root   /u/apps/ssltest/current;
    location / {
      proxy_set_header X-Real-IP  $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-FORWARDED_PROTO https;
      proxy_set_header X-SSL_CLIENT_S_DN $ssl_client_s_dn;
      proxy_set_header X-SSL_PROTO $ssl_protocol;
      proxy_pass http://ssl_test;
      break;
  }
}&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Well, if you want to see for yourself, just go to &lt;a href=&quot;http://ssltest.startika.com/&quot;&gt;http://ssltest.startika.com/&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;If you want to see the code (I&#8217;m ashamed of it, but it&#8217;s the only proof I have I actually made this), you can get it from github here: &lt;a href=&quot;http://github.com/labria/rails-ssl-authentication/tree/master&quot;&gt;http://github.com/labria/rails-ssl-authentication/&lt;/a&gt; (sorry for the mess, I&#8217;m quite a noob programmer yet&#8230;)&lt;/p&gt;


	&lt;p&gt;&lt;em&gt;PS:&lt;/em&gt; If you will actually go and test the thing, don&#8217;t forget Safari has serious issues with certificates, better use Firefox =)&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://blog.startika.com/">
    <author>
      <name>labria</name>
    </author>
    <id>tag:blog.startika.com,2008-02-23:101</id>
    <published>2008-02-23T21:30:00Z</published>
    <updated>2008-02-23T22:11:59Z</updated>
    <link href="http://blog.startika.com/2008/2/23/ssl-client-certificate-login-pt-2" rel="alternate" type="text/html"/>
    <title>SSL client certificate login pt.2</title>
<content type="html">
            &lt;p&gt;Well, I&#8217;ve made some progress at last. Now my test app lets you logon automatically if you happen to have a certificate whose name and email matches a user in the DB. Still, you have to have &lt;em&gt;some&lt;/em&gt; certificate just to get to the site, but &#8220;a progress there is&#8221;.&lt;/p&gt;


	&lt;p&gt;Now I&#8217;ll try to figure out how to generate certificates for users (and the root cert too). The code is a mess, but it works, kinda.&lt;/p&gt;


	&lt;p&gt;&lt;em&gt;&lt;span class=&quot;caps&quot;&gt;UPD&lt;/span&gt;:&lt;/em&gt; wow! I just found http://segment7.net/projects/ruby/QuickCert/, it may save me 90% of the pain with the almost undocumented OpenSSL library!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://blog.startika.com/">
    <author>
      <name>labria</name>
    </author>
    <id>tag:blog.startika.com,2008-02-23:100</id>
    <published>2008-02-23T14:57:00Z</published>
    <updated>2008-02-23T15:15:43Z</updated>
    <link href="http://blog.startika.com/2008/2/23/ssl-client-certificate-login-pt-1" rel="alternate" type="text/html"/>
    <title>SSL client certificate login pt.1</title>
<content type="html">
            &lt;p&gt;Being inspired by Dr.Nic I jumped on the idea of making a plugin to handle Client Certificate login in a rails app. But before writing a string of code i bumped into a problem with my favorite web server — nginx. Then you set up client certificates in apache, you must use the SSLRequire directive to check if the client certificate provided by the user is what you wanted to see from him. This is actually useful when you do some manual user restriction. But in the case of a app behind Apache managing logins, you can just omit this directive, pass the &lt;span class=&quot;caps&quot;&gt;SSL&lt;/span&gt;_CLIENT_S_DN header to your script and you&#8217;re done.&lt;/p&gt;


	&lt;p&gt;But with nxing, it&#8217;s not the case. You have to use the ssl_verify_client directive to check the user&#8217;s cert. If the check passes, nginx happily forward some header to your script and everything is fine. But, if the check fails, nginx generates an error. You have the option to handle that error (actually, redirect the user somewhere), but it&#8217;s not what I want. The problem is that you can &lt;span class=&quot;caps&quot;&gt;NOT&lt;/span&gt; redirect the user to some page in the same domain while still using https, because the certificate will be checked again and the user will find himself in an infinite loop.&lt;/p&gt;


	&lt;p&gt;Maybe I should write a patch for nginx with something like &#8220;ssl_verify_client_enforce&#8221; option to override this behavior, but I&#8217;ll leave this for later. For now I&#8217;ll try implementing a schema where the user gets to a https://domain/login page, and if the certificate check fails I&#8217;ll redirect him to http://domain/login to check his username/password. This way i can make it work no matter what server it happens to use.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://blog.startika.com/">
    <author>
      <name>labria</name>
    </author>
    <id>tag:blog.startika.com,2007-12-06:81</id>
    <published>2007-12-06T10:49:00Z</published>
    <updated>2007-12-06T10:49:41Z</updated>
    <link href="http://blog.startika.com/2007/12/6/generating-a-fake-id-for-a-model" rel="alternate" type="text/html"/>
    <title>Generating a fake id for a model.</title>
<content type="html">
            &lt;p&gt;Sometimes you don&#8217;t want to reveal the real id of the object in the system to the user for some reason. For example, you don&#8217;t want to reveal the number of items in the system, or let the user view all of them by simply changing the id in the address.&lt;/p&gt;


The most obvious and easy way to do it is to generate a fake id for the object and use it instead.
Lets say we have a model named Foo and you want it to have a fake id. Here&#8217;s the code for it:
&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;15&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;19&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;21&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;r&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;cl&quot;&gt;Foo&lt;/span&gt; &amp;lt; &lt;span class=&quot;co&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  before_validation_on_create &lt;span class=&quot;sy&quot;&gt;:generate_fake_id&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;to_param&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    fake_id&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;protected&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;generate_fake_id&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    string = random_string&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;co&quot;&gt;Foo&lt;/span&gt;.find_by_fake_id(string)&lt;tt&gt;
&lt;/tt&gt;      string = random_string&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.fake_id = string&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;random_string&lt;/span&gt;(size = &lt;span class=&quot;i&quot;&gt;8&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;    chars = ((&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;..&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;).to_a + (&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;..&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Z&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;).to_a + (&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;..&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;).to_a)&lt;tt&gt;
&lt;/tt&gt;    (&lt;span class=&quot;i&quot;&gt;1&lt;/span&gt;..size).collect{|a| chars[rand(chars.size)] }.join&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

Now, when you create a Foo with for example &#8220;Foo.create(:name =&amp;gt; &#8216;first foo&#8217;)&#8221;, the model generates a random string of 8 characters and stores it in &lt;em&gt;fake_id&lt;/em&gt;. The fake id is only generated once, on creation, so it&#8217;s not changed later on.

Now, for the helpers. Suppose you have &lt;em&gt;map.resources :foos&lt;/em&gt; in your routes.rb. The helper you user before, &lt;em&gt;foo_path(@foo)&lt;/em&gt; now generates a url with the fake id (foos/Hd45jdg3), because of the &lt;em&gt;to_param&lt;/em&gt; method. All you have  to do, is to change your foos_controller this way:
&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;r&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;cl&quot;&gt;FoosController&lt;/span&gt; &amp;lt; &lt;span class=&quot;co&quot;&gt;ApplicationController&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;show&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;iv&quot;&gt;@foo&lt;/span&gt; = &lt;span class=&quot;co&quot;&gt;Foo&lt;/span&gt;.find_by_fake_id(params[&lt;span class=&quot;sy&quot;&gt;:id&lt;/span&gt;])&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

The uniqueness of the &lt;em&gt;fake_id&lt;/em&gt; is guarantied by the Foo.find_by_fake_id call in the &lt;em&gt;generate_fake_id&lt;/em&gt; method. Yes, it does add an extra query to the database, but it&#8217;s not really impaction performance much unless you are generating a lot of objects all of the time.

You can change the way the fake id looks like by modifying the array used in &lt;em&gt;random_string&lt;/em&gt;. For example if you want to eliminate symbols that look much alike you can have it this way:
&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;random_string&lt;/span&gt;(size = &lt;span class=&quot;i&quot;&gt;8&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;   chars = ((&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;..&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;).to_a + (&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;..&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Z&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;).to_a + (&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;..&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;).to_a) - &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;%w(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;i o 0 1 l O&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;   (&lt;span class=&quot;i&quot;&gt;1&lt;/span&gt;..size).collect{|a| chars[rand(chars.size)] }.join&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

And also: don&#8217;t forget to add the &lt;em&gt;fake_id&lt;/em&gt; field to the table in the database.
          </content>  </entry>
  <entry xml:base="http://blog.startika.com/">
    <author>
      <name>labria</name>
    </author>
    <id>tag:blog.startika.com,2007-12-06:79</id>
    <published>2007-12-06T03:17:00Z</published>
    <updated>2007-12-06T04:06:19Z</updated>
    <link href="http://blog.startika.com/2007/12/6/moving-to-2-0-glitches" rel="alternate" type="text/html"/>
    <title>Moving to 2.0 glitches: RSS</title>
<content type="html">
            While moving a project to Rails 2.0RC I bumped into the fact that old-style RSS generation didn't work anymore. The code I was using before was:
&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;rss&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    render  &lt;span class=&quot;sy&quot;&gt;:layout&lt;/span&gt; =&amp;gt;  &lt;span class=&quot;pc&quot;&gt;false&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

And the template was named rss.rxml

What it became after some googling and trial-and-failure:
&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;index&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    request.format = &lt;span class=&quot;sy&quot;&gt;:rss&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    respond_to &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt; |format|&lt;tt&gt;
&lt;/tt&gt;      format.rss  { render &lt;span class=&quot;sy&quot;&gt;:layout&lt;/span&gt; =&amp;gt; &lt;span class=&quot;pc&quot;&gt;false&lt;/span&gt; }&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

And the template (the same one, actually) is now named index.rss.builder.
The weird thing was that I tried to use :xml instead of :rss, and it didn't work. Anyway, it's working fine now.
          </content>  </entry>
  <entry xml:base="http://blog.startika.com/">
    <author>
      <name>labria</name>
    </author>
    <id>tag:blog.startika.com,2007-12-05:77</id>
    <published>2007-12-05T15:12:00Z</published>
    <updated>2007-12-05T15:16:41Z</updated>
    <link href="http://blog.startika.com/2007/12/5/welcome" rel="alternate" type="text/html"/>
    <title>Welcome!</title>
<content type="html">
            This is kinda YARW. Sounds much like YARV, but with the sole exception that W stands for weblog.
Ruby blogs are numerous, but I think one more won't hurt. Maybe one day I'll have a revelation and post something really useful here. But not today, I'm too tired installing Mephisto and fighting it's multisite mod.
          </content>  </entry>
</feed>
