为了使用富文本,决定 DEMO 下 Rails 6。比着几位兄台关于 webpack 在 Rails 6 上的实例,搞了一把。发现有些地方不准确,特别是 bootstrap 部分。应该是这样的:
1、创建 APP
rails new loans -d mysql
2、安装 boostrap jquery 和 popper.js
yarn add bootstrap jquery popper.js
3、在 config/webpack/environment.js 中添加
# config/webpack/environment.js
......
const webpack = require('webpack')
environment.plugins.append( "Provide", new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
Popper: ['popper.js', 'default']
}))
......
4、在 app/javascript/packs/application.js 中添加
#app/javascript/packs/application.js
......
import "bootstrap"
import "../styles/application"
document.addEventListener("turbolinks:load",() => {
$('[data-toggle="tooltip"]').tooltip()
$('[data-toggle="popover"]').popover()
})
......
5、在 app/javascript/styles/application.scss 中添加
#app/javascript/styles/application.scss
......
@import 'bootstrap/scss/bootstrap';
@import 'fontawesome/scss/fontawesome';
......
以上的初始配置算是完成了,加个 Navbar 试试
6、在 application.html.erb 中加上 bootstrap 的菜单
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
以上资料,GG 半天也大搭,百度更白痴,最后在 YT 上找到了一片资料。希望给和我一样刚入门的家伙们节省一点时间。 哦,忘说了,那个 font-awesome 我也没搞定,搜遍全世界也没有只言片语。