学生向けプログラミング入門 | 無料

学生向けにプログラミングを無料で解説。Java、C++、Ruby、PHP、データベース、Ruby on Rails, Python, Django

【学習6.0】【MacOSX】アクションテキスト

アクションテキストをインストールします。


コマンド
rails action_text:install


マイグレーション適用
rails db:migrate


「app\models\project.rb」ファイルを以下の内容に更新します。


1.5行目に以下の記述を追加します。

has_rich_text :description
has_many_attached :images



2.9行目に以下の記述を追加します。

validates :description, presence: true, length: { maximum: 500 }



app\models\project.rb

class Project < ApplicationRecord
  belongs_to :user
  has_many :tasks

  has_rich_text :description
  has_many_attached :images

  validates :name, presence: true, length: { maximum: 50 }
  validates :description, presence: true, length: { maximum: 500 }
  validates :price, presence: true, numericality: { only_integer: true }
end



「app\models\task.rb」ファイルを以下の内容に更新します。


1.4行目に以下の記述を追加します。

has_rich_text :description



2.9行目に以下の記述を追加します。

validates :description, presence: true, length: { maximum: 500 }



app\models\task.rb

class Task < ApplicationRecord
  belongs_to :project

  has_rich_text :description

  validates :title, presence: true, length: { maximum: 50 }
  validates :video, presence: true
  validates :tag, presence: true
  validates :description, presence: true, length: { maximum: 500 }
  validates :project, presence: true
end