Friday, June 19, 2009

Get month names for the integer

>> Date::MONTHNAMES[1]
=> "January"

some other date methods:
Date::ABBR_DAYNAMES
Date::ABBR_MONTHNAMES
Date::DAYNAMES


Thanks,
sri..

Thursday, June 18, 2009

Adding data in add column

 
Adding data in add column

class AddPeopleSalary < ActiveRecord::Migration
def self.up
add_column :people, :salary, :integer
Person.reset_column_information
Person.find(:all).each do |p|
p.update_attribute :salary, SalaryCalculator.compute(p)
end
end
end

Tuesday, June 9, 2009

Amazon simple Payment in ruby on rails

hi,
Amazon is Doing a great job in rails Payments.
here is the ruby code for generation of button.

require 'base64'
require 'openssl'
module PayNowWidgetUtils
def generate_signed_form(access_key, aws_secret_key, form_params)
form_params['accessKey'] = access_key
str_to_sign = ""
form_params.keys.sort.each { |k| str_to_sign += "#{k}#{form_params[k]}" }
digest = OpenSSL::Digest::Digest.new('sha1')
hmac = OpenSSL::HMAC.digest(digest, aws_secret_key, str_to_sign)
form_params['signature'] = Base64.encode64(hmac).chomp
signed_form =<<-STARTFORM

STARTFORM

form_params.each do |key, value|
next unless key and value
signed_form +=<<-"FORMELEM"
FORMELEM
end

signed_form +=<<-ENDFORM

ENDFORM

return signed_form
end
end

include PayNowWidgetUtils
ACCESS_KEY = 'your amazon aws access key'
SECRET_KEY = 'your amazon aws secret key'
print generate_signed_form(ACCESS_KEY, SECRET_KEY,
'amount' => 'USD 100',
'description' => 'Test Button',
'referenceId' => 'txn1102',
'returnUrl' => 'http://localhost:3000/success',
'abandonUrl' => 'http://localhost:3000/fail')


amazon aws signup..
http://aws.amazon.com/

use a sandbox account for doing test case.