Created
October 9, 2011 22:10
-
-
Save anonymous/1274274 to your computer and use it in GitHub Desktop.
Controller
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 LinksController < ApplicationController | |
before_filter :authenticate, :only => [:edit, :update, :destroy, :admin] | |
def up | |
@link = Link.find(params[:id]) | |
@link.update_attribute :points, @link.points + 1 | |
redirect_to :action => :index | |
end | |
def down | |
@link = Link.find(params[:id]) | |
@link.update_attribute :points, @link.points - 1 | |
redirect_to :action => :index | |
end | |
def index | |
@links = Link.all(:order => 'points DESC') | |
end | |
def show | |
@link = Link.find(params[:id]) | |
redirect_to @link.url | |
end | |
def new | |
@link = Link.new | |
end | |
def create | |
@link = Link.new(params[:link]) | |
if @link.save | |
flash[:notice] = "The link was successfully added" | |
redirect_to :action => :index | |
else | |
redirect_to :action => :new | |
end | |
end | |
def edit | |
@link = Link.find(params[:id]) | |
end | |
def update | |
@link = Link.find(params[:id]) | |
if | |
@link.update_attributes(params[:link]) | |
redirect_to :action => :index | |
else | |
redirect_to :action => :edit | |
end | |
end | |
def destroy | |
@link = Link.find(params[:id]) | |
@link.destroy | |
redirect_to :action => :index | |
end | |
def admin | |
@links = Link.all | |
end | |
protected | |
def authenticate | |
authenticate_or_request_with_http_basic do |user, password| | |
user == "x5d548ew6" && password == "0xd456s64" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment