OSDN Git Service

t#30200:update i18n devise
[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, :new, :create, :edit, :update]
4   before_filter :authenticate_author, :only => [:index, :show, :edit, :update]
5   before_filter :authenticate_admin!, :only => [:list, :browse]
6
7   def index
8     @page = Author.page params[:page]
9     @page_size = Author.page_size params[:page_size]
10     @authors = Author.list(@page, @page_size)
11
12     respond_to do |format|
13       format.html # index.html.erb
14       format.json { render :json => @authors.to_json(Author.list_json_opt) }
15     end
16   end
17
18   def show
19     @au = Author.show(params[:id], @author)
20
21     respond_to do |format|
22       format.html
23       format.json { render :json => @au.to_json(Author.show_json_opt) }
24     end
25   end
26
27   def count
28     @au = {:count => Author.visible_count}
29     respond_to do |format|
30       format.json { render json: @au.to_json }
31     end
32   end
33   
34   def list
35     @authors = Author.all
36
37     respond_to do |format|
38       format.html { render layout: 'system' }
39     end
40   end
41
42   def browse
43     @au = Author.find(params[:id])
44
45     respond_to do |format|
46       format.html { render layout: 'system' }
47     end
48   end
49   
50   def new
51     @au = Author.new
52     @au.supply_default 
53
54     respond_to do |format|
55       format.html # new.html.erb
56       format.js
57       format.json { render json: @au.to_json(Author.show_json_opt) }
58     end
59   end
60
61   def edit
62     @au = Author.edit(params[:id], @author)
63   end
64
65   def create
66     @au = Author.new()
67     @au.supply_default 
68     @au.attributes = params[:author]
69     @au.overwrite @user.id
70     respond_to do |format|
71       if @au.save
72         format.html { redirect_to @au, notice: 'Author was successfully created.' }
73         format.json { render json: @au.to_json(Author.show_json_opt), status: :created, location: @artist }
74       else
75         format.html { render action: "new" }
76         format.json { render json: @au.errors, status: :unprocessable_entity }
77       end
78     end
79   end
80
81   def update
82     @au = Author.edit(params[:id], @author)
83     @au.attributes = params[:author]
84     @au.overwrite @user.id
85
86     respond_to do |format|
87       if @au.save
88         format.html { redirect_to @au, notice: 'Author was successfully updated.' }
89         format.json { head :ok }
90       else
91         format.html { render action: "edit" }
92         format.json { render json: @au.errors, status: :unprocessable_entity }
93       end
94     end
95   end
96 end