Tuesday, April 16, 2013

Combining many rake tasks into one

namespace :playcricket do
desc 'build legacy data to new'
  task :rebuild_database => ["playcricket:sample1", "playcricket:sample2", "playcricket:sample3"]
 
  desc "first sample task"
  task :sample1 => :environment do
    puts "sample1 executed"
  end
 
  desc "second sample task"
  task :sample2 => :environment do
    puts "sample2 executed"
  end
 
  desc "call another rake task with arguments"
  task :sample3 => :environment do
    puts "sample3 executed"
    Rake::Task["playcricket:sample4"].invoke("333")
  end
 
  desc "rake task with argument"   
  # => sample rake playcricket:sample4["767"]
  task :sample4, [:sg_group_id] => :environment do |t, args|
    puts "Migrating Data"
    puts args[:sg_group_id]
  end

end

Monday, March 18, 2013

Setting up gem aws-sdk to send emails


1) Firstly add  add gem 'aws-sdk', '1.7.0' into your Gemfile
2) Create aws.rb inside initializers and then add valid amazon access key id and secret key  as shown below. (aws.rb)

AWS.config(access_key_id: ENV['ACCESS_KEY_ID'], secret_access_key: ENV['SECRET_ACCESS_KEY'])

3) Add the Setup ACCESS_KEY_ID and SECRET_ACCESS_KEY into your application.yml file

default: &default
  access_key_id: 'your acces key id'
  secret_access_key: 'your secret access key'
development:
  <<: *default
production:
  access_key_id: 'your acces key id'
  secret_access_key: 'your secret access key'
test:
  <<: *default


4) To setup the feature in production mode add the following into your environments/production.rb

config.action_mailer.delivery_method = :amazon_ses
 
 
 
5) To setup in development mode add the following into your environments/development.rb
 
config.action_mailer.delivery_method = :amazon_ses
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
 
 
 
 
6) TO fix the following error (sample)

AWS::SimpleEmailService::Errors::MessageRejected in SessionsController#forgot_password

Email address is not verified.
7) Run the following command in console to verify
a) ses = AWS::SimpleEmailService.new(access_key_id: 'your access key', secret_access_key: 'you secret access key')
b)  ses.identities.verify('email@yourdomain.com'). This is the same from email which you set while sending email. Once you run this command you will receive an email from amazon 

Amazon SES Address Verification Request

One you approve your email then your email feature will start working.