Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment