Rails 6 setup on Mac Catalina or BigSur, with Brew - activescaffold/active_scaffold GitHub Wiki
These notes should work to build a new Rails6 project, using Active Scaffold, on a Mac. Tested by D. Bulgatz using Catalina, 10.15.7 with mysql 5.7, using Brew to install Ruby, mysql, and dependencies. Updated by Brian Xu using Big Sur 11.6.7.
Basic setup of Brew and Bundler
# skip this git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
brew update
brew install node
brew install yarn
brew install rbenv
rbenv install 2.7.7
brew install [email protected]
brew install shared-mime-info
Create a folder for your application and install gems
mkdir rails6app
cd rails6app/
rbenv init
rbenv local 2.7.7
gem install bundler
gem install webpacker
yarn add @rails/webpacker
gem install rails -v 6.1.7.2
Installing mysql2 Gem for mysql 5.7
gem install mysql2 -v '0.5.5' -- \
--with-mysql-config /usr/local/Cellar/[email protected]/5.7.29/bin/mysql_config \
--with-cppflags=-I/usr/local/opt/[email protected]/include \
--with-ldflags=-L/usr/local/opt/[email protected]/lib
mysql and openssl paths may be different
Installing mysql2 Gem for mysql 8.0 with BigSur (new Cellar location)
gem install mysql2 -v '0.5.3' -- \
--with-mysql-lib=/opt/homebrew/Cellar/mysql/8.0.27/lib \
--with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.27 \
--with-mysql-config=/opt/homebrew/Cellar/mysql/8.0.27/bin/mysql_config \
--with-mysql-include=/opt/homebrew/Cellar/mysql/8.0.27/include
Fix Default version of bundler
This may be necessary to not use an old/default version of bundler. It was for me.
gem update --system
Create the Rails app
setup for mysql, and with a specified version of Rails (Must be Pre 6.1)
#create the new Rails app
rails _6.1.7.2_ new myapp -d mysql
setup the application for Active Scaffold
#Add to Gemfile
gem 'active_scaffold', '~>3.6.10'
gem 'jquery-rails'
gem 'jquery-ui-rails' #needed for Date field searches to work
#For Export to excel, add these
gem "active_scaffold_export"
gem 'caxlsx'
gem 'caxlsx_rails'
#run Bundle install
bundle install
Setup your rails app for Active Scaffold
bundle exec rails g active_scaffold:install
Create app/assets/javascripts/application.js,
The new Rails 6 architecture has moved the javascript folder and renamed it!
//= require jquery
//= require jquery_ujs
//= require_tree .
//= require active_scaffold
Precompile the application.js
config/initializers/assets.rb
bundle exec rails assets:precompile
Add this javascript include to main layout
app/views/layouts/application.html.erb
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
Ensure this tag exists.
Create a resource (use a generator to make life easy!)
rails g active_scaffold:resource vehicle m_id:integer chassis:string type:string yr_made:string yr_ended:string doors:string drive_train:string e_mnt:string hp:integer trq:integer e_id:integer trans:string
rails g active_scaffold:resource user auid:string first_name:string last_name:string email:string \
encrypted_password:string sign_in_count:integer current_sign_in_at:datetime last_sign_in_at:datetime \
current_sign_in_ip:string reset_password_token:string reset_password_sent_at:datetime remember_created_at:datetime \
approved:integer
Run the migration created to build the new resource
If mysql is not currently running, type mysql.server start in terminal
bundle exec rails db:create
bundle exec rails db:migrate
Modify controller to setup for both search and field search and Export
app/controller/vehicles_controller.rb
conf.actions << :field_search
conf.field_search.link.parameters = {:kind => :field_search}
conf.field_search.link.label = 'Field Search'
#For excel export
conf.actions << :export
conf.export.default_file_format = 'xslx'
Add Stylesheets for Active Scaffold and Active Scaffold Export
app/assets/stylesheets/application.css
*= require active_scaffold
*= require active_scaffold_export
Start the Rails Server
rails webpacker:install or bundle update webpacker
bundle exec rails s
Show Routes
bundle exec rails routes
Navigate to newly created resource
http://localhost:3000/vehicles
Notes on Active Scaffold Export
be sure to define a to_s (to string) method in each model that will never return nil. There is a bug in the caxlxs gem that tries to determine the cell type, and it gets handed the active record object, which must respond to to_s or you will get an unhandled exception.