OSDN Git Service

fix form
[pettanr/pettanr.git] / app / controllers / artists_controller.rb
1 class ArtistsController < ApplicationController
2   if Manifest.manifest.magic_numbers['run_mode'] == 0
3     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
4     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
5   else
6     before_filter :authenticate_resource_reader, :only => [:index, :show, :resource_pictures]
7     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
8     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
9   end
10
11   def self.model
12     Artist
13   end
14   
15   def index
16     filer_list
17   end
18   
19   def show
20     @item = Artist.show(params[:id], @operators)
21   
22     respond_to do |format|
23       format.html {
24         @artist = @item
25       }
26       format_prof format
27       format.json { render :json => @item.to_json(Artist.show_json_opt) }
28     end
29   end
30   
31   def count
32     list_count
33   end
34   
35   def new
36     form_new
37   end
38   
39   def edit
40     form_edit
41   end
42   
43   def create
44     @artist = Artist.new()
45     @artist.supply_default 
46     @artist.attributes = params[:artist]
47     @artist.overwrite @operators
48     respond_to do |format|
49       if @artist.save
50         flash[:notice] = I18n.t('flash.notice.created', :model => Artist.model_name.human)
51         format.html { redirect_to root_path }
52         format.json { render json: @artist.to_json(Artist.show_json_opt), status: :created, location: @artist }
53       else
54         flash[:notice] = I18n.t('flash.notice.not_created', :model => Artist.model_name.human)
55         format.html { render action: "new" }
56         format.json { render json: @artist.errors, status: :unprocessable_entity }
57       end
58     end
59   end
60
61   def update
62     @artist = Artist.edit(params[:id], @operators)
63     @artist.attributes = params[:artist]
64     @artist.overwrite @operators
65
66     respond_to do |format|
67       if @artist.save
68         flash[:notice] = I18n.t('flash.notice.updated', :model => Artist.model_name.human)
69         format.html { redirect_to '/home/configure' }
70         format.json { head :ok }
71       else
72         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Artist.model_name.human)
73         format.html { render action: "edit" }
74         format.json { render json: @artist.errors, status: :unprocessable_entity }
75       end
76     end
77   end
78
79   def destroy
80     @artist = Artist.edit(params[:id], @operators)
81     @artist.destroy
82
83     respond_to do |format|
84       format.html { redirect_to artists_url }
85       format.json { head :ok }
86     end
87   end
88 end