Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. class ProxiesController < ApplicationController
  2. before_action :set_proxy, only: [:show, :edit, :update, :destroy]
  3. before_action :authenticate_user!
  4.  
  5. def index
  6. @proxies = policy_scope(Proxy)
  7. #@proxies = current_user.proxies
  8. end
  9.  
  10. def show
  11. authorize @proxy
  12. end
  13.  
  14. def new
  15. @proxy = Proxy.new(user: current_user)
  16. authorize @proxy
  17. end
  18.  
  19. def edit
  20. authorize @proxy
  21. end
  22.  
  23. def create
  24. @proxy = current_user.proxies.build(proxy_params)
  25. authorize @proxy
  26.  
  27. respond_to do |format|
  28. if @proxy.save
  29. format.html { redirect_to @proxy, notice: 'Proxy was successfully created.' }
  30. format.json { render :show, status: :created, location: @proxy }
  31. else
  32. format.html { render :new }
  33. format.json { render json: @proxy.errors, status: :unprocessable_entity }
  34. end
  35. end
  36. end
  37.  
  38. def update
  39. authorize @proxy
  40. respond_to do |format|
  41. if @proxy.update(proxy_params)
  42. format.html { redirect_to @proxy, notice: 'Proxy was successfully updated.' }
  43. format.json { render :show, status: :ok, location: @proxy }
  44. else
  45. format.html { render :edit }
  46. format.json { render json: @proxy.errors, status: :unprocessable_entity }
  47. end
  48. end
  49. end
  50.  
  51. def destroy
  52. authorize @proxy
  53. @proxy.destroy
  54. respond_to do |format|
  55. format.html { redirect_to proxies_url, notice: 'Proxy was successfully destroyed.' }
  56. format.json { head :no_content }
  57. end
  58. end
  59.  
  60. private
  61. # Use callbacks to share common setup or constraints between actions.
  62. def set_proxy
  63. @proxy = Proxy.find(params[:id])
  64. end
  65.  
  66. # Never trust parameters from the scary internet, only allow the white list through.
  67. def proxy_params
  68. params.require(:proxy).permit(:user_id, :ip, :port, :country, :city, :username, :password)
  69. end
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement