OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / controllers / original_picture_license_groups_controller.rb
1 class OriginalPictureLicenseGroupsController < ApplicationController
2   before_action :authenticate_user, :only => [:new, :create]
3   before_action :authenticate_artist, :only => [:new, :create]
4   
5   def new
6     @original_picture = OriginalPicture.show params[:original_picture_id], @operators
7     @item = OriginalPictureLicenseGroup.new()
8     @item.supply_default @original_picture.id
9     
10     respond_to do |format|
11       format.html {
12         @form = Locmare::Bucket.factory @item.item_name, 'default', @item, true, true, @operators
13       }
14       format.json { render json: @item.to_json }
15     end
16   end
17   
18   def create
19     @my_model_class = OriginalPictureLicenseGroup
20     
21     @item = @my_model_class.new
22     @my_model_class.fold_extend_settings params[@my_model_class.item_name]
23     @item.attributes = @item.permit_params params
24     @item.overwrite 
25     @original_picture = OriginalPicture.show @item.original_picture, @operators
26     
27     if @item.valid?
28       # switch my_model_class
29       @item = OriginalPictureLicenseGroup.build_original_picture_license @item, nil, @operators
30       respond_to do |format|
31         format.html {
32           @form = Locmare::Bucket.factory @item.item_name, 'default', @item, true, true, @operators
33           render :template => @item.path_name + '/new'
34         }
35         format.json {
36           render json: @item.to_json(), status: :created, location: @item
37         }
38       end
39     else
40       respond_to do |format|
41         format.html {
42           @form = Locmare::Bucket.factory @item.item_name, 'default', @item, true, true, @operators
43           render action: "new"
44         }
45         format.json {
46           render json: @item.errors, status: :unprocessable_entity
47         }
48       end
49     end
50   end
51
52 end