summaryrefslogtreecommitdiff
path: root/app/controllers/tutorials_controller.rb
diff options
context:
space:
mode:
authormo k <mo@mokhan.ca>2012-09-06 07:59:40 -0600
committermo k <mo@mokhan.ca>2012-09-06 07:59:40 -0600
commit0844c47d1104e874bab6d2a64d17573b25e2052d (patch)
tree7c16711eb2b1bfff9e93d6679eb0d539692f9793 /app/controllers/tutorials_controller.rb
parent694b2b8dc71f171bf08b6d549381c558d66b349f (diff)
associate a tutorial with the user signed in.
Diffstat (limited to 'app/controllers/tutorials_controller.rb')
-rw-r--r--app/controllers/tutorials_controller.rb51
1 files changed, 50 insertions, 1 deletions
diff --git a/app/controllers/tutorials_controller.rb b/app/controllers/tutorials_controller.rb
index a4f8b9c0..2ebab43f 100644
--- a/app/controllers/tutorials_controller.rb
+++ b/app/controllers/tutorials_controller.rb
@@ -1,3 +1,52 @@
-class TutorialsController < InheritedResources::Base
+class TutorialsController < ApplicationController
before_filter :authenticate_user!, :except => [:show, :index]
+
+ def index
+ @tutorials = Tutorial.all
+ end
+
+ def show
+ @tutorial = Tutorial.find(params[:id])
+ end
+
+ def new
+ @tutorial = Tutorial.new
+ end
+
+ def edit
+ @tutorial = current_user.tutorials.find(params[:id])
+ end
+
+ def create
+ @tutorial = current_user.tutorials.create(params[:tutorial])
+ respond_to do |format|
+ if @tutorial.save
+ format.html { redirect_to( '/tutorials/' ) }
+ else
+ flash[:error] = @tutorial.errors.full_messages
+ format.html { render :action => "new" }
+ end
+ end
+ end
+
+ def update
+ @tutorial = current_user.tutorials.find(params[:id])
+
+ respond_to do |format|
+ if @tutorial.update_attributes(params[:tutorial])
+ format.html { redirect_to(@tutorial, :notice => 'tutorial was successfully updated.') }
+ else
+ format.html { render :action => "edit" }
+ end
+ end
+ end
+
+ def destroy
+ @tutorial = current_user.tutorials.find(params[:id])
+ @tutorial.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(tutorials_url) }
+ end
+ end
end