OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / controllers / original_picture_licenses_controller.rb
1 class OriginalPictureLicensesController < ApplicationController
2   before_action :authenticate_user, :only => [:new, :create]
3   before_action :authenticate_artist, :only => [:new, :create]
4   
5   def new
6     # use @item, @original_picture, @form
7     
8     respond_to do |format|
9       format.html
10     end
11   end
12   
13   def create
14     @my_model_class = OriginalPictureLicense
15     
16     @item = @my_model_class.new
17     @my_model_class.fold_extend_settings params[@my_model_class.item_name]
18     @item.attributes = @item.permit_params params
19     @item.overwrite 
20     @item.boosts 'post'
21     @original_picture = OriginalPicture.show @item.original_picture, @operators
22     
23     if @item.valid?
24       # switch my_model_class
25       @item = OriginalPictureLicense.build_resource_picture @item, @original_picture, @item.permit_params(params)
26       respond_to do |format|
27         format.html {
28           render main_app.new_resource_picture_path
29         }
30         format.json {
31           # response contains credits template
32           #
33           # confirm page need show credit
34           # however, building resource picture has not credit
35           # 
36           r = {
37             :item => @item,
38             :credits => render_to_string('credits', :formats => :html, :layout => false)
39           }
40           render json: r.to_json, status: :created
41         }
42       end
43     else
44       respond_to do |format|
45         format.html {
46           @form = Locmare::Bucket.factory @item.item_name, 'default', @item, true, true, @operators
47           render action: "new"
48         }
49         format.json {
50           render json: @item.errors, status: :unprocessable_entity
51         }
52       end
53     end
54   end
55 end