Guest User

Untitled

a guest
Jul 13th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. class TutorialsController < ApplicationController
  2. # GET /tutorials
  3. # GET /tutorials.xml
  4. before_filter :authenticate
  5.  
  6. def index
  7. @tutorials = Tutorial.all
  8.  
  9. respond_to do |format|
  10. format.html # index.html.erb
  11. format.xml { render :xml => @tutorials }
  12. end
  13. end
  14.  
  15. # GET /tutorials/1
  16. # GET /tutorials/1.xml
  17. def show
  18. @tutorial = Tutorial.find_by_name(params[:id])
  19.  
  20. respond_to do |format|
  21. format.html # show.html.erb
  22. format.xml { render :xml => @tutorial }
  23. end
  24. end
  25.  
  26. # GET /tutorials/new
  27. # GET /tutorials/new.xml
  28. def new
  29. @tutorial = Tutorial.new
  30.  
  31. respond_to do |format|
  32. format.html # new.html.erb
  33. format.xml { render :xml => @tutorial }
  34. end
  35. end
  36.  
  37. # GET /tutorials/1/edit
  38. def edit
  39. @tutorial = Tutorial.find_by_name(params[:id])
  40. end
  41.  
  42. # POST /tutorials
  43. # POST /tutorials.xml
  44. def create
  45. @tutorial = Tutorial.new(params[:tutorial])
  46.  
  47. respond_to do |format|
  48. if @tutorial.save
  49. flash[:notice] = 'Tutorial was successfully created.'
  50. format.html { redirect_to(@tutorial) }
  51. format.xml { render :xml => @tutorial, :status => :created, :location => @tutorial }
  52. else
  53. format.html { render :action => "new" }
  54. format.xml { render :xml => @tutorial.errors, :status => :unprocessable_entity }
  55. end
  56. end
  57. end
  58.  
  59. # PUT /tutorials/1
  60. # PUT /tutorials/1.xml
  61. def update
  62. @tutorial = Tutorial.find_by_name(params[:id])
  63.  
  64. respond_to do |format|
  65. if @tutorial.update_attributes(params[:tutorial])
  66. flash[:notice] = 'Tutorial was successfully updated.'
  67. format.html { redirect_to(@tutorial) }
  68. format.xml { head :ok }
  69. else
  70. format.html { render :action => "edit" }
  71. format.xml { render :xml => @tutorial.errors, :status => :unprocessable_entity }
  72. end
  73. end
  74. end
  75.  
  76. # DELETE /tutorials/1
  77. # DELETE /tutorials/1.xml
  78. def destroy
  79. @tutorial = Tutorial.find_by_name(params[:id])
  80. @tutorial.destroy
  81.  
  82. respond_to do |format|
  83. format.html { redirect_to(tutorials_url) }
  84. format.xml { head :ok }
  85. end
  86.  
  87. protected
  88.  
  89. def authenticate
  90. authenticate_or_request_with_http_basic do |username, password|
  91. username == "admin" && password == "m6219123"
  92. <% end %>
  93. end
Add Comment
Please, Sign In to add comment