OSDN Git Service

t#32326:fix work
[pettanr/pettanr.git] / app / controllers / ground_colors_controller.rb
index c74e930..e9456f9 100644 (file)
@@ -31,9 +31,10 @@ class GroundColorsController < ApplicationController
   end
   
   def new
-    @ground_color = GroundColor.new params[:ground_color]
+    raise Pettanr::NotWork unless @author.working_panel
+    @panel = Panel.edit(@author.working_panel, @author)
+    @ground_color = GroundColor.new :panel_id => @panel.id, :code => params[:code].to_i
     @ground_color.supply_default
-    @panel = @author.working_panel
 
     respond_to do |format|
       format.html
@@ -51,9 +52,11 @@ class GroundColorsController < ApplicationController
   end
 
   def create
-    @ground_color = GroundColor.new params[:ground_color]
-    @ground_color.supply_default
+    raise Pettanr::NotWork unless @author.working_panel
     @panel = Panel.edit(@author.working_panel, @author)
+    
+    @ground_color = GroundColor.new 
+    @ground_color.attributes = params[:ground_color]
     @ground_color.overwrite @panel.id
     
     respond_to do |format|
@@ -63,10 +66,12 @@ class GroundColorsController < ApplicationController
           format.html { redirect_to @panel }
           format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
         else
-          format.html { render action: "panels/new" }
-          format.json { render json: @panel.errors, status: :unprocessable_entity }
+          flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundColor.model_name.human)
+          format.html { render action: "new" }
+          format.json { render json: @ground_color.errors, status: :unprocessable_entity }
         end
       else
+        flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundColor.model_name.human)
         format.html { render action: "new" }
         format.json { render json: @ground_color.errors, status: :unprocessable_entity }
       end
@@ -85,6 +90,7 @@ class GroundColorsController < ApplicationController
         format.html { redirect_to @ground_color }
         format.json { head :ok }
       else
+        flash[:notice] = I18n.t('flash.notice.not_updated', :model => GroundColor.model_name.human)
         format.html { render action: "edit" }
         format.json { render json: @ground_color.errors, status: :unprocessable_entity }
       end