I follow this video in the homepage of ruby on rails: https://rubyonrails.org/ . These are my steps
<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
<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
<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
<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
<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
<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
<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 %>
Why my images did not show? How to fix it?