Skip to content

Commit

Permalink
create articles table, model and add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitchauhan2065 committed Apr 5, 2018
1 parent b1efb8e commit fa4ce27
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/article.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Article < ActiveRecord::Base

validates :title , presence: true, length: { minimum: 3, maximum: 50 }
validates :description, presence: true, length: { minimum: 10, maximum: 300}

end
7 changes: 7 additions & 0 deletions db/migrate/20180405102959_create_articles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CreateArticles < ActiveRecord::Migration
def change
create_table :articles do |t|
t.string :title
end
end
end
7 changes: 7 additions & 0 deletions db/migrate/20180405104833_add_description_to_articles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddDescriptionToArticles < ActiveRecord::Migration
def change
add_column :articles, :description, :text
add_column :articles, :created_at, :datetime
add_column :articles, :updated_at, :datetime
end
end
23 changes: 23 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180405104833) do

create_table "articles", force: :cascade do |t|
t.string "title"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
end

end

0 comments on commit fa4ce27

Please sign in to comment.