Skip to content

How to install with Rails

Ben Koshy edited this page Oct 16, 2018 · 1 revision
  1. Go to your Gemfile.rb and add the following line:
    gem 'business_time', '~> 0.9.3'
  1. Run bundle install in the terminal, where your rails project resides.

  2. Don't forget to run the generator:

       rails generate business_time:config

This should create the following files:

11:03 $ rails g business_time:config
      Running via Spring preloader in process 14031
      create  config/initializers/business_time.rb
      create  config/business_time.yml

For your own understanding, it is worth having a look in there.

  1. Now you can use it in your controllers. e.g. a 'hello-world test':
class ShiftsController < ApplicationController

  def index
    @beginning_of_month = Time.current.to_date.beginning_of_month
    @end_of_month = Time.current.to_date.end_of_month
    @business_days_in_month = @beginning_of_month.business_days_until(@end_of_month)

    @shifts = Shift.all

    @pagy, @shifts = pagy(@shifts.order(created_at: :desc))
  end
end
Clone this wiki locally