简体   繁体   中英

How should I structure my Rails 3 app for beta testing on Heroku?

I'm diving into Ruby on Rails and I'm trying to build a basic web app from scratch to learn the platform and associated technologies. So far, I only have it running on my local machine, but I'd like to get it deployed to a free Heroku account to start getting familiar with deployment and testing the app on a live server. Obviously I don't want the app to be publicly available to anyone since it's far from finished and simply not ready for public use. I suppose what I'm trying to do is similar to a closed beta test, but since this is my first go around, I have no idea which direction I should go to accomplish this.

I have user accounts and authentication enabled. One thing I could do is toss up a static landing page that shows the site is under construction, and since I have a login URL, I could just add before_filter 's to all my controllers so that only I can login and access the site, but that feels hackish and doesn't let me properly test the pages that should be public (because they're private). Do I at least have the right idea here? Or is my strategy way off?

Does Heroku have any built in support for keeping sites private until they're ready to go public?

Any direction would help, thank you so much!

First, if you're using one of heroku's generated subdomains (like "pretty-flower-99.heroku.com") it's not likely anyone will stumble upon your app. Or you can specify a very obscure domain/subdomain yourself.

After that, the easiest thing to do is probably add http basic authentication to your application controller and run it in a before_filter. Something like this:

class ApplicationController < ActionController::Base
before_filter :beta_login_required

protected

    def beta_login_required
      authenticate_or_request_with_http_basic do |username, password|
        username == "foo" && password == "bar"
      end
    end

This will give you an old-school browser-based username and password dialog. If there are any places you want to skip this, just run a skip_before_filter in that controller.

If at some point you want to allow multiple users to beta test without having to enforce http basic auth, you can set a status attribute on the User model. This way you can still have people sign up, then through Heroku console or your own admin page approve them.

The new Rails Enums feature makes it really easy.

Create a migration:

rails g migration AddStatusToUsers users:integer

Include the enum status and a before action:

class User
  enum status: [:pending, :live]
end

class ApplicationController
  before_action :must_be_approved_beta_user

  def must_be_approved_beta_user
    redirect_to home_path unless current_user.live?
  end
end

The #live? method is given to you free with Enums. http://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM