Rails Action Text implementation

Introduction

Leave it as a memo for yourself.

environment

procedure

1. Create an app

Create an app using MySQL.

$ rails new actionText -d mysql

Go to the created app

2.scaffold Create an app template with scaffold.

$ rails g scaffold article title:string

3. DB creation

$ rails db:create

4.migrate

$ rails db:migrate

5. Action Text installation

$ rails action_text:install

6.migrate

$ rails db:migrate

7. Association

Since Action Text data is stored in a dedicated table, it needs to be associated with the article model.

app/models/article.rb


class Article < ApplicationRecord
  has_rich_text :content
end

8. Add content to view

rhtml:app/views/articles/_form.html.erb



#abridgement
  <div class="field">
    <%= form.label :title %>
    <%= form.text_field :title %>
    <%= form.label :content %>
    <%= form.rich_text_area :content %>
  </div>
#abridgement

rhtml:app/views/articles/show.html.erb


<p id="notice"><%= notice %></p>

<p>
  <strong>Title:</strong>
  <%= @article.title %>
</p>
<p>
  <strong>Content:</strong>
  <%= @article.content %>
</p>

<%= link_to 'Edit', edit_article_path(@article) %> |
<%= link_to 'Back', articles_path %>

9. Add content to the controller

Add content to the method that reads the params parameter.

app/controllers/articles_controller.rb


#abridgement
    def article_params
      params.require(:article).permit(:title, :content)
    end
#abridgement

10.image_processing No image is displayed without image_processing.

gem 'image_processing'
$ bundle install

End

Recommended Posts

Rails Action Text implementation
Rails6: Extract the image in Action Text
Rails hashtag search implementation
Rails6 countdown timer implementation
[rails] gem'payjp' implementation procedure
[Rails 6] Implementation of inquiry function using Action Mailer
Rails search function implementation
Rails implementation of ajax removal
Rails fuzzy search function implementation
[Rails 6] Implementation of search function
[Rails] Implementation of category function
Login function implementation with rails
[Rails] Implementation of tutorial function
[Rails] Implementation of like function
[Rails 6] Pagination function implementation (kaminari)
[Rails] Implementation of user logic deletion
[Rails] Implementation of CSV import function
[Rails] Asynchronous implementation of like function
Rails 5 Code Reading Part 2 ~ Action View ~
[rails] Login screen implementation in devise
[Rails] Implementation of image preview function
[Rails] About implementation of like function
[Rails] Implementation of user withdrawal function
[Rails] Implementation of CSV export function
[Rails] Implementation of many-to-many category functions
[Rails] gem ancestry category function implementation
[Ruby on Rails] Comment function implementation
[Rails 6] Like function (synchronous → asynchronous) implementation
[Rails] Comment function implementation procedure memo
Fastest rails mail devise Welcome mail sending function implementation action mailer unnecessary Easyest
[Rails] views file creation # text is displayed
[Ruby on Rails] Follow function implementation: Bidirectional
Rails [For beginners] Implementation of comment function
Rails Basic CRUD function implementation procedure scaffold
[Rails 6] Implementation of SNS (Twitter) sharing function
[Vue.js] Implementation of menu function Implementation version rails6
[Ruby on rails] Implementation of like function
[Rails] Implementation of validation that maintains uniqueness
[Vue.js] Implementation of menu function Vue.js introduction rails6
[Rails 6 + Action Mailbox] Those who extracted the plain text of Gmail received by Action Mailbox