Ever want to use your webapp while it's still a closed alpha? Me too.
My solution is to only let people who have a passphrase create an account. Thanks to a suggestion by Rob125 in freenode's #RubyOnRails channel, I found the easiest way to do this was to modify 3 files.
- Create a constant in your Rails::Initializer.run do |config| method (config/environment.rb):
Note you'll need to restart your app server for this to take effect.MY_SECRET_PHRASE = "econometrics is fun!"
- Add a textbox to your signup form (app/views/users/new.html.erb if using restful_authentication):
<p>What's the passphrase?<br />
<%= text_field_tag 'passphrase' %></p> - Compare the constant to your parameter in the create method of the Users controller (app/controllers/users_controller.rb):
@secret = params[:passphrase]
if @secret == MY_SECRET_PHRASE then
#all that successful stuff...
else
#all that flash[:error] stuff...
And there you have it. Easy to only allow access to a few a people while testing and easy to get rid of when it's time to truly go live. There is a drawback in the form of overhead that comes with an initializer, but certainly it's a fair tradeoff for a quick solution to a temporary problem.
No comments:
Post a Comment