OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / controllers / original_picture_licenses_controller.rb
1 class OriginalPictureLicensesController < ApplicationController
2   before_filter :authenticate_user, :only => [:new, :create]
3   before_filter :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 = params[@my_model_class.item_name]
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, params[@my_model_class.item_name]
26       respond_to do |format|
27         format.html {
28           render main_app.new_resource_picture_path
29         }
30         format.json { render json: @item.to_json, status: :created }
31       end
32     else
33       respond_to do |format|
34         format.html {
35           @form = Locmare::Bucket.factory @item.item_name, 'default', @item, true, true, @operators
36           render action: "new"
37         }
38         format.json {
39           render json: @item.errors, status: :unprocessable_entity
40         }
41       end
42     end
43   end
44 end