OSDN Git Service

t#30169:show, index action create all resource
[pettanr/pettanr.git] / app / controllers / speeches_controller.rb
index b9a3c7b..88a9bcb 100644 (file)
@@ -1,19 +1,28 @@
 class SpeechesController < ApplicationController
   layout 'test' if MagicNumber['test_layout']
   before_filter :authenticate_user!, :only => [:index, :show]
+  before_filter :authenticate_author, :only => [:index, :show]
   before_filter :authenticate_admin!, :only => [:list, :browse]
 
-  # GET /speeches
-  # GET /speeches.json
   def index
-    @speeches = Speech.all
+    @page = Speech.page params[:page]
+    @page_size = Speech.page_size params[:page_size]
+    @speeches = Speech.list(@page, @page_size)
 
     respond_to do |format|
       format.html # index.html.erb
-      format.json { render json: @speeches }
+      format.json { render json: @speeches.to_json(Speech.list_json_opt) }
     end
   end
-
+  
+  def show
+    @speech = Speech.show(params[:id], @author)
+    respond_to do |format|
+      format.html # show.html.erb
+      format.json { render json: @speech.to_json(Speech.show_json_opt) }
+    end
+  end
+  
   def list
     @speeches = Speech.all
 
@@ -22,4 +31,14 @@ class SpeechesController < ApplicationController
       format.json { render json: @speeches }
     end
   end
+
+  def browse
+    @speech = Speech.find(params[:id])
+
+    respond_to do |format|
+      format.html { render layout: 'system' }
+      format.json { render json: @speech }
+    end
+  end
+
 end