Halaman

Rabu, 06 Oktober 2010

[shared] netbeans rails additional code template

Ruby


1. model

#--
# constants
#++

#--
# require
#++

#--
# include
#++

#--
# attr
#++

#--
# extra capabilities
#++

#--
# belongs_to
#++

#--
# has_one
#++

#--
# has_many
#++

#--
# accepts_nested_attributes_for
#++

#--
# validation
#++

#--
# callbacks
#++

#--
# named_scope
#++

#--
# other definition such as alias_method
#++

#--
# public class methods
#++

#--
# public instance methods
#++

private
#--
# private class methods
#++

#--
# private instance methods
#++

protected
#--
# protected class methods
#++

#--
# protected instance methods
#++


2. resource

before_filter :prepare_account, :only => [:show, :edit, :update, :destroy]

# GET new_account_url
def new
# return an HTML form for describing the new account
end

# POST account_url
def create
# create an account
end

# GET account_url
def show
# find and return the account
end

# GET edit_account_url
def edit
# return an HTML form for editing the account
end

# PUT account_url
def update
# find and update the account
unless @account.update_attributes params[:account]
# failure code here..
end
end

# DELETE account_url
def destroy
# delete the account
@account.destroy
end

private

def prepare_account
@account = Account.first
end


3. resources

before_filter :prepare_messages, :only => [:index]
before_filter :prepare_message, :only => [:show, :edit, :update, :destroy]

# GET messages_url
def index
# return all messages
end

# GET new_message_url
def new
# return an HTML form for describing a new message
end

# POST messages_url
def create
# create a new message
end

# GET message_url(:id => 1)
def show
# find and return a specific message
end

# GET edit_message_url(:id => 1)
def edit
# return an HTML form for editing a specific message
end

# PUT message_url(:id => 1)
def update
# find and update a specific message
unless @message.update_attributes params[:message]
# failure code here..
end
end

# DELETE message_url(:id => 1)
def destroy
# delete a specific message
@message.destroy
end

private

def prepare_messages
@messages = Message.all
end

def prepare_message
@message = Message.find params[:id]
end


4. vf

validates_format_of :${1 default="attribute"}


5. vn

validates_numericality_of :${1 default="attribute"}


Ruby HTML (RHTML)


1. script




2. style


Kamis, 30 September 2010

[shared] datejs, impressive js date helpers

http://www.datejs.com/
http://code.google.com/p/datejs/wiki/APIDocumentation

include in rails 2.1+ not always generate single query

"..for some situations, the monster outer join becomes slower than many smaller queries..."

http://akitaonrails.com/2008/05/25/rolling-with-rails-2-1-the-first-full-tutorial-part-2
in Optimized Eager Loading

Kamis, 23 September 2010

[shared] paypal recurring with activemerchant

add this file:
from http://github.com/rayvinly/active_merchant/blob/master/lib/active_merchant/billing/gateways/paypal_express_recurring.rb


read:
- https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_WPRecurringPayments
- and PP_RecurringPaymentsAPI.pdf

Credit Card







allowed credit card type (not all country support all type):
  • Visa
  • MasterCard
  • Discover
  • Amex
  • Maestro
  • Solo


test credit card obtained from:
http://www.darkcoding.net/credit-card-numbers/
you can generate it yourself using MOD 10 algorithm (Luhn formula) or so they said =P
http://www.darkcoding.net/credit-card/luhn-formula/

Error! DPRP is disabled for this merchant ?
- Only US & UK sandbox business accounts can be enabled for WPP
- use preconfigured account using Website Payments Pro
- or read https://www.x.com/docs/DOC-1603

Paypal Account





Additional



ActiveMerchant::Billing::CreditCard patch to support paypal recurring:

libmysql.dll is missing

copy [mysql installation directory]/bin/libmysql.dll to [ruby installation directory]/bin/