<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.3" -->
<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/"
	>

<channel>
	<title>corprewland &#187; welcome screen</title>
	<link>http://www.corprew.org</link>
	<description>(dis)information organization</description>
	<pubDate>Sat, 03 Jan 2009 04:01:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
	<language>en</language>
			<item>
		<title>ruby/rails and the invited beta</title>
		<link>http://www.corprew.org/blog/2008/04/16/rubyrails-and-the-invited-beta/</link>
		<comments>http://www.corprew.org/blog/2008/04/16/rubyrails-and-the-invited-beta/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 06:31:59 +0000</pubDate>
		<dc:creator>corprew</dc:creator>
		
		<category><![CDATA[computer programming]]></category>

		<category><![CDATA[account]]></category>

		<category><![CDATA[acts_as_authenticated]]></category>

		<category><![CDATA[facebook]]></category>

		<category><![CDATA[guid]]></category>

		<category><![CDATA[invite]]></category>

		<category><![CDATA[invite functionality]]></category>

		<category><![CDATA[private beta]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[rails]]></category>

		<category><![CDATA[ror]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[slicehost]]></category>

		<category><![CDATA[tristero]]></category>

		<category><![CDATA[welcome screen]]></category>

		<guid isPermaLink="false">http://www.corprew.org/blog/2008/04/16/rubyrails-and-the-invited-beta/</guid>
		<description><![CDATA[I&#8217;ve been working on a website in RoR for the last while, and it&#8217;s about to go live in the private beta sort of way that seems to be so popular these days.  It&#8217;s handy that way, because that way I can set up the site at slicehost or similar and not have to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a website in RoR for the last while, and it&#8217;s about to go live in the private beta sort of way that seems to be so popular these days.  It&#8217;s handy that way, because that way I can set up the site at slicehost or similar and not have to worry (too much) about my server slowing from getting overloaded.  This same site&#8217;s next incarnation is going to be facebook related, so that should overwhelm any sense of moderation (if I&#8217;m lucky.)</p>
<p>So, the key method of invitation to a private beta is that you mail someone a code allowing them access to the system, for these purposes, let&#8217;s just assume that the code is some reasonably long unique string (in my code, it&#8217;s actually a <code>uuid</code>.)  So, set up a migration something like this to manage them:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
    create_table <span style="color:#ff3333; font-weight:bold;">:invites</span> <span style="color:#9966CC; font-weight:bold;">do</span> |t|
<span style="color:#008000; font-style:italic;"># deleted stuff</span>
      t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#ff3333; font-weight:bold;">:guid</span>
      t.<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#ff3333; font-weight:bold;">:used_yet</span>
<span style="color:#008000; font-style:italic;"># deleted stuff</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><code>used_yet</code> isn&#8217;t a boolean for reasons that are too laborious to go into here, but reflect some functionality in the code that I&#8217;m not going to display.  Assuming that you&#8217;re using acts_as_authentication and are redirecting anyone who tries to access your app to the default welcome page according to the usual methods, set up something like this in your routes.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">  map.<span style="color:#9900CC;">root</span> <span style="color:#ff3333; font-weight:bold;">:controller</span> =&gt; <span style="color:#996600;">&quot;welcome&quot;</span></pre></div></div>

<p>This is probably the case in like half the rails apps out there.  Have the <code>index</code> method of the welcome controller put up a form with a field like:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;">#let's see if the formatter can handle rails erb without exploding.</span>
&lt; % form_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'welcome/checkinvite'</span>, <span style="color:#ff3333; font-weight:bold;">:method</span>=&gt;:get<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> -%&gt;
  &lt; %= text_field_tag <span style="color:#996600;">'invite'</span> %&gt;
  &lt; %= submit_tag <span style="color:#996600;">'begin'</span> %&gt;
&lt; % <span style="color:#9966CC; font-weight:bold;">end</span> -%&gt;</pre></div></div>

<p>This lets the user enter their invite in more or less the normal method.  Now in your &#8216;welcome&#8217; controller, you&#8217;ll need a &#8216;checkinvite&#8217; method that looks something like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"> <span style="color:#9966CC; font-weight:bold;">def</span> checkinvite
    <span style="color:#0066ff; font-weight:bold;">@inviteguid</span> = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:invite</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#0066ff; font-weight:bold;">@invite</span> = Invite.<span style="color:#9900CC;">find_by_guid</span><span style="color:#006600; font-weight:bold;">&#40;</span>@inviteguid<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>@invite == <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Your invite was invalid&quot;</span>
      redirect_to root_url
      <span style="color:#0000FF; font-weight:bold;">return</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>@invite.<span style="color:#9900CC;">used_yet</span> == <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Your invite had already been used&quot;</span>
      redirect_to root_url
      <span style="color:#0000FF; font-weight:bold;">return</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>After this, you&#8217;ll need to have some code in your HTML page that links you to the account/signup functionality of acts_as_authenticated.  I&#8217;m not going to include that because I&#8217;m too lazy to fish it out of my app functionality, but you can do that pretty much with a link_to using <code>:invite=%gt;@invite_guid</code> as an extra parameter.</p>
<p>You need to put the same invite detection code in account/signup, and then when you&#8217;ve created the account, set <code>invite.used_yet = 1</code>.  This is about as simple as a method that I can think of for doing the private beta functionality that seems to be so much in vogue these days.  Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.corprew.org/blog/2008/04/16/rubyrails-and-the-invited-beta/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
