How to add custom fonts to the Rails Application

Steps to add custom fonts to rails

1. Search and Download your prefered fonts from any website. I prefer google fonts.

2. Move the download files to your rails application’s vendor folder. i.e vendor/assets/fonts

3. Add following configuration to fileconfig/application.rb.

config.assets.paths << Rails.root.join('vendor', 'assets', 'fonts')
config.assets.precompile << /\.(?:svg|eot|woff|ttf)$/

4. Link all your fonts and font types into rails application. Add following lines to your CSS file.

@font-face {
font-family: 'SourceSansPro';
src: url('SourceSansPro/SourceSansPro-Regular.ttf') format('truetype');
src: url('SourceSansPro/SourceSansPro-Bold.ttf') format('truetype');
src: url('SourceSansPro/SourceSansPro-Italic.ttf') format('truetype');
}

5. Now you can use the above-declared @font-face in our CSS file using the below code.

#invoice-wrapper {
font-family: 'SourceSansPro';
}

Quick Info

  • url of the declarationfont-face should exist in your foldervendor/assets/fonts.
  • font-family of the isfont-face the name of your font which you should use in the CSS file.
  • During assign font in CSS, the font-family should be same as decorated in @font-face

Ruby program for Happy and Unhappy(sad) Numbers

Description

As per Wiki, 

Happy Number – A happy number is a number defined by the following process: Starting with any positive integer, replace thenumber by the sum of the squares of its digits, and repeat the process until the number either equals 1 (where it will stay), or it loops endlessly in a cycle that does not include 1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100..

Sad Number – An unhappy number is a number that is not happy, i.e., a number such that iterating this sum-of-squared-digits map starting with never reaches the number 1. The first few unhappy numbers are 2, 3, 4, 5, 6, 8, 9, 11, 12, 14, 15, 16, 17, 18…

Program

Output

Case 1

Enter the number:
10
Happy

Case 2

Enter the number:
18
Sad