community engine, S3, Heroku

1) clone the source code from

2) build and deploye to heroku

3) add addon sendgrid to your application
4)made necessary changes in application_config.rb


:app_host => ‘your hostname’,
:community_name => “your community name”,
:s3_credentials => {
:access_key_id => ENV[“S3_KEY”],
:secret_access_key => ENV[“S3_SECRET”]
:bucket => ENV[‘S3_BUCKET’],

5) add following too application_config.rb

:s3_protocol=> “https”,
:default_url=> “:attachment/:id_:style.:extension”,
:support_email => “”,

6) add configure values

heroku config:set S3_KEY=”your key”
heroku config:set S3_SECRET=”your secret”
heroku config:set S3_BUCKET=”your bucket”

Posted in ruby on rails | Tagged , , , , , , | Leave a comment

Refinery Hosting on Heroku


1) The Ruby language version 1.9.3 or higher
2) A working installation of ImageMagick
1) create a gemset using RVM

rvm use –create ruby-1.9.3@refinery
2)Installing Refinery

gem install refinerycms

3) Creating a Refinery application

refinerycms mycms

4) Starting up the Web Server

cd mycms
rails server

5) make sure to run these rake tasks

rake db:create
rake db:migrate
rake db:seed

6) create firat user

navigate to http://localhost:3000/refinery. You should be greeted with a screen prompting you to create your first Refinery user.
7) Deploying an existing local Refinery application to heroku

a) Update the Gemfile by adding pg gem as follows

group :production do
gem ‘pg’

b) add to git, create and deploy to heroku as follows
git commit -m “setup for Heroku”
heroku create myapp
git push heroku master

make sure you add the following: to config/application.rb
config.assets.initialize_on_precompile = true

d) run these on heroku too

heroku run rake db:migrate
heroku run rake db:seed


Klairvoyant info solutions

Posted in ruby on rails, web development | Tagged , , , , , , , | Leave a comment

configure S3 in spree, Heroku

1) add gem ‘aws-sdk’ and then bundle install.

add to spree.rb located at config/intializers/spree.rb. you don’t want to change anything in this code

attachment_config = {

s3_credentials: {
access_key_id: ENV[‘AWS_ACCESS_KEY_ID’],
secret_access_key: ENV[‘AWS_SECRET_ACCESS_KEY’],
bucket: ENV[‘S3_BUCKET_NAME’]

storage: :s3,
s3_headers: { “Cache-Control” => “max-age=31557600” },
s3_protocol: “https”,
bucket: ENV[‘S3_BUCKET_NAME’],
url: “:s3_domain_url”,

styles: {
mini: “48×48>”,
small: “100×100>”,
product: “240×240>”,
large: “600×600>”

path: “/spree/:class/:id/:style/:basename.:extension”,
default_url: “/spree/:class/:id/:style/:basename.:extension”,
default_style: “product”

attachment_config.each do |key, value|
Spree::Image.attachment_definitions[:attachment][key.to_sym] = value

Additionally, we’ll need to the set the AWS configuration variables on the Heroku application.
$ heroku config:set S3_BUCKET_NAME=your_bucket_name
$ heroku config:set AWS_ACCESS_KEY_ID=your_access_key_id
$ heroku config:set AWS_SECRET_ACCESS_KEY=your_secret_access_key
use IAM user Access Credentials



Posted in ecommerce, web development | Tagged , , , , , , | Leave a comment

heroku add second email

create new public/private key for new email as follows

1) ssh-keygen -t rsa -C “”

2) provide new file name in which to save the key (/home/.ssh/seckey)

3) Then add your new key to the ssh-agent:- ssh-add ~/.ssh/seckey

4) Then add your new key to heroku :- heroku keys:add ~/.ssh/seckey

5) add SSH Config File as ~/.ssh/config and content as follows

Port 22
IdentitiesOnly yes
IdentityFile ~/.ssh/seckey
Port 22
IdentitiesOnly yes
IdentityFile ~/.ssh/id_rsa

6) clone the code using either

a) git clone
b) heroku git:clone -a your-application





Posted in ROR, Ruby, ruby on rails, web development | Tagged , | Leave a comment

Ruby Tips

Exclamation marks (!) with functions

In general, methods that end in ! indicate that the method will modify the object it’s called on. Ruby calls these “dangerous methods” because they change state that someone else might have a reference to.

“Danger” is relative; For example, gsub! is the dangerous version of gsub. exit! is the dangerous version of exit. flatten! is the dangerous version of flatten. And so forth.

in all case ! does not mean that the method changes its receiver.

“case when” and case equality operator (===)

case a
when 1..5
puts “It’s between 1 and 5”
when 6
puts “It’s 6”
when String
puts “You passed a string”
puts “You gave me #{a} — I have no idea what to do with that.”

The comparison is done by comparing the object in the when-clause with the object in the case-clause using the === operator. That is, it does 1..5 === a and String === a
result = case score
when 0..40 then “Fail”
when 41..60 then “Pass”
when 61..70 then “Pass with Merit”
when 71..100 then “Pass with Distinction”
else “Invalid Score”

then keyword following the when clauses can be replaced with a newline or semicolon. Ruby 1.8 also allows a colon in place of then… But this syntax is no longer allowed in Ruby 1.9.
ruby tutorial links

Posted in Ruby | Tagged | Leave a comment

RSpec – doubles stub and mock


when we depend on components with nondeterministic characteristics, we may find that files get corrupted, disk fail, networks time out, and servers go down in the middle of running specs. because these are things that we have no control over, they can lead to inconsistent and surprising results when we run our specs. doubles can disconnect our examples from real implementations of these dependencies.

when the system behaviour based on a sequence. a stub is perfect for this .Because each example can specify a different sequence.example:- In case of random generator, it is clearely a source of non determination. we want to replace the real random generator with stable sequence.


some time we need some service from another object that may not yet exist. In cases like this we can introduce mock object. which we can program to behave as the object we are currently expects. so when we focus on interaction mock objects make it much easier to achieve.


Source: The RSpec Book

Posted in rails, ROR, ruby on rails, testing, web development | Tagged , , , , , | Leave a comment

Heroku application- increase performance – Tips and Tools

1) use unicorn
2) Using Amazon CloudFront CDN with Rails
3) enable gzip compression
4) Use the following browser plugins to check performance issues
a) FireBug
b) page speed insights

5) Optimize Images for the Web ( ) it’s work with windows only
6) Minfy CSS  ( )

7) set max-age

in production.rb set max-age for 3 days( 2419200 seconds)

config.serve_static_assets = true
config.static_cache_control = “public, max-age=2419200”

more performance checking tools


Posted in rails, ROR, ruby on rails, web development | Tagged , , , , , | 1 Comment

Bootstrap 3 with Rails 4

Refer the blog
In the downloaded bootstrap archive you will see a ‘dist’ folder which will house the css, javascripts, and fonts folders we will want to copy to our Rails application vendor/assets/ directory.
bootstrap/dist/css/bootstrap.css and bootstrap/dist/css/bootstrap.min.css to vendor/assets/stylesheets
bootstrap/dist/js/bootstrap.js and bootstrap/dist/js/bootstrap.min.js to vendor/assets/javascripts
bootstrap/dist/fonts/* to vendor/assets/fonts/



Posted in rails, ROR, ruby on rails, web development | Tagged , , , , , , | Leave a comment

Custom rake task

Task to add Indian states to spree database.

1) Add a text file with extension .rake to the folder lib/tasks/

2) add file content as follows

task :add_indian_states=>:environment do
CSV.foreach(“lib/tasks/states.csv”) do | row |
state, abbr = row
Spree::State.create(:name => state,:abbr=> abbr,:country_id=>3)


3) add file “states.csv” to lib/tasks/ with file content as follows

“Andhra Pradesh”,” AP”
“Arunachal Pradesh”,” AR”
“Assam”,” AS”
“Bihar”,” BR”
“Chhattisgarh”,” CT”
“Goa”,” GA”
“Gujarat”,” GJ”
“Haryana”,” HR”
“Himachal Pradesh”,” HP”
“Jammu & Kashmir”,” JK”
“Jharkhand”,” JH”
“Karnataka”,” KA”
“Kerala”,” KL”
“Madhya Pradesh”,” MP”
“Maharashtra”,” MH”
“Manipur”,” MN”
“Meghalaya”,” ML”
“Mizoram”,” MZ”
“Nagaland”,” NL”
“Odisha”,” OR”
“Punjab”,” PB”
“Rajasthan”,” RJ”
“Sikkim”,” SK”
“Tamil Nadu”,” TN”
“Tripura”,” TR”
“Uttarakhand”,” UT”
“Uttar Pradesh”,” UP”
“West Bengal”,” WB”
“Andaman & Nicobar”,” AN”
“Chandigarh”,” CH”
“Dadra and Nagar Haveli”,” DN”
“Daman & Diu”,” DD”
“Delhi”,” DL”
“Lakshadweep”,” LD”
“Puducherry”,” PY”
4) want to add the following to config/application.rb to work with CSV library
require ‘csv’

5) here “country_id=3” denotes INDIA as foreign key.

you can avoid  step 6 in later versions of spree and rails if this raise error

6) you want to make new file state_decorator.rb with the following content to the folder app/models to avoid rails Mass assignment error.

Spree::State.class_eval do
attr_accessible :country_id

7) rake add_indian_states will run the task. ( rails will detect the task name from the file which is the folder lib/tasks)
Rake Reference

railscasts 362
csv reference

Posted in rails, ruby on rails, web development | Tagged , , , , , | 5 Comments

Rails API

1) follow  railcast no:-348

In /public/index.html file

use function addTask as the following way instead of described

function addTask(ta) {
$(‘#tasks’).append(‘<li>’ + + ‘</ul>’);




Securing a API  ( but not find a solution to work with the above API )

1) follow the railcast no:352. it describes

a) Using HTTP Basic Authentication
b) Authentication Via an Access Token



Posted in rails, ROR, ruby on rails, web development | Tagged , , , , , , | 1 Comment