Friday, April 24, 2015

NoMethodError: undefined method `devise' for User

 Problem: NoMethodError: undefined method `devise' for User (call 'User.connection' to establish a connection):Class
 run rake db:migrate
before :
 rails g devise user

Check current environment in Sinatra

   if Sinatra::Base.development?
     # do something exciting here

How to exclude spec folder from test coverage report

   SimpleCov.start do
     add_filter '/spec/'


Sinatra TDD Tools   

Thursday, April 23, 2015

Upgrading Ruby using rbenv

1. Change the default version of Ruby globally to use 2.2.2

rbenv global 2.2.2

2. Change the ruby version in Gemfile

ruby '2.2.2'

3. gem install bundler

4. bundle

Wednesday, April 22, 2015

Sinatra Console

There is nothing similar to rails console in sinatra. You can go to irb and do a :

require './myapp.rb'

to start experimenting with your Sinatra app.

You can create a console.rb and put the following code:

require './game.rb'
require 'irb'

You now have a simple Sinatra console, you can run it as ruby console.rb.


Sinatra Console

irb history

I installed ruby 2.2.1 using rbenv on Mac OS 10.10.3. By default the irb console does not save the history, so you cannot use the saved code in the history by using the arrows in new irb sessions. To fix this problem, create ~/.irbrc and add this code:

require 'irb/ext/save-history'
#History configuration
IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"

Tuesday, April 21, 2015

Bundler is using a binstub that was created for a different gem.

This is an rvm issue. Suggestions on rvm home page did not work. Solution: Uninstall rvm and use rbenv to manage ruby versions.

Add the following to ~/.bashrc
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
rt PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"

source ~/.bashrc

Say 'Yes' to the prompt.

which bundle showed no output. Run: gem install bundle


Monday, April 20, 2015

Textmate 2 Setup Mate

You may get No such file or directory error when you create the symlink. 

1. Run:
ln -s /Applications/ /usr/local/bin/mate
2. Go to Textmate -> Preferences, click on Terminal tab, click install for 'Shell support'.

Now the mate command will work.

Tuesday, April 14, 2015

short prompt in ubuntu 14.04 terminal

In your ~/.bash_profile add:


Open a new terminal and you should see a small prompt.

Saturday, April 11, 2015

Using Custom Fonts in Rails 4.2

1. For Rails 4.2, copy the custom fonts to the folder app/assets/fonts. I am using the purchased fonts OpenSans.

2. Declare your font in your css file like this:

@font-face {
    font-family: 'OpenSans-Bold';

3. Use the declared font in css. For example:

font-family: 'OpenSans-Regular'

4. Add gem 'font-awesome-sass' to Gemfile

5. Run bundle intall

6. In application.scss, add:

@import "font-awesome-sprockets";
@import "font-awesome";

Sunday, April 05, 2015

Using Jeweler to Create Ruby Gems

1. gem install jeweler
2. jeweler gem-name
3. bundle install
4. rake version:write MAJOR=0 MINOR=1 PATCH=0
5. git remote rm origin
Jeweler automatically creates a git repo
6. Open the Rakefile and customize the gem details.
I changed the default github repo URL to bitbucket repo URL
7. git remote add origin bitbucket-url
8. Delete the line to prevent accidental release to Gemcutter.
9. rake gemspec
10. rake build to create the .gem file that can be used with any project.

pessimistic dependency may be overly strict


$rake build
WARNING:  pessimistic dependency on jeweler (~> 2.0.1, development) may be overly strict
  if jeweler is semantically versioned, use:
    add_development_dependency 'jeweler', '~> 2.0', '>= 2.0.1'
WARNING:  See for help
  Successfully built RubyGem
  Name: pdf_stamper
  Version: 0.2.0
  File: pdf_stamper-0.2.0.gem


group :development do
  gem "rdoc", "~> 3.12"
  gem "bundler", "~> 1.0"
  gem "jeweler", "~> 2.0"

Now you can build the gem file:

 $rm -rf pkg
 $rake build
  Successfully built RubyGem
  Name: pdf_stamper
  Version: 0.2.0
  File: pdf_stamper-0.2.0.gem

Saturday, April 04, 2015

Twitter Bootstrap 3.3.4 on Rails 4.2.1

1. Add : gem 'bootstrap-sass', '~> 3.3.4' to Gemfile.
2. Run bundle
3. Rename application.css to application.scss
4. Copy this to application.scss

// "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"
@import "bootstrap-sprockets";
@import "bootstrap";