OSDN Git Service

modify comic(win7)
authoryasushiito <yasushiito@git.sourceforge.jp>
Tue, 13 Mar 2012 23:11:24 +0000 (08:11 +0900)
committeryasushiito <yasushiito@git.sourceforge.jp>
Tue, 13 Mar 2012 23:11:24 +0000 (08:11 +0900)
Gemfile.lock
app/controllers/comics_controller.rb
app/models/comic.rb
db/migrate/20111206105830_create_comics.rb

index 8c9ad92..30c6cd9 100644 (file)
@@ -152,7 +152,7 @@ GEM
     sprockets (2.0.3)
       hike (~> 1.2)
       rack (~> 1.0)
     sprockets (2.0.3)
       hike (~> 1.2)
       rack (~> 1.0)
-      tilt (!= 1.3.0, ~> 1.1)
+      tilt (~> 1.1, != 1.3.0)
     sqlite3 (1.3.5-x86-mingw32)
     term-ansicolor (1.0.7)
     therubyracer-heroku (0.8.1.pre3)
     sqlite3 (1.3.5-x86-mingw32)
     term-ansicolor (1.0.7)
     therubyracer-heroku (0.8.1.pre3)
index fdddd7a..2af0b30 100644 (file)
@@ -97,7 +97,7 @@ class ComicsController < ApplicationController
   # GET /comics/new.json
   def new
     @comic = Comic.new
   # GET /comics/new.json
   def new
     @comic = Comic.new
-
+    @comic.supply_default
     respond_to do |format|
       format.html # new.html.erb
       format.json { render json: @comic }
     respond_to do |format|
       format.html # new.html.erb
       format.json { render json: @comic }
@@ -112,8 +112,9 @@ class ComicsController < ApplicationController
   # POST /comics
   # POST /comics.json
   def create
   # POST /comics
   # POST /comics.json
   def create
-    @comic = Comic.new(params[:comic])
-    treat_param @comic
+    params[:comic].merge! author_id: @author.id
+    @comic = Comic.new params[:comic]
+    @comic.supply_default 
 
     respond_to do |format|
       if @comic.save
 
     respond_to do |format|
       if @comic.save
@@ -129,9 +130,10 @@ class ComicsController < ApplicationController
   # PUT /comics/1
   # PUT /comics/1.json
   def update
   # PUT /comics/1
   # PUT /comics/1.json
   def update
+    params[:comic].merge! author_id: @author.id
     @comic = Comic.find(params[:id])
     @comic = Comic.find(params[:id])
-    if @comic.own? @author
-      respond_to do |format|
+    respond_to do |format|
+      if @comic.own? @author
         if @comic.update_attributes(params[:comic])
           format.html { redirect_to @comic, notice: 'Comic was successfully updated.' }
           format.json { head :ok }
         if @comic.update_attributes(params[:comic])
           format.html { redirect_to @comic, notice: 'Comic was successfully updated.' }
           format.json { head :ok }
@@ -139,10 +141,10 @@ class ComicsController < ApplicationController
           format.html { render action: "edit" }
           format.json { render json: @comic.errors, status: :unprocessable_entity }
         end
           format.html { render action: "edit" }
           format.json { render json: @comic.errors, status: :unprocessable_entity }
         end
+      else
+        format.html { render action: "edit" }
+        format.json { render json: @comic.errors, status: :unprocessable_entity }
       end
       end
-    else
-      format.html { render action: "edit" }
-      format.json { render json: @comic.errors, status: :unprocessable_entity }
     end
   end
 
     end
   end
 
index 2411318..4e6f0f4 100644 (file)
@@ -1,7 +1,28 @@
 class Comic < ActiveRecord::Base
   has_many :panels, :dependent => :destroy
   belongs_to :author
 class Comic < ActiveRecord::Base
   has_many :panels, :dependent => :destroy
   belongs_to :author
+  
+  class NotZeroValidator < ActiveModel::EachValidator\r
+    def validate_each(record, attribute, value)\r
+      record.errors[attribute] << (options[:message] || "is zero") if value == 0\r
+    end\r
+  end\r
 
 
+  validates :title, :presence => true, :length => {:maximum => 100}\r
+  validates :width, :presence => true, :numericality => true, :not_zero => true
+  validates :height, :presence => true, :numericality => true, :not_zero => true
+  validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0...4}
+  validates :editable, :presence => true, :numericality => true, :inclusion => {:in => 0...4}
+  
+  before_save do |r|
+    r.supply_default
+  end
+  
+  def supply_default
+    self.visible = 0 if self.visible.blank?
+    self.editable= 0 if self.editable.blank?
+  end
+  
   def own? author
     return false unless author
     self.author_id == author.id
   def own? author
     return false unless author
     self.author_id == author.id
index 8748a14..9beabbc 100644 (file)
@@ -1,12 +1,12 @@
 class CreateComics < ActiveRecord::Migration
   def change
     create_table :comics do |t|
 class CreateComics < ActiveRecord::Migration
   def change
     create_table :comics do |t|
-      t.string :title
-      t.integer :width, :null => false, :default => 200
-      t.integer :height, :null => false, :default => 80
+      t.string :title, :null => false, :limit => 100
+      t.integer :width, :null => false
+      t.integer :height, :null => false
       t.integer :visible, :null => false, :default => 0
       t.integer :editable, :null => false, :default => 0
       t.integer :visible, :null => false, :default => 0
       t.integer :editable, :null => false, :default => 0
-      t.integer :author_id
+      t.integer :author_id, :null => false
 
       t.timestamps
     end
 
       t.timestamps
     end