OSDN Git Service

add show
[pettanr/pettanr.git] / app / controllers / licenses_controller.rb
index fe93071..dc31794 100644 (file)
@@ -65,43 +65,23 @@ class LicensesController < ApplicationController
   end
   
   def create
-    @item = self.class.model.new
+    set_model
+    @item = @my_model_class.new
     @item.supply_default 
-    @item.attributes = params[:license]
-    @item.overwrite @operators
-
-    if @item.save
-      respond_to do |format|
-        flash[:notice] = I18n.t('flash.notice.created', :model => self.class.model.model_name.human)
-        format.html { redirect_to @item }
-        format.json { render json: @item.to_json(self.class.model.show_json_opt), status: :created, location: @item }
-      end
-    else
-      flash[:notice] = I18n.t('flash.notice.not_created', :model => self.class.model.model_name.human)
-      render_new
-        format.html { render action: "new" }
-        format.json { render json: @item.errors, status: :unprocessable_entity }
-    end
+    @my_model_class.fold_extend_settings params[@my_model_class.item_name]
+    @item.attributes = params[@my_model_class.item_name]
+    @item.overwrite 
+    render_create
   end
-
+  
   def update
-    @item = self.class.model.edit(params[:id], @operators)
-    self.class.model.fold_extend_settings params
-    @item.attributes = params[:license]
+    set_edit
+    @my_model_class.fold_extend_settings params[@my_model_class.item_name]
+    @item.attributes = params[@my_model_class.item_name]
     @item.overwrite 
-    respond_to do |format|
-      if @item.save
-        flash[:notice] = I18n.t('flash.notice.updated', :model => self.class.model.model_name.human)
-        format.html { redirect_to @item }
-        format.json { head :ok }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_updated', :model => self.class.model.model_name.human)
-        format.html { render action: "edit" }
-        format.json { render json: @item.errors, status: :unprocessable_entity }
-      end
-    end
+    render_update
   end
-
+  
   def destroy
     @item = self.class.model.edit(params[:id], @operators)
     respond_to do |format|