OSDN Git Service

list browser created
[pettanr/pettanr.git] / app / controllers / comics_controller.rb
index 7200ab0..8a5169c 100644 (file)
@@ -1,5 +1,6 @@
 class ComicsController < ApplicationController
-  before_filter :authenticate_author!, :except => [:index, :show, :play]
+  before_filter :authenticate_author!, :only => [:top, :index, :show, :play, :create, :update, :destroy]
+  before_filter :authenticate_admin!, :only => [:list, :browse]
 
   private
   
@@ -10,12 +11,19 @@ class ComicsController < ApplicationController
   public
   
   def top
+    @comics = Comic.all
+
+    respond_to do |format|
+      format.html # index.html.erb
+    end
   end
   
   # GET /comics
   # GET /comics.json
   def index
-    @comics = Comic.all
+    @comics = Comic.find(:all, 
+      :include => :author, :conditions => ['visible = 1'], :order => 'updated_at desc', :limit => 20
+    )
 
     respond_to do |format|
       format.html # index.html.erb
@@ -29,24 +37,24 @@ class ComicsController < ApplicationController
     @comic = Comic.find(params[:id])
 
     respond_to do |format|
-      format.html # show.html.erb
+#      format.html # show.html.erb
       format.json { render json: @comic }
     end
   end
 
   def play
-    @comic = Comic.find(params[:id], include: {:panels => [:panel_pictures => :resource_picture, :balloons => :speaches]}, order: 'panels.t')
+    @comic = Comic.find(params[:id], include: [:author, {:panels => [:panel_pictures => :resource_picture, :balloons => :speaches]}], order: 'panels.t')
 
     respond_to do |format|
       format.html # index.html.erb
       format.json {
         render :json => @comic.to_json(
-          :include => {
+          :include => [:author, {
             :panels => {:include => {
               :panel_pictures => {:include => :resource_picture}, 
               :balloons => {:include => :speaches}
             }}
-          }
+          }]
         )
       }
       format.jsonp {
@@ -62,6 +70,24 @@ class ComicsController < ApplicationController
     end
   end
   
+  def list
+    @comics = Comic.all
+
+    respond_to do |format|
+      format.html { render layout: 'system' }# index.html.erb
+      format.json { render json: @comics }
+    end
+  end
+
+  def browse
+    @comic = Comic.find(params[:id])
+
+    respond_to do |format|
+      format.html { render layout: 'system' } # show.html.erb
+      format.json { render json: @comic }
+    end
+  end
+  
   # GET /comics/new
   # GET /comics/new.json
   def new