OSDN Git Service

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