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
.githubfolder for Issues and Pull request templates. - Adding the License, Code of conduct and contributing guidelines.
- Updating the
README.mdfor basic steps and README updates along the way. - Cleaning the
Gemfile, update it and then run:$ bundle i
- Added
badgesto theREADMEfile.
- 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 documentationto.rspec - Rails generators - Not to run helpers generators in
rails gcommand. See commentDon't run un-required generations of filesinconfig/application.rband 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
figarogem and installed it with:$ bundle exec figaro install - Setting up the
config/application-sample.ymlwith initial data. - Rewriting
config/database.ymlfile to use config variables from figaro env variables.
- Added the
-
You must have Ruby version
2.6.5and Rails6.0.2installed. You can install them using GoRails Setup Guide.- You can install Rails
6.0.2with:$ 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.encfile, 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 pressYand then pressEnterto exit thenanoeditor. You don't have to change anything in your credentials, as we usefigarogem 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.ymltoconfig/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_basetoflowers_app - Then, in
config/application.rb, changeLine 9frommodule RailsBasetoFlowersApp.- Remember the app name must be in
PascalCaselike 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_productionto:channel_prefix: flowers_app_production
- In
CONTRIBUTING.mdandREADME.mdfile, change all references ofhttps://github.com/drabkirn/rails_baseto your own GitHub project. You can do this by finding thehttps://github.com/drabkirn/rails_basein these files and replacing it with your repo.- Also change all references of
Drabkirn Rails BaseorRails Baseto 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:3000and 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 generationsof 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/javascriptfolder.
- 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
specfolder. - Add some more badges to your
README.mdfile.
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!
