參考 How to install Bootstrap and jQuery on Rails 6, 2020-04-27
mac 上執行
brew install yarnYarn add bootstrap jquery popper.js編輯 config/webpack/environment.js
const { environment } = require('@rails/webpacker') const webpack = require('webpack')environment.plugins.append('Provide', new webpack.ProvidePlugin({ s: 'jquery', jQuery: 'jquery', Popper: ['popper.js', 'default'] }))module.exports = environmentapp/javascript/packs/application.js
import 'bootstrap'app/assets/stylesheets/application.css 副檔名改為 scss
並加上:
@import 'bootstrap/scss/bootstrap';編輯 Gemfile
group :development do gem "capistrano", "~> 3.10", require: false gem "capistrano-rails", "~> 1.6", require: false gem 'capistrano-asdf' gem 'capistrano-passenger'end執行
bundle installbundle exec cap install編輯 Capfile
require "capistrano/bundler"require "capistrano/rails/assets"require "capistrano/rails/migrations"require "capistrano/passenger"require "capistrano/asdf"編輯 config/deploy.rb, 如果 server 上還沒有 master.key 就上傳。
set :application, "YourApplicationName"set :repo_url, "URL of Your Git Repository"append :linked_files, "config/master.key"set :passenger_restart_with_touch, truenamespace :deploy do namespace :check do before :linked_files, :set_master_key do on roles(:app), in: :sequence, wait: 10 do unless test("[ -f #{shared_path}/config/master.key ]") upload! 'config/master.key', "#{shared_path}/config/master.key" end end end endendnamespace :deploy do task :restart do on roles(:web), in: :sequence do execute :touch, release_path.join('tmp/restart.txt') end endend編輯 config/deploy/production.rb
server 'Your.Server.URL', user: 'UserNameUsedToDeployToServer', roles: %w{app db web}Source code 上傳 Git.
使用 asdf 安裝 yarn
asdf plugin-add yarnasdf install yarn latest查看版本
yarn -v結果
No version set for command yarnConsider adding one of the following versions in your config file at /var/www/vm_docx/releases/20210128042346/.tool-versionsyarn 1.22.10設為預設
asdf global yarn 1.22.10執行以下命令:
passenger-config about ruby-command結果
To use in Apache: PassengerRuby /home/ray/.asdf/installs/ruby/3.0.0/bin/ruby例如 http://xxx.dila.edu.tw/ProjectName
假設 rails project root: /var/www/ProjectName/current
編輯 /etc/apache2/sites-available/ProjectName.conf
Alias /ProjectName /var/www/ProjectName/current/public<Location /ProjectName> PassengerBaseURI /ProjectName PassengerAppRoot /var/www/ProjectName/current PassengerRuby /home/ray/.asdf/installs/ruby/3.0.0/bin/ruby</Location><Directory /var/www/ProjectName/current/public> Allow from all Options -MultiViews Require all granted</Directory>編輯 /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80> ... Include sites-available/ProjectName.conf</VirtualHost>重新啟動 apache2
sudo service apache2 restartcap production deploy如果出現如下錯誤:
Your bundle only supports platforms ["x86_64-darwin-20"] but your local platform is x86_64-linux. Add the current platform to the lockfile with `bundle lock --add-platform x86_64-linux` and try again.就依指示執行
bundle lock --add-platform x86_64-linux