我应该如何构建我的 Rails 3 应用程序以在 Heroku 上进行 Beta 测试?

发布于 2024-10-30 02:21:48 字数 473 浏览 0 评论 0原文

我正在深入研究 Ruby on Rails,并尝试从头开始构建一个基本的 Web 应用程序来学习该平台和相关技术。到目前为止,我只在本地计算机上运行它,但我想将其部署到免费的 Heroku 帐户,以开始熟悉在实时服务器上部署和测试应用程序。显然,我不希望该应用程序向任何人公开,因为它还远未完成,而且还没有准备好供公众使用。我想我想做的事情类似于封闭测试,但由于这是我第一次尝试,我不知道应该朝哪个方向来完成此任务。

我启用了用户帐户和身份验证。我可以做的一件事是扔出一个静态登录页面,显示该网站正在建设中,并且由于我有一个登录 URL,我可以将 before_filter 添加到我的所有控制器,以便只有我可以登录并访问该网站,但这感觉很黑客,并且不允许我正确测试应该公开的页面(因为它们是私有的)。我在这里至少有正确的想法吗?还是我的策略偏离了?

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伴我心暖 2024-11-06 02:21:48

首先,如果您使用 heroku 生成的子域之一(例如“pretty-flower-99.heroku.com”),那么不太可能有人会偶然发现您的应用程序。或者您可以自己指定一个非常模糊的域/子域。

之后,最简单的事情可能是将 http 基本身份验证添加到您的应用程序控制器并在 before_filter 中运行它。像这样的东西:

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

这将为您提供一个基于旧式浏览器的用户名和密码对话框。如果您想在任何地方跳过此操作,只需在该控制器中运行skip_before_filter即可。

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.

零度℉ 2024-11-06 02:21:48

如果在某个时候您希望允许多个用户进行 Beta 测试而不必强制执行 http 基本身份验证,则可以在 User 模型上设置状态属性。这样,您仍然可以让人们注册,然后通过 Heroku 控制台或您自己的管理页面批准他们。

新的 Rails Enums 功能使它变得非常简单。

创建迁移:

rails g migration AddStatusToUsers users:integer

包括枚举状态和之前的操作:

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

#live?方法是通过枚举免费提供给您的。
http://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文