LoginSignup
0

More than 5 years have passed since last update.

【メモ】ActionTextを使う6ステップ

Posted at

概要

  • ActionTextを使う手順を箇条書き

環境

  • Rails 6 beta 1

手順

  • ActionTextインストール
  • gemインストール
  • modelに追加
  • viewのformに追加
  • controllerのparamsに追加
  • viewの showに追加

ActionTextインストール

rails action_text:install
rails db:migrate

gemインストール

gem 'image_processing', '~> 1.0'
bundle install

modelに追加

例えば Item モデルに content という名称で追加します。

app/model/item.rb
class Item < ApplicationRecord
  has_rich_text :content

viewのformに追加

rich_text_areaを使います

app/views/new.html.erb
form_with @item do |f|
  f.rich_text_area :content

controllerのparamsに追加

例えばitem_paramsに :content を追加します。

app/controllers/items_controller.rb
  def create
    @item = Item.new(item_params)
    @item.save!
  end

  def item_params
    params.require(:item).permit(:content)
  end
  • viewの showに追加 content で呼び出すだけ。
app/views/items/show.html.erb
@item.content

以上

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0