OSDN Git Service

t#31538:fix default value
[pettanr/pettanr.git] / app / controllers / ground_pictures_controller.rb
index dd8ebb6..26c14b7 100644 (file)
@@ -31,9 +31,12 @@ class GroundPicturesController < ApplicationController
   end
   
   def new
-    @ground_picture = GroundPicture.new params[:ground_picture]
+    @picture = Picture.show params[:picture_id], @author
+    raise ActiveRecord::Forbidden unless @picture.enable?
+    @panel = Panel.edit(@author.working_panel, @author)
+    
+    @ground_picture = GroundPicture.new :panel_id => @panel.id, :picture_id => @picture.id
     @ground_picture.supply_default
-    @panel = @ground_picture.panel
 
     respond_to do |format|
       format.html
@@ -51,10 +54,14 @@ class GroundPicturesController < ApplicationController
   end
 
   def create
-    @ground_picture = GroundPicture.new params[:ground_picture]
-    @ground_picture.supply_default
-    @ground_picture.overwrite 
-    @panel = Panel.edit(@ground_picture.panel.id, @author)
+    @panel = Panel.edit(@author.working_panel, @author)
+    
+    @ground_picture = GroundPicture.new
+    @ground_picture.attributes = params[:ground_picture]
+    @ground_picture.overwrite @panel.id
+    
+    @picture = Picture.show @ground_picture.picture_id, @author
+    raise ActiveRecord::Forbidden unless @picture.enable?
     
     respond_to do |format|
       if @ground_picture.valid?
@@ -63,8 +70,8 @@ class GroundPicturesController < 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" }
+          flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundPicture.model_name.human)
+          format.html { render action: "new" }
           format.json { render json: @panel.errors, status: :unprocessable_entity }
         end
       else
@@ -78,8 +85,11 @@ class GroundPicturesController < ApplicationController
   def update
     @ground_picture = GroundPicture.show(params[:id], @author)
     @ground_picture.attributes = params[:ground_picture]
-    @ground_picture.overwrite 
     @panel = Panel.edit(@ground_picture.panel.id, @author)
+    @ground_picture.overwrite @panel.id
+    
+    @picture = Picture.show @ground_picture.picture_id, @author
+    raise ActiveRecord::Forbidden unless @picture.enable?
     
     respond_to do |format|
       if @ground_picture.store @author