OSDN Git Service

t#31538:fix default value
[pettanr/pettanr.git] / app / controllers / ground_colors_controller.rb
index 0652ea7..139699c 100644 (file)
@@ -31,9 +31,8 @@ class GroundColorsController < ApplicationController
   end
   
   def new
-    @ground_color = GroundColor.new
-    @panel = @author.working_panel
-    @ground_color.panel_id = @panel.id
+    @panel = Panel.edit(@author.working_panel, @author)
+    @ground_color = GroundColor.new :panel_id => @panel.id, :code => params[:code].to_i
     @ground_color.supply_default
 
     respond_to do |format|
@@ -52,10 +51,10 @@ class GroundColorsController < ApplicationController
   end
 
   def create
-    @ground_color = GroundColor.new params[:ground_color]
     @panel = Panel.edit(@author.working_panel, @author)
-    @ground_color.panel_id = @panel.id
-    @ground_color.supply_default
+    
+    @ground_color = GroundColor.new 
+    @ground_color.attributes = params[:ground_color]
     @ground_color.overwrite @panel.id
     
     respond_to do |format|
@@ -65,9 +64,9 @@ class GroundColorsController < ApplicationController
           format.html { redirect_to @panel }
           format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
         else
-          flash[:notice] = I18n.t('flash.notice.not_created', :model => Panel.model_name.human)
-          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)