Permalink
Browse files

2 mei

  • Loading branch information...
1 parent c74bdd6 commit fc844d4889b2d98a65088d00b358e6e9745b5053 @varid007 committed May 2, 2012
@@ -1,2 +1,6 @@
class Article < ActiveRecord::Base
+ has_many :comments
+ belongs_to :user
+
+ scope :rating_is_and_above, lambda {|rate| where("rating > ?", rate) }
end
@@ -0,0 +1,4 @@
+class Article < ActiveRecord::Base
+ has_many :comments
+ belongs_to :user
+end
@@ -0,0 +1,4 @@
+class CategoriesProduct < ActiveRecord::Base
+ belongs_to :category
+ belongs_to :product
+end
@@ -0,0 +1,4 @@
+class Category < ActiveRecord::Base
+ has_many :categories_products
+ has_many :products, :through => :categories_products
+end
@@ -1,2 +1,3 @@
class Comment < ActiveRecord::Base
+ belongs_to :article
end
@@ -1,2 +1,14 @@
class Countrie < ActiveRecord::Base
+ belongs_to :user
+
+ validate :valid_id
+ def valid_id
+ self.errors[:code]<< "Harus id, usa atau frc" unless code =="id" || code == "usa" || code == "frc"
+ end
+
+ validates :name, :presence => true,
+ :length => {:minimum => 1, :maximum => 15},
+ :format => {:with => /[a-zA-Z\s]+$/}
end
+
+
@@ -0,0 +1,8 @@
+class Product < ActiveRecord::Base
+ belongs_to :user
+ has_many :categories_products
+ has_many :categories, :through => :categories_products
+
+ scope :prince_more_than_1000, where("prince >= 1000")
+end
+
@@ -0,0 +1,8 @@
+class Product < ActiveRecord::Base
+ belongs_to :user
+ has_many :categories_products
+ has_many :categories, :through => :categories_products
+
+ scope :prince_more_than_1000, where("prince >= 1000")
+end
+
@@ -1,2 +1,11 @@
class User < ActiveRecord::Base
+ has_many :products
+ has_many :articles
+ has_many :countries
+
+ def show_full_name
+
+ "#{self.first_name} #{self.last_name}"
+ end
+
end
@@ -0,0 +1,24 @@
+class User < ActiveRecord::Base
+ has_many :products
+ has_many :articles
+ has_many :countries
+
+ def show_full_name
+
+ "#{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 :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
+end
@@ -0,0 +1,10 @@
+class CreateProducts < ActiveRecord::Migration
+ def change
+ create_table :products do |t|
+ t.string :name
+ t.integer :prince
+ t.text :description
+ t.timestamps
+ end
+ end
+end
@@ -0,0 +1,8 @@
+class CreateCategories < ActiveRecord::Migration
+ def change
+ create_table :categories do |t|
+ t.string :name
+ t.timestamps
+ end
+ end
+end
@@ -0,0 +1,9 @@
+class CreateCategoriesProducts < ActiveRecord::Migration
+ def change
+ create_table :categories_products do |t|
+ t.integer :category_id
+ t.integer :product_id
+ t.timestamps
+ end
+ end
+end
@@ -0,0 +1,5 @@
+class AddRatingToArticles < ActiveRecord::Migration
+ def change
+ add_column :articles, :rating,:integer
+ end
+end
View
@@ -11,13 +11,27 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120501105724) do
+ActiveRecord::Schema.define(:version => 20120502062857) do
create_table "articles", :force => true do |t|
t.string "title"
t.text "body"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "rating"
+ end
+
+ create_table "categories", :force => true do |t|
+ t.string "name"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "categories_products", :force => true do |t|
+ t.integer "category_id"
+ t.integer "product_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
create_table "comments", :force => true do |t|
@@ -33,6 +47,14 @@
t.datetime "updated_at"
end
+ create_table "products", :force => true do |t|
+ t.string "name"
+ t.integer "prince"
+ t.text "description"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "users", :force => true do |t|
t.string "first_name"
t.string "last_name"
View
@@ -5,30 +5,11 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
-users = User.create([{:first_name => "aku", :last_name => "farid", :email => "sadewa44@gmail.com", :username => "aku", :age => 21, :birthday => 01-05-1990},
- {:first_name => "sundel", :last_name => "yoyok", :email => "sadewa441@gmail.com", :username => "dia", :age => 21, :birthday => 01-05-1990},
- {:first_name => "ari", :last_name => "ismunanto", :email => "sadewa442@gmail.com", :username => "mereka",:age => 21, :birthday => 01-05-1990},
- {:first_name => "Dian", :last_name => "ria", :email => "sadewa443@gmail.com", :username => "bion", :age => 21, :birthday => 101-05-1990},
- {:first_name => "poses", :last_name => "ngeh", :email => "sadewa444@gmail.com", :username => "botak", :address => "kami", :age => 21, :birthday => 05-04-1990}
- ])
-countries = Country.create([{:code => "JKT48", :name => "Jakarta"},
- {:code => "BDG49", :name => "BANGKA"},
- {:code => "PDG50", :name => "PADANG"},
- {:code => "BL001", :name => "BALI"},
- {:code => "AMB19", :name => "AMBON"}
+countries = Countries.create([{:code => "JKT1", :name => "Jakarta"},
+ {:code => "JKT2", :name => "Bandung"},
+ {:code => "JKT3", :name => "Padang"},
+ {:code => "JKT4", :name => "Jambi"},
+ {:code => "JKT5", :name => "Bali"}
])
-articles = Article.create([{:title => "Bandung 1", :body => "SATU"},
- {:title => "Bandung 2", :body => "DUA"},
- {:title => "Bandung 3", :body => "TIGA"},
- {:title => "Bandung 4", :body => "EMPAT"},
- {:title => "Bandung 5", :body => "LIMA"},
- ])
-
-comments = Comment.create([{:content => "HAI"},
- {:content => "HAI"},
- {:content => "HAI"},
- {:content => "HAI"},
- {:content => "HAI"},
- ])
View
@@ -0,0 +1,15 @@
+# This file should contain all the record creation needed to seed the database with its default values.
+# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
+#
+# Examples:
+#
+# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
+# Mayor.create(name: 'Emanuel', city: cities.first)
+
+countries = Counties.create([{:code => "JKT1", :name => "Jakarta"},
+ {:code => "JKT2", :name => "Bandung"},
+ {:code => "JKT3", :name => "Padang"},
+ {:code => "JKT4", :name => "Jambi"},
+ {:code => "JKT5", :name => "Bali"}
+ ])
+
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class CategoriesProductTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class CategoryTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ProductTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit fc844d4

Please sign in to comment.