Building beta sites can become cluttered with <% if else %> statements, but Rails before_actions make it easy to lock down sections of web applications without flow control in views.

class PagesController < ApplicationController
 
  before_action :redirect_unless_live, only: [:tickets, :shows, :press]
 
  def press; end
  def shows; end
  def tickets; end
 
  home
    # ready for production
  end
 
  private
 
  def redirect_unless_live
    return unless current_user.beta_access?
    redirect_to root_path
  end
 
end

Leave a Reply

Your email address will not be published. Required fields are marked *