重学rails: rails8 安装/puma 报错/新特性
正式版安装
安装
rbenv install 3.3.6puma 报错

解决方案
PUMA_DISABLE_SSL=1 gem install puma -v 6.5.0 启动
./bin/dev脚手架/资源(resources)
# 原来的
rails generate scaffold post title:string body:text
# 不生成view
rails g resource comment references:post comment:string通过CDN的方式快速引入CSS
编辑
app/views/layouts/application.html.erb,插入一行<%= stylesheet_link_tag "https://cdn.simplecss.org/simple.css" %>
<%# Includes all stylesheet files in app/assets/stylesheets %>
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
<%= stylesheet_link_tag "https://cdn.simplecss.org/simple.css" %>
<%= javascript_importmap_tags %>方便前端debug
class PostsController < ApplicationController
before_action :set_post, only: %i[ show edit update destroy ]
# GET /posts or /posts.json
def index
@posts = Post.all
raise 'err'
end
...富文本
rails action_text:install修改model,添加对应富文本字段has_rich_text :body:
class Post < ApplicationRecord
has_rich_text :body
has_many :comments
end修改view,将textarea修改为rich_textarea:
<div>
<%= form.label :body, style: "display: block" %>
<%= form.rich_textarea :body %>
</div>内置身份验证
rails generate authentication
# 安装bcrypt
bundle
# 更新db
rails db:migrate部署 kamal
部署方面 rails8 默认加入了Kamal 2 和 Thruster,分别解决了 docker 容器化部署 以及https自动证书问题。 但国内目前并没有与之适配基础设施,慎用。 如果需要跳过kamal执行:
rails new blog --skip-kamal