-
Notifications
You must be signed in to change notification settings - Fork 330
Rails 6 setup on Mac Catalina or BigSur, with Brew
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.
# 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.`
brew install [email protected]
Create a folder for your application and install gems
mkdir rails6app
cd rails6app/
rbenv init
rbenv local 2.7.1
yarn add @rails/webpacker
gem install bundler
gem install rails -v 6.0.3.5
gem install mysql2 -v '0.5.3' -- \
--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
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
This may be necessary to not use an old/default version of bundler. It was for me.
gem update --system
setup for mysql, and with a specified version of Rails (Must be Pre 6.1)
#create the new Rails app
rails _6.0.3.5_ new myapp -d mysql
#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
bundle exec rails g active_scaffold:install
The new Rails 6 architecture has moved the javascript folder and renamed it!
//= require jquery
//= require jquery_ujs
//= require_tree .
//= require active_scaffold
config/initializers/assets.rb
Rails.application.config.assets.precompile += %w( application.js )
app/views/layouts/application.html.erb
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
Ensure this tag exists.
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
If mysql is not currently running, type mysql.server start in terminal
bundle exec rails db:create
bundle exec rails db:migrate
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'
app/assets/stylesheets/application.css
*= require active_scaffold
*= require active_scaffold_export
bundle update webpacker
bundle exec rails s
http://localhost:3000/vehicles
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.