1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/README.md
David Heinemeier Hansson 60050ee412
Change to current approach
2018-06-27 13:38:24 +02:00

1.2 KiB

Action Text

🤸‍♂️💰📝

Installing

Assumes a Rails 5.2+ application with Active Storage and Webpacker installed.

  1. Install the gem:

    # Gemfile
    gem "actiontext", github: "basecamp/actiontext", require: "action_text"
    gem "image_processing", "~> 1.2" # for Active Storage variants
    
  2. Install the npm package:

    // package.json
    "dependencies": {
      "actiontext": "basecamp/actiontext"
    }
    
    $ yarn install
    
    // app/javascript/packs/application.js
    import "actiontext"
    
  3. Migrate the database

    ./bin/rails active_storage:install
    ./bin/rails action_text:install
    ./bin/rails db:migrate
    
  4. Declare text columns as Action Text attributes:

    # app/models/message.rb
    class Message < ActiveRecord::Base
      has_rich_text :content
    end
    
  5. Replace form text_areas with rich_text_areas:

    <%# app/views/messages/_form.html.erb %>
    <%= form_with(model: message) do |form| %>
      …
      <div class="field">
        <%= form.label :content %>
        <%= form.rich_text_area :content %>
      </div>
      …
    <% end %>