OSDN Git Service

fix form
[pettanr/pettanr.git] / app / controllers / scrolls_controller.rb
index 8e271c5..4c1a6af 100644 (file)
@@ -73,70 +73,61 @@ class ScrollsController < ApplicationController
   end
   
   def new
-    @scroll = Scroll.new
-    @scroll.supply_default
-    respond_to do |format|
-      format.html
-      format.js
-      format.json { render json: @scroll.to_json(Scroll.show_json_opt) }
-    end
+    form_new
   end
-
+  
   def edit
-    @scroll = Scroll.edit(params[:id], @operators)
-    respond_to do |format|
-      format.html 
-      format.js
-    end
+    form_edit
   end
-
+  
   def create
-    @scroll = Scroll.new
-    @scroll.supply_default 
-    @scroll.attributes = params[:scroll]
-    @scroll.overwrite @operators
+    @item = Scroll.new
+    @item.supply_default 
+    @item.attributes = params[:scroll]
+    @item.overwrite @operators
 
-    respond_to do |format|
-      if @scroll.save
+    if @item.save
+      respond_to do |format|
         flash[:notice] = I18n.t('flash.notice.created', :model => Scroll.model_name.human)
-        format.html { redirect_to @scroll }
-        format.json { render json: @scroll.to_json(Scroll.show_json_opt), status: :created, location: @scroll }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_created', :model => Scroll.model_name.human)
-        format.html { render action: "new" }
-        format.json { render json: @scroll.errors, status: :unprocessable_entity }
+        format.html { redirect_to @item }
+        format.json { render json: @item.to_json(Scroll.show_json_opt), status: :created, location: @item }
       end
+    else
+      flash[:notice] = I18n.t('flash.notice.not_created', :model => Scroll.model_name.human)
+      render_new
+        format.html { render action: "new" }
+        format.json { render json: @item.errors, status: :unprocessable_entity }
     end
   end
 
   def update
-    @scroll = Scroll.edit(params[:id], @operators)
-    @scroll.attributes = params[:scroll]
-    @scroll.overwrite @operators
+    @item = Scroll.edit(params[:id], @operators)
+    @item.attributes = params[:scroll]
+    @item.overwrite @operators
     respond_to do |format|
-      if @scroll.save
+      if @item.save
         flash[:notice] = I18n.t('flash.notice.updated', :model => Scroll.model_name.human)
-        format.html { redirect_to @scroll }
+        format.html { redirect_to @item }
         format.json { head :ok }
       else
         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Scroll.model_name.human)
         format.html { render action: "edit" }
-        format.json { render json: @scroll.errors, status: :unprocessable_entity }
+        format.json { render json: @item.errors, status: :unprocessable_entity }
       end
     end
   end
 
   def destroy
-    @scroll = Scroll.edit(params[:id], @operators)
+    @item = Scroll.edit(params[:id], @operators)
     respond_to do |format|
-      if @scroll.destroy_with_scroll_panel
+      if @item.destroy_with_scroll_panel
         flash[:notice] = I18n.t('flash.notice.destroyed', :model => Scroll.model_name.human)
         format.html { redirect_to '/home/scrolls' }
         format.json { head :ok }
       else
         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Scroll.model_name.human)
-        format.html { redirect_to @scroll }
-        format.json { render json: @scroll.errors, status: :unprocessable_entity }
+        format.html { redirect_to @item }
+        format.json { render json: @item.errors, status: :unprocessable_entity }
       end
     end
   end