OSDN Git Service

create demander
[pettanr/pettanr.git] / app / controllers / authors_controller.rb
1 class AuthorsController < ApplicationController
2   layout 'test' if MagicNumber['test_layout']
3   before_filter :authenticate_user!, :only => [:index, :show, :edit, :update]
4   before_filter :authenticate_admin!, :only => [:list, :browse]
5
6   def index
7     @page = Author.page params[:page]
8     @page_size = Author.page_size params[:page_size]
9     @authors = Author.list(@page, @page_size)
10
11     respond_to do |format|
12       format.html # index.html.erb
13       format.json { render :json => @authors.to_json(Author.list_json_opt) }
14     end
15   end
16
17   def show
18     @au = Author.show(params[:id], @author)
19
20     respond_to do |format|
21       format.html
22       format.json { render :json => @au.to_json(Author.show_json_opt) }
23     end
24   end
25
26   def count
27     @au = {:count => Author.visible_count}
28     respond_to do |format|
29       format.json { render json: @au.to_json }
30     end
31   end
32   
33   def list
34     @authors = Author.all
35
36     respond_to do |format|
37       format.html { render layout: 'system' }
38     end
39   end
40
41   def browse
42     @author = Author.find(params[:id])
43
44     respond_to do |format|
45       format.html { render layout: 'system' }
46     end
47   end
48   
49   def edit
50     @au = Author.edit(params[:id], @author)
51   end
52
53   def update
54     @au = Author.edit(params[:id], @author)
55     @au.attributes = params[:author]
56     @au.overwrite
57
58     respond_to do |format|
59       if @au.save
60         format.html { redirect_to @au, notice: 'Author was successfully updated.' }
61         format.json { head :ok }
62       else
63         format.html { render action: "edit" }
64         format.json { render json: @au.errors, status: :unprocessable_entity }
65       end
66     end
67   end
68 end