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
Solution:
 run rake db:migrate
before :
 rails g devise user

Check current environment in Sinatra

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

How to exclude spec folder from test coverage report

   SimpleCov.start do
     add_filter '/spec/'
   end

Reference

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'
ARGV.clear
IRB.start

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

Reference:

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

References:
https://gorails.com/forum/rbenv-bundle-command-not-found
https://gorails.com/setup/osx/10.10-yosemite

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/TextMate.app/Contents/SharedSupport/Support/bin/mate /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:

PROMPT_COMMAND='PS1="[\W]\\$ "'

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';
    src:url('OpenSans-Bold.ttf');
}

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 Jeweler::RubygemsDotOrgTasks.new 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

ISSUE

$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 http://guides.rubygems.org/specification-reference/ for help
  Successfully built RubyGem
  Name: pdf_stamper
  Version: 0.2.0
  File: pdf_stamper-0.2.0.gem

RESOLUTION

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

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";