Browse files

+models: Prase,Translate,TranslatesFrases

  • Loading branch information...
1 parent eeb5268 commit 61a29dbe201454ae5744e4a88b16d588e9402fe2 @DarTSeNSe committed Dec 9, 2011
View
16 app/models/phrase.rb
@@ -0,0 +1,16 @@
+class Phrase < ActiveRecord::Base
+ attr_accessible :phrase, :tag
+
+ has_many :translates, :dependent => :destroy
+ has_many :translates_phrases, :class_name => "TranslatesPhrases",
+ :foreign_key => "translate_id",
+ :dependent => :destroy
+
+ belongs_to :user
+
+ validates :phrase, :presence => true,
+ :length => { :maximum => 140 },
+ :uniqueness => { :case_sensitive => false }
+ validates :user_id, :presence => true
+
+end
View
12 app/models/translate.rb
@@ -0,0 +1,12 @@
+class Translate < ActiveRecord::Base
+ attr_accessible :translate, :rating
+
+ belongs_to :phrase
+ belongs_to :translates_phrases, :foreign_key => "phrase_id",
+ :dependent => :destroy
+
+ validates :translate, :presence => true,
+ :length => { :maximum => 200 },
+ :uniqueness => { :case_sensitive => false }
+ validates :rating, :presence => true
+end
View
10 app/models/translates_phrases.rb
@@ -0,0 +1,10 @@
+class TranslatesPhrases < ActiveRecord::Base
+ attr_accessible :translate_id, :phrase_id
+
+ belongs_to :phrase
+ belongs_to :translate
+
+ validates :phrase_id, :presence => true
+ validates :translate_id, :presence => true
+
+end
View
2 app/models/user.rb
@@ -2,6 +2,8 @@ class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :name, :email, :password, :password_confirmation
+ has_many :phrases, :dependent => :destroy
+
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :name, :presence => true,
View
14 db/migrate/20111209123536_create_phrases.rb
@@ -0,0 +1,14 @@
+class CreatePhrases < ActiveRecord::Migration
+ def change
+ create_table :phrases do |t|
+ t.string :phrase, :unique => true
+ t.string :tag
+ t.integer :user_id
+
+ t.timestamps
+ end
+ add_index :phrases, :phrase
+ add_index :phrases, :tag
+ add_index :phrases, :user_id
+ end
+end
View
16 db/migrate/20111209123913_create_translates.rb
@@ -0,0 +1,16 @@
+class CreateTranslates < ActiveRecord::Migration
+ def change
+ create_table :translates do |t|
+ t.string :translate
+ t.integer :phrase_id
+ t.integer :language_id
+ t.string :rating
+
+ t.timestamps
+ end
+ add_index :translates, :translate
+ add_index :translates, :phrase_id
+ add_index :translates, :language_id
+ add_index :translates, :rating
+ end
+end
View
13 db/migrate/20111209124823_create_translates_phrases.rb
@@ -0,0 +1,13 @@
+class CreateTranslatesPhrases < ActiveRecord::Migration
+ def change
+ create_table :translates_phrases, :id => false do |t|
+ t.integer :phrase_id
+ t.integer :translate_id
+
+ t.timestamps
+ end
+ add_index :translates_phrases, :translate_id
+ add_index :translates_phrases, :phrase_id
+ add_index :translates_phrases, [:phrase_id, :translate_id], :unique => true
+ end
+end
View
26 db/schema.rb
@@ -11,7 +11,31 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20111209090431) do
+ActiveRecord::Schema.define(:version => 20111209124823) do
+
+ create_table "phrases", :force => true do |t|
+ t.string "phrase"
+ t.string "tag"
+ t.integer "user_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "translates", :force => true do |t|
+ t.string "translate"
+ t.integer "phrase_id"
+ t.integer "language_id"
+ t.string "rating"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "translates_phrases", :id => false, :force => true do |t|
+ t.integer "phrase_id"
+ t.integer "translate_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
create_table "users", :force => true do |t|
t.string "name"
View
5 spec/models/phrase_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Phrase do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
5 spec/models/translate_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Translate do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
5 spec/models/translates_phrases_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe TranslatesPhrases do
+ pending "add some examples to (or delete) #{__FILE__}"
+end

0 comments on commit 61a29db

Please sign in to comment.