A Basic CMS for a Company Website
- Setup Ruby and Rails
-
Install rbenv and necessary plugins
$ brew install rbenv ruby-build rbenv-binstubs rbenv-gem-rehash
-
If you are using prezto just include ruby module in .zpreztorc file and all are set. If not, add the following line to the end of your .bashrc or .zshrc
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
-
-
Install ruby (this project use version 2.1.0)
-
Install necessary gems
-
Read more here
-
- Install required package and app
-
ImageMagick for handling image resize
$ brew install ImageMagick
-
PostgresSQL
- Install Postgres.app
-
- Setup PostgresSQL user for development
-
Open Postgres.app, click it icon in Mac's menubar and choose open psql. The terminal will open psql command prompt
-
Use the following command to reate a new user with the right to login and create db
CREATE ROLE develop WITH login createdb password '123456';
-
-
Install project's gem dependencies
$ cd $project_path $ bundle install --no-binstubs # Configure bundle to not install binstubs
-
Install necessary binstubs needed in development
$ bundle binstub rspec-core guard thin capistrano spring
- Because we installed the rbenv-binstubs plugin, we don't need to type
bundle exec ...
to use those binstub in our project folder anymore, just type their binstub name and the plugin will handle the rest
- Because we installed the rbenv-binstubs plugin, we don't need to type
-
Use spring to overrider main Rails' binstub (rails, rake, rspec...) to preload Rails environment so that server and test startup take shorter time
$ spring binstub --all
-
Setup initial database for development and test
$ rake db:setup # The above command is the equavalent of the following commands $ rake db:create # create the databse as defined in config/database.yml $ rake db:migrate # migrate data $ rake db:seed # seed initial data if they are defined in db/seeds.rb # create the database and data for testing $ rake test:prepare
-
Run development server and test
# Run server $ rails server # or rails s # Run test (not watching changes) $ rspec # Run test (watching changes) $ guard
- /app - Main project folder for holding the app's main logic
- assets - All css, js, static images go here, rails will monitor all files in this folders and automatic serve them under global namespace assets
- controllers - Controllers for the app, all logic to handle request from client go here
- front - Controllers for the front part
- admin - Controllers for the admin part
- base_controller - Base controller for all controllers in Admin namespace
- ...
- application_controller.rb - Main controller
- views - Views files, all html that render to the client go here *front - Views file for controllers in namespace Front * services - Views file for controller Front::ServicesController * ... *admin - Views file for controllers in namespace Admin
- helpers - Helpers functions for use in views, each controller will have its respective helper *front *admin *application_helper.rb - Main helper for use in all views
- models - ActiveRecord models files, each models => a table in the dtabase
- uploaders *_image_uploader.rb - Carrierwave uploader class, handle uploading image
- mailers - Not using at this time
- /bin - Hold projects and gems's binstubs (rake, rails, bundle, rspec...)
- /config - Main project configuration
- deploy - Capistrano deploy settings for each environment
- environments - Hold settings specific for each environments
- initializers - Hold initials script that will be run when app starts
- locales - Hold locales files, define new locales by adding new .yml file in this folder
- routes.rb - Manage all routes in the app, map route to controller actions
- deploy.rb - Capistrano deployment script, defines capistrano tasks
- application.rb - Default settings
- settings.ym - Our custome settings go here
- ... (Other files not importaint or not in use at this times)
- /db - Hold all database related stuffs, migrations, seeds
- migrate - App's migration files are here
- schema.rb - Auto generated by rails, track all changes to DB
- seeds.rb - Default data to seed to DB
- /lib - Custom library to use in the app
- tasks - Custom tasks to use with Rake
- ... */log */public - Public folders, anything that need to display public go here (imaages, static html...)
- /spec - Tests
- /tmp - Temporary things
- /vendor - 3rd party stuffs
- assets - 3rd party library's asset, Asset Pipeline will also monitor this folder
- Capfile - Capistrano setting
- Guardfile - Guard setting
- Gemfile - Define project's gem dependencies
- ...
-
Main development branch is develop. Branch master is used for deployment (in development can also use develop for deployment)
-
When working in a new feature create a new branch feature_name
$ git checkout -b feature_name
-
After finishing working in this feature, change back to develop, pull any update, merge the feature branch and push to remote repo
$ git checkout develop $ git pull $ git merge feature_name
-
When development a feature_branh, if you want to pull change from the remote repo, use rebase (need revise)
$ git checkout develop $ git pull $ git checkout feature_name $ git rebase develop
-
If there is some changes to the database, migrate the data
$ rake db:migrate
-
Check Caphistrano settings in those files and folder
Capfile
,config/deploy.rb
,config/deploy
-
Use the following command to deploy (can choose the branch to deploy)
$ cap staging deploy # only stating environment is enabled now