Guest User

Untitled

a guest
Jan 13th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. class LinksController < ApplicationController
  2.  
  3. before_filter :authenticate, :only => [:edit, :update, :destroy]
  4.  
  5. def up
  6. @link = Link.find(params[:id])
  7. @link.update_attribute :points, @link.points + 1
  8. redirect_to :action => :index
  9. end
  10.  
  11. def down
  12. @link = Link.find(params[:id])
  13. @link.update_attribute :points, @link.points - 1
  14. redirect_to :action => :index
  15. end
  16.  
  17. def index
  18. @links = Link.all
  19. end
  20.  
  21. def show
  22. @link = Link.find(params[:id])
  23. redirect_to @link.url
  24. end
  25.  
  26. def new
  27. @link = Link.new
  28. end
  29.  
  30. def create
  31. @link = Link.new(params[:link])
  32. if @link.save
  33. flash[:notice] = "The link was successfully added"
  34. redirect_to :action => :index
  35. else
  36. redirect_to :action => :new
  37. end
  38. end
  39.  
  40. def edit
  41. @link = Link.find(params[:id])
  42. end
  43.  
  44. def update
  45. @link = Link.find(params[:id])
  46. if
  47. @link.update_attributes(params[:link])
  48. redirect_to :action => :index
  49. else
  50. redirect_to :action => :edit
  51. end
  52. end
  53.  
  54. def destroy
  55. @link = Link.find(params[:id])
  56. @link.destroy
  57. redirect_to :action => :index
  58. end
  59.  
  60. protected
  61. def authenticate
  62. authenticate_or_request_with_http_basic do |user, password|
  63. user == "x4556d4s" && password == "fd55sas64x"
  64. end
  65. end
  66. end
Add Comment
Please, Sign In to add comment