OSDN Git Service

t#29045:create overwrite on panel
[pettanr/pettanr.git] / app / controllers / panels_controller.rb
index 6854b42..2dc0e67 100644 (file)
@@ -3,12 +3,6 @@ class PanelsController < ApplicationController
   before_filter :authenticate_user!, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
   before_filter :authenticate_admin!, :only => [:list, :browse]
 
-  private
-  
-  def treat_param panel
-    panel.author_id = @author.id
-  end
-  
   public
   
   # GET /panels
@@ -64,7 +58,7 @@ class PanelsController < ApplicationController
 
   def new
     @panel = Panel.new
-    @panel.supply_default @author
+    @panel.supply_default
 
     respond_to do |format|
       format.html # new.html.erb
@@ -84,13 +78,14 @@ class PanelsController < ApplicationController
   # POST /panels
   # POST /panels.json
   def create
+    @panel = Panel.new
+    @panel.supply_default
     if params[:json]
       jsn = JSON.parse(params[:json])
     end
     @prm = params[:panel] || jsn
-    @panel = Panel.new(@prm)
-    treat_param @panel
-
+    @panel.attributes = @prm
+    @panel.overwrite @author
     respond_to do |format|
       if @panel.store
         format.html { redirect_to @panel, notice: 'Panel was successfully created.' }
@@ -110,8 +105,9 @@ class PanelsController < ApplicationController
       jsn = JSON.parse(params[:json])
     end
     @prm = params[:panel] || jsn
+    @panel.attributes = @prm
+    @panel.overwrite @author
     respond_to do |format|
-      @panel.attributes = @prm
       if @panel.store
         format.html { redirect_to @panel, notice: 'Panel was successfully updated.' }
         format.json { head :ok }