Created
October 8, 2011 19:06
-
-
Save anonymous/1272712 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] | |
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 | |
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 | |
protected | |
def authenticate | |
authenticate_or_request_with_http_basic do |user, password| | |
user == "x4556d4s" && password == "fd55sas64x" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment