1
0
Fork 0

Add attribute Post#published_at

This commit is contained in:
Alex Kotov 2021-03-10 15:18:57 +05:00
parent 5828b51ba6
commit 23cf15a705
4 changed files with 6 additions and 2 deletions

View File

@ -1,5 +1,7 @@
class Post < ApplicationRecord class Post < ApplicationRecord
belongs_to :profile belongs_to :profile
validates :text, length: { maximum: 200 } validates :text, presence: true, length: { maximum: 200 }
validates :published_at, presence: true
end end

View File

@ -11,7 +11,7 @@
<p class="card-text"> <p class="card-text">
<small class="text-muted"> <small class="text-muted">
<%= localize post.created_at, format: :short %> <%= localize post.published_at, format: :short %>
</small> </small>
</p> </p>
</div> </div>

View File

@ -4,6 +4,7 @@ class CreatePosts < ActiveRecord::Migration[6.1]
t.timestamps t.timestamps
t.references :profile, null: false, foreign_key: true t.references :profile, null: false, foreign_key: true
t.string :text, null: false t.string :text, null: false
t.datetime :published_at, null: false
end end
end end
end end

1
db/schema.rb generated
View File

@ -17,6 +17,7 @@ ActiveRecord::Schema.define(version: 2021_03_10_092955) do
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.integer "profile_id", null: false t.integer "profile_id", null: false
t.string "text", null: false t.string "text", null: false
t.datetime "published_at", null: false
t.index ["profile_id"], name: "index_posts_on_profile_id" t.index ["profile_id"], name: "index_posts_on_profile_id"
end end