Created
May 19, 2010 21:32
-
-
Save adelevie/406865 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
#... | |
def feature(name) | |
if Feature.exists?(:name => name) | |
Feature.find_by_name(name).deployed? | |
else | |
Feature.create(:name => name, :deployed => false) | |
false | |
end | |
end | |
#... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FeaturesController < ApplicationController | |
before_filter :require_admin #this could be anything, just make sure only an admin can access this controller | |
def index | |
@features = Feature.find(:all) | |
#use whatever layout you want. I decided to stick all of this in the admin section of my application | |
render :layout => 'admin' | |
end | |
def update | |
if params[:feature] | |
Feature.update(params[:id], params[:feature]) | |
end | |
#I modified routes.rb to make this url work | |
redirect_to '/admin/featues/index' #or redirect to an error page | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Features</h1> | |
<table border="1"> | |
<tr> | |
<td>name</td> | |
<td></td> | |
</tr> | |
<% @features.each do |feature| %> | |
<tr> | |
<% form_for feature, :url => '/admin/features/update' do |f| %> | |
<input type="hidden" name="id" value=<%= feature.id %> /> | |
<td><%= feature.name %></td> | |
<% if feature.deployed %> | |
<input type="hidden" name="feature[deployed]" value="false" /> | |
<td><input type="submit" value="rollback" /></td> | |
<% else %> | |
<input type="hidden" name="feature[deployed]" value="true" /> | |
<td><input type="submit" value="deploy" /></td> | |
<% end %> | |
<% end %> | |
</tr> | |
<% end %> | |
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index | |
@products = Product.find(:all) | |
if feature("Everything Must Go") | |
#take 90% off everything! | |
@products.each {|product| product.price = product.price*(0.10)} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% if feature("Time Machine") %> | |
<%= render :partial => 'time_machine' %> | |
<% else %> | |
<p>Our time machine is still in development. Check back soon!</p> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment