Header image

corprewland

(dis)information organization

  • Home

Subscribe to feed

‹ loltelegraph  •  Yuri’s Night Bay Area 2008 ›

ruby/rails and the invited beta

2008 April 16 in computer programming by corprew | No comments

I’ve been working on a website in RoR for the last while, and it’s about to go live in the private beta sort of way that seems to be so popular these days. It’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’s next incarnation is going to be facebook related, so that should overwhelm any sense of moderation (if I’m lucky.)

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’s just assume that the code is some reasonably long unique string (in my code, it’s actually a uuid.) So, set up a migration something like this to manage them:

  def self.up
    create_table :invites do |t|
# deleted stuff
      t.string :guid
      t.integer :used_yet
# deleted stuff
    end
  end

used_yet isn’t a boolean for reasons that are too laborious to go into here, but reflect some functionality in the code that I’m not going to display. Assuming that you’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:

  map.root :controller => "welcome"

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

#let's see if the formatter can handle rails erb without exploding.
< % form_tag('welcome/checkinvite', :method=>:get) do -%>
  < %= text_field_tag 'invite' %>
  < %= submit_tag 'begin' %>
< % end -%>

This lets the user enter their invite in more or less the normal method. Now in your ‘welcome’ controller, you’ll need a ‘checkinvite’ method that looks something like the following:

 def checkinvite
    @inviteguid = params[:invite]
    @invite = Invite.find_by_guid(@inviteguid)
    if(@invite == nil)
      flash[:notice] = "Your invite was invalid"
      redirect_to root_url
      return
    end
    if(@invite.used_yet == 1)
      flash[:notice] = "Your invite had already been used"
      redirect_to root_url
      return
    end
  end

After this, you’ll need to have some code in your HTML page that links you to the account/signup functionality of acts_as_authenticated. I’m not going to include that because I’m too lazy to fish it out of my app functionality, but you can do that pretty much with a link_to using :invite=%gt;@invite_guid as an extra parameter.

You need to put the same invite detection code in account/signup, and then when you’ve created the account, set invite.used_yet = 1. 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.

Tags: account, acts_as_authenticated, facebook, guid, invite, invite functionality, private beta, programming, rails, ror, ruby, slicehost, tristero, welcome screen

No comments

Comments feed for this article

Trackback link: http://www.corprew.org/blog/2008/04/16/rubyrails-and-the-invited-beta/trackback/

Reply

Click here to cancel your reply

Tags

43 2008 aperture aperture science apple asist asistpnw bees bloom busses celiaq drupal enrichment center fail glados humor ignition northwest infocamp iphone iphone dev i say potato ischool jackalope java macbook pro macosx metro php plu poetry portal programming rails rangering ruby seattle text-to-speech the uw tom dobrowolsky total eclipse west seattle work youngstown you say potato

Subscribe to feed

Powered by WordPress and free online casino, Online Baccarat, online slot machines