Skip to content
Browse files

revisi code on task 3

  • Loading branch information...
1 parent fc844d4 commit 6cda7ddc76f7742e74814440200523790cecc716 @varid007 committed
Showing with 36 additions and 12 deletions.
  1. +4 −0 belajar/app/models/article.rb
  2. +20 −1 belajar/app/models/user.rb
  3. +12 −11 belajar/app/models/user.rb~
View
4 belajar/app/models/article.rb
@@ -3,4 +3,8 @@ class Article < ActiveRecord::Base
belongs_to :user
scope :rating_is_and_above, lambda {|rate| where("rating > ?", rate) }
+ validates :title, :uniqueness => true,
+ :presence => true,
+ :length => {:minimum => 1, :maximum => 15},
+ :format => {:with => /[a-zA-Z\s]+$/}
end
View
21 belajar/app/models/user.rb
@@ -3,9 +3,28 @@ class User < ActiveRecord::Base
has_many :articles
has_many :countries
+ has_many :shared_articles,
+ :class_name => "Article",
+ :foreign_key => "user_id"
+ :"title like '%share%'"
+
def show_full_name
"#{self.first_name} #{self.last_name}"
end
-
+ validates :first_name, :presence => true,
+ :length => {:minimum => 1, :maximum => 20},
+ :format => {:with => /[a-zA-Z\s]+$/}
+ validates :last_name, :presence => true,
+ :length => {:minimum => 1, :maximum => 20},
+ :format => {:with => /[a-zA-Z\s]+$/}
+
+ validates :email, :presence => true,
+ :length => {:minimum => 3, :maximum => 254},
+ :uniqueness => true,
+ :format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i}
+ validates :username, :presence => true,
+ :length => {:minimum => 3, :maximum => 254},
+ :uniqueness => true,
+ :format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i}
end
View
23 belajar/app/models/user.rb~
@@ -7,18 +7,19 @@ class User < ActiveRecord::Base
"#{self.first_name} #{self.last_name}"
end
- validates :first_name, :presence => true,
- :length => {:minimum => 1, :maximum => 20}
-
- validates :last_name, :presence => true,
- :length => {:minimum => 1, :maximum => 20}
-
+ validates :first_name, :presence => true,
+ :length => {:minimum => 1, :maximum => 20},
+ :format => {:with => /[a-zA-Z\s]+$/}
+ validates :last_name, :presence => true,
+ :length => {:minimum => 1, :maximum => 20},
+ :format => {:with => /[a-zA-Z\s]+$/}
+
validates :email, :presence => true,
:length => {:minimum => 3, :maximum => 254},
:uniqueness => true,
- :format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i}
-
- validates :username, :presence => true,
- :length => {:minimum => 1, :maximum => 254},
- :uniqueness => true
+ :format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i}
+ validates :username, :presence => true,
+ :length => {:minimum => 3, :maximum => 254},
+ :uniqueness => true,
+ :format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i}
end

0 comments on commit 6cda7dd

Please sign in to comment.
Something went wrong with that request. Please try again.