Rails 7: Upload image to rich text area did not show

I follow this video in the homepage of ruby on rails: https://rubyonrails.org/ . These are my steps

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>rails new demo
rails generate scaffold post title:string content:text
rails db:migrate
rails server
http://localhost:3000/
http://localhost:3000/posts
http://localhost:3000/posts/1
http://localhost:3000/posts/1/edit
http://localhost:3000/posts/new
</code>
<code>rails new demo rails generate scaffold post title:string content:text rails db:migrate rails server http://localhost:3000/ http://localhost:3000/posts http://localhost:3000/posts/1 http://localhost:3000/posts/1/edit http://localhost:3000/posts/new </code>
rails new demo
rails generate scaffold post title:string content:text
rails db:migrate
rails server
http://localhost:3000/
http://localhost:3000/posts
http://localhost:3000/posts/1
http://localhost:3000/posts/1/edit
http://localhost:3000/posts/new

File D:2024_04_29demoappviewslayoutsapplication.html.erb

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
<%= javascript_importmap_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
</code>
<code><!DOCTYPE html> <html> <head> <title>Demo</title> <meta name="viewport" content="width=device-width,initial-scale=1"> <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> <link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css"> <%= javascript_importmap_tags %> </head> <body> <%= yield %> </body> </html> </code>
<!DOCTYPE html>
<html>
<head>
  <title>Demo</title>
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <%= csrf_meta_tags %>
  <%= csp_meta_tag %>

  <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
  <link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
  <%= javascript_importmap_tags %>
</head>

<body>
<%= yield %>
</body>
</html>

http://localhost:3000/posts.json
http://localhost:3000/posts/2.json

Validate

File D:2024_04_29demoappmodelspost.rb

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class Post < ApplicationRecord
validates_presence_of :title
end
</code>
<code>class Post < ApplicationRecord validates_presence_of :title end </code>
class Post < ApplicationRecord
    validates_presence_of :title
end
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>rails console
rails c
Post.first
Post.create! title:”From the console”, content: “Nice!”
Post.where(created_at: Time.now.all_day).to_sql
Post.where(created_at: Time.now.all_day)
irb(main):008> Post.where(created_at: Time.now.yesterday.all_day)
irb(main):008> Post.where(created_at: Time.now.yesterday.all_day).to_sql
</code>
<code>rails console rails c Post.first Post.create! title:”From the console”, content: “Nice!” Post.where(created_at: Time.now.all_day).to_sql Post.where(created_at: Time.now.all_day) irb(main):008> Post.where(created_at: Time.now.yesterday.all_day) irb(main):008> Post.where(created_at: Time.now.yesterday.all_day).to_sql </code>
rails console
rails c
Post.first
Post.create! title:”From the console”, content: “Nice!”
Post.where(created_at: Time.now.all_day).to_sql

Post.where(created_at: Time.now.all_day)


irb(main):008> Post.where(created_at: Time.now.yesterday.all_day)

irb(main):008> Post.where(created_at: Time.now.yesterday.all_day).to_sql
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>rails action_text:install
bundle
rails db:migrate
</code>
<code>rails action_text:install bundle rails db:migrate </code>
rails action_text:install
bundle
rails db:migrate

File D:2024_04_29demoappmodelspost.rb

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class Post < ApplicationRecord
validates_presence_of :title
has_rich_text :content
end
</code>
<code>class Post < ApplicationRecord validates_presence_of :title has_rich_text :content end </code>
class Post < ApplicationRecord
    validates_presence_of :title
    has_rich_text :content
end

File D:2024_04_29demoappviewsposts_form.html.erb

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><%= form_with(model: post) do |form| %>
<% if post.errors.any? %>
<div style="color: red">
<h2><%= pluralize(post.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% post.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>
<div>
<%= form.label :title, style: "display: block" %>
<%= form.text_field :title %>
</div>
<div>
<%= form.label :content, style: "display: block" %>
<%= form.rich_text_area :content %>
</div>
<div>
<%= form.submit %>
</div>
<% end %>
</code>
<code><%= form_with(model: post) do |form| %> <% if post.errors.any? %> <div style="color: red"> <h2><%= pluralize(post.errors.count, "error") %> prohibited this post from being saved:</h2> <ul> <% post.errors.each do |error| %> <li><%= error.full_message %></li> <% end %> </ul> </div> <% end %> <div> <%= form.label :title, style: "display: block" %> <%= form.text_field :title %> </div> <div> <%= form.label :content, style: "display: block" %> <%= form.rich_text_area :content %> </div> <div> <%= form.submit %> </div> <% end %> </code>
<%= form_with(model: post) do |form| %>
  <% if post.errors.any? %>
    <div style="color: red">
      <h2><%= pluralize(post.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
        <% post.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div>
    <%= form.label :title, style: "display: block" %>
    <%= form.text_field :title %>
  </div>

  <div>
    <%= form.label :content, style: "display: block" %>
    <%= form.rich_text_area :content %>
  </div>

  <div>
    <%= form.submit %>
  </div>
<% end %>

enter image description here

Why my images did not show? How to fix it?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật