Wednesday, March 19, 2008

Password Validation

From: here
  • Users must supply a passphrase when signing up
  • Passphrases should be between 8 and 64 characters in length
  • It is not necessary to supply a passphrase when updating an existing record
  • Confirmation must be supplied when setting a new passphrase on an existing record

These requirements lead to the following validations:


  MINIMUM_PASSPHRASE_LENGTH     = 8
MAXIMUM_PASSPHRASE_LENGTH = 64

validates_presence_of  :passphrase,
 :on => :create
validates_length_of  :passphrase,
 :in => MINIMUM_PASSPHRASE_LENGTH..MAXIMUM_PASSPHRASE_LENGTH,
 :if => Proc.new { |u| !u.passphrase.blank? }
validates_confirmation_of  :passphrase,
 :if => Proc.new { |u| !u.passphrase.blank? }

Tuesday, March 18, 2008

Wma player embedding example


<object id="MediaPlayer" height=50 classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Windows Media Player components..." type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">
<param name="filename" value="http://ws.radley.org.uk/Public/Modern%20Languages/Deutsch/media/AQA_GCSE/AQA%202003%20specimen.wma">
<embed type="application/x-mplayer2" src="http://ws.radley.org.uk/Public/Modern%20Languages/Deutsch/media/AQA_GCSE/AQA%202003%20specimen.wma" name="MediaPlayer" width=600 height=50></embed>
</object>
<p>
Download paper <a href="http://ws.radley.org.uk/Public/Modern%20Languages/Deutsch/media/AQA_GCSE/papers/listen%202003%20spec.pdf" target="_blank">here</a>

Partial syntax

<%= render :partial => "signup_form" %>



This would render "_signupform.html.erb" and pass the instance variable @signup_form in as a local variable account to the template for display.

Monday, March 17, 2008

Ruby if else syntax


print "The variable is " + (var == 10 ? "10″ : "Not 10″)