Guest User

Untitled

a guest
Jul 28th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. class AdsController < ApplicationController
  2. before_filter :check_logged_in, only: [:destroy, :edit, :update]
  3.  
  4. def create
  5. @ad = Ad.new(params[:ad])
  6. @ad.save
  7.  
  8. redirect_to "/ads/#{@ad.id}"
  9. end
  10.  
  11. def destroy
  12. @ad = Ad.find(params[:id])
  13. @ad.destroy
  14. redirect_to "/ads/"
  15. end
  16.  
  17. def edit
  18. @ad = Ad.find(params[:id])
  19. end
  20.  
  21. def index
  22. @ads = Ad.find(:all)
  23. end
  24.  
  25. def new
  26. @ad = Ad.new
  27. end
  28.  
  29. def show
  30. @ad = Ad.find(params[:id])
  31. end
  32.  
  33. def update
  34. @ad = Ad.find(params[:id])
  35. @ad.update_attributes(params[:ad])
  36. redirect_to "/ads/#{@ad.id}"
  37. end
  38.  
  39. private
  40. def check_logged_in
  41. authenticate_or_request_with_http_basic("Ads") do |username, password|
  42. username == "admin" && password == "lolwat"
  43. end
  44. end
  45. end
Add Comment
Please, Sign In to add comment