OSDN Git Service

t30329#:i18n flash message
[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         flash[:notice] = I18n.t('flash.notice.created', :model => Author.model_name.human)
73         format.html { redirect_to root_path }
74         format.json { render json: @au.to_json(Author.show_json_opt), status: :created, location: @artist }
75       else
76         format.html { render action: "new" }
77         format.json { render json: @au.errors, status: :unprocessable_entity }
78       end
79     end
80   end
81
82   def update
83     @au = Author.edit(params[:id], @author)
84     @au.attributes = params[:author]
85     @au.overwrite @user.id
86
87     respond_to do |format|
88       if @au.save
89         flash[:notice] = I18n.t('flash.notice.updated', :model => Author.model_name.human)
90         format.html { redirect_to '/home/configure' }
91         format.json { head :ok }
92       else
93         format.html { render action: "edit" }
94         format.json { render json: @au.errors, status: :unprocessable_entity }
95       end
96     end
97   end
98 end