Created
October 8, 2011 17:18
-
-
Save anonymous/1272577 to your computer and use it in GitHub Desktop.
Links Controller
This file contains hidden or 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 | |
| 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 | |
| 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 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment