OSDN Git Service

try autotest
[pettanr/pettanr.git] / app / controllers / artists_controller.rb
1 class ArtistsController < ApplicationController
2 layout 'test'
3   before_filter :authenticate_user!, :only => [:index, :show, :create, :update, :destroy]
4   before_filter :authenticate_admin!, :only => [:list, :browse]
5
6   # GET /artists
7   # GET /artists.json
8   def index
9     @page = Artist.page params[:page]
10     @page_size = Artist.page_size params[:page_size]
11     @artists = Artist.list({}, @page, @page_size)
12
13     respond_to do |format|
14       format.html # index.html.erb
15       format.json { render :json => @artists.to_json(Artist.list_json_opt) }
16     end
17   end
18
19   # GET /artists/1
20   # GET /artists/1.json
21   def show
22     @artist = Artist.show(params[:id])
23
24     respond_to do |format|
25       format.html # show.html.erb
26       format.json { render :json => @artist.to_json(Artist.list_json_opt) }
27     end
28   end
29
30   def count
31     @artist = {:count => Artist.visible_count}
32     respond_to do |format|
33       format.json { render json: @artist.to_json }
34     end
35   end
36   
37   def list
38     @artists = Artist.all
39
40     respond_to do |format|
41       format.html { render layout: 'system' }
42       format.json { render json: @artists }
43     end
44   end
45
46   def browse
47     @artist = Artist.find(params[:id])
48
49     respond_to do |format|
50       format.html { render layout: 'system' }
51       format.json { render json: @artist }
52     end
53   end
54
55   # GET /artists/new
56   # GET /artists/new.json
57   def new
58     @artist = Artist.new
59
60     respond_to do |format|
61       format.html # new.html.erb
62       format.js
63       format.json { render json: @artist }
64     end
65   end
66
67   # GET /artists/1/edit
68   def edit
69     @artist = Artist.find(params[:id])
70   end
71
72   # POST /artists
73   # POST /artists.json
74   def create
75     @artist = Artist.new(params[:artist])
76     @artist.author_id = @author.id
77     respond_to do |format|
78       if @artist.save
79         format.html { redirect_to @artist, notice: 'Artist was successfully created.' }
80         format.json { render json: @artist, status: :created, location: @artist }
81       else
82         format.html { render action: "new" }
83         format.json { render json: @artist.errors, status: :unprocessable_entity }
84       end
85     end
86   end
87
88   # PUT /artists/1
89   # PUT /artists/1.json
90   def update
91     @artist = Artist.find(params[:id])
92
93     respond_to do |format|
94       if @artist.update_attributes(params[:artist])
95         format.html { redirect_to @artist, notice: 'Artist was successfully updated.' }
96         format.json { head :ok }
97       else
98         format.html { render action: "edit" }
99         format.json { render json: @artist.errors, status: :unprocessable_entity }
100       end
101     end
102   end
103
104   # DELETE /artists/1
105   # DELETE /artists/1.json
106   def destroy
107     @artist = Artist.find(params[:id])
108     @artist.destroy
109
110     respond_to do |format|
111       format.html { redirect_to artists_url }
112       format.json { head :ok }
113     end
114   end
115 end