community engine, S3, Heroku

1) clone the source code from

https://github.com/bborn/ce-heroku

2) build and deploye to heroku

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

example

: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”,
:url=>”:s3_domain_url”,
:default_url=> “:attachment/:id_:style.:extension”,
:support_email => “your@email.com”,

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”

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

Refinery Hosting on Heroku

Prerequisites

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’
end

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

c)
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

source
http://refinerycms.com/guides/getting-started

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
end

3)
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
4)
use IAM user Access Credentials

Reference

1) https://guides.spreecommerce.com/developer/s3_storage.html
2)https://devcenter.heroku.com/articles/paperclip-s3

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 “mvjohn@klairvoynat.com”

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

Host heroku.com
Hostname heroku.com
Port 22
IdentitiesOnly yes
IdentityFile ~/.ssh/seckey
User mvjohn@klairvoynat.com
Host heroku.com
Hostname heroku.com
Port 22
IdentitiesOnly yes
IdentityFile ~/.ssh/id_rsa
User mvjohn@hotmail.com

6) clone the code using either

a) git clone git@heroku.com:your-application.git
b) heroku git:clone -a your-application

 

 

referenc

1) https://help.github.com/articles/generating-ssh-keys
2) http://kb.mediatemple.net/questions/1625/Using+an+SSH+Config+File

 

 

www.klairvoyant.in

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

Ruby Tips

Inject

http://blog.flvorful.com/2010/01/24/a-simple-pattern-for-rubys-inject-method
http://stackoverflow.com/questions/3455627/how-does-this-ruby-injection-magic-work
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.

http://stackoverflow.com/questions/612189/why-are-exclamation-marks-used-in-ruby-methods
http://dablog.rubypal.com/2007/8/15/bang-methods-or-danger-will-rubyist

“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”
else
puts “You gave me #{a} — I have no idea what to do with that.”
end

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”
end

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.
http://stackoverflow.com/questions/7156955/whats-the-difference-between-equal-eql-and

http://stackoverflow.com/questions/948135/how-can-i-write-a-switch-statement-in-ruby
ruby tutorial links

http://www.rubyinside.com/21-ruby-tricks-902.html
http://tryruby.org/
https://www.ruby-lang.org/en/documentation/

 

www.klairvoyant.in

Posted in Ruby | Tagged | Leave a comment

RSpec – doubles stub and mock

doubles

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.
stub

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.

Mocks

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

www.klairvoyant.in

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 ( http://luci.criosweb.ro/riot/ ) it’s work with windows only
6) Minfy CSS  (http://www.freeformatter.com/css-minifier.html )

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”
reference

https://devcenter.heroku.com/articles/rails-unicorn
https://devcenter.heroku.com/articles/using-amazon-cloudfront-cdn-with-rails
http://www.codebeerstartups.com/2013/04/enable-gzip-compression-for-rails-3-dot-2-on-heroku-cedar/
http://developers.google.com/speed/pagespeed/insights/

more performance checking tools

1) http://tools.pingdom.com/fpt/
2) http://www.webpagetest.org/
3) http://gtmetrix.com/

http://www.klairvoyant.in/

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

Bootstrap 3 with Rails 4

Refer the blog

http://www.erikminkel.com/2013/09/01/twitter-bootstrap-3-in-a-rails-4-application/
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/

Reference

1) http://stackoverflow.com/questions/18371318/installing-bootstrap-3-on-rails-app/18371521#18371521

http://www.klairvoyant.in/

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/
example:-lib/tasks/mytask.rake

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)

end
end

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
end

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
http://jasonseifer.com/2010/04/06/rake-tutorial
http://blog.jayfields.com/2006/11/ruby-testing-rake-tasks.html
http://lukaszwrobel.pl/blog/rake-tutorial
http://railsguides.net/2012/03/14/how-to-generate-rake-task/
csv reference

http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV.html

 

www.klairvoyant.in

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>’ + ta.task.name + ‘</ul>’);
}

Reference

1) http://railscasts.com/episodes/348-the-rails-api-gem?view=asciicast
2) https://github.com/rails-api/rails-api
3) http://davidsulc.com/blog/2011/04/10/implementing-a-public-api-in-rails-3/

 

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

Reference

1)http://railscasts.com/episodes/352-securing-an-api?view=asciicast

http://www.klairvoyant.in

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