This repository serves as a base repository for new projects in rails that we build at Drabkirn
We don't like building up the same rails project that we spin up for each new project that we build. So we made this template, where the defaults are set so we can prototype our ideas as fast as we can, then build the big picture of the project.
-
Basic Setup:
- New Rails Application:
$ rails new bare_rails -d mysql
- Adding the
.github
folder for Issues and Pull request templates. - Adding the License, Code of conduct and contributing guidelines.
- Updating the
README.md
for basic steps and README updates along the way. - Cleaning the
Gemfile
, update it and then run:$ bundle i
- Added
badges
to theREADME
file.
- New Rails Application:
-
Adding Testing support:
- Added latest versions of
brakeman
,bundler-audit
,database_cleaner
,simplecov
,shoulda-matchers
,rails-controller-testing
,rspec-rails
,factory_bot_rails
,faker
. Then run:$ bundle i
- Install Rspec:
$ rails g rspec:install
- Add
--format documentation
to.rspec
- Rails generators - Not to run helpers generators in
rails g
command. See commentDon't run un-required generations of files
inconfig/application.rb
and uncomment required stuff as required. - In
spec/rails_helper.rb
- Added Simplecov, database cleaner, shoulda-matchers and FactoryBot:# Simple Cov ... # DB Cleaner ... # Shoulda Matchers ... # Include Factory Girl syntax to simplify calls to factories ...
- Added latest versions of
-
Environment variables and Database support:
- Added the
figaro
gem and installed it with:$ bundle exec figaro install
- Setting up the
config/application-sample.yml
with initial data. - Rewriting
config/database.yml
file to use config variables from figaro env variables.
- Added the
-
You must have Ruby version
2.6.5
and Rails6.0.2
installed. You can install them using GoRails Setup Guide.- You can install Rails
6.0.2
with:$ gem install rails -v 6.0.2
- This repo uses MySQL as it's database. You can install it from above GoRails guide.
- That's it, prequisites are now installed.
- You can install Rails
-
Clone the Repo:
$ git clone https://github.com/drabkirn/rails_base.git
-
Install dependencies:
$ cd rails_base $ bundle i $ yarn install --check-files
-
Rails Crendentials setup:
- There is a
config/credentials.yml.enc
file, but this repo doesn't have themaster.key
, so delete this file:$ rm config/credentials.yml.enc
- Create your new rails credentials:
$ EDITOR=nano rails credentials:edit
- Then press
ctrl + X
, then pressY
and then pressEnter
to exit thenano
editor. You don't have to change anything in your credentials, as we usefigaro
gem for our credentials. Rails credentials is only needed forsecret_key_base
- There is a
-
Setting up figaro and Database setup:
- Copy the
config/application-sample.yml
toconfig/application.yml
$ cp config/application-sample.yml config/application.yml
- Then in your
config/application.yml
, add all your database configuration. For example:development: db_hostname: "localhost" db_username: "root" db_password: "12345678" db_name: "flowers_app_development"
- Then setup the database:
$ rails db:create $ rails db:migrate
- Copy the
-
Change the name of the Rails App:
- Let's say your project name is
flowers_app
. - First, rename this folder from
rails_base
toflowers_app
- Then, in
config/application.rb
, changeLine 9
frommodule RailsBase
toFlowersApp
.- Remember the app name must be in
PascalCase
like above.
- Remember the app name must be in
- In
package.json
, change the name to:"name": "flowers_app",
- In
config/cable.yml
, changechannel_prefix: rails_base_production
to:channel_prefix: flowers_app_production
- In
CONTRIBUTING.md
andREADME.md
file, change all references ofhttps://github.com/drabkirn/rails_base
to your own GitHub project. You can do this by finding thehttps://github.com/drabkirn/rails_base
in these files and replacing it with your repo.- Also change all references of
Drabkirn Rails Base
orRails Base
to your app name.
- Also change all references of
- Let's say your project name is
-
Test it:
- Run the rails server:
$ rails server
- Now visit
http://localhost:3000
and you should see default Rails page.
- Run the rails server:
-
Next steps:
- Now you can proceed build your app.
- If you want to use React(or any other JS library) as front-end, then:
- you'll need to disable
rails generations
of assets and templates inconfig/application.rb
. Just un-comment below lines:g.assets false g.template_engine false
- Run the command:
$ rails webpacker:install:react
- Then build your front-end in
app/javascript
folder.
- you'll need to disable
- You can start by running a scaffold:
$ rails g scaffold Artile title:string body:text
- Then Consider writing tests in
spec
folder. - Add some more badges to your
README.md
file.
If you would like to contribute, please check this contributing guide
Please check this Code of Conduct guide before contributing or having any kind of discussion(issues, pull requests etc.) with the Bare Rails project!
Need any help? Have any Questions? Or just say us hi!