OSDN Git Service

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