Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Add Basic Auth to Rails Controller
- #
- # AUTHOR : Tomoya Hirano
- # DATE : 2009-08-04
- #
- # Cf: Head First Rails p.143
- #
- class QuestionsController < ApplicationController
- before_filter :check_logged_in, :only => [:edit, :update]
- def new
- @q = Question.new
- end
- def create
- @q = Question.new params[:q]
- @q.save
- redirect_to "/questions/#{@q.id}"
- end
- def edit
- @q = Question.find(params[:id])
- end
- def update
- @q = Question.find(params[:id])
- @q.update_attribtes(params[:q])
- redirect_to "/questions/#{@q.id}"
- end
- def show
- @q = Question.find(params[:id])
- end
- def index
- @qs = Question.all
- end
- def destroy
- @q = Question.find(params[:id])
- @q.destroy
- redirect_to "/questions/"
- end
- private
- def check_logged_in
- authenticate_or_request_with_http_basic("Questions") do |username, password|
- username == 'admin' && password == 'admin'
- end
- end
- end
Add Comment
Please, Sign In to add comment