Custom Rails Validation (Doesn't seem to be working)

Posted by Karl Entwistle on Stack Overflow See other posts from Stack Overflow or by Karl Entwistle
Published on 2010-06-07T13:56:51Z Indexed on 2010/06/07 14:02 UTC
Read the original article Hit count: 175

Filed under:
|
|

Hey guys ive got the following Model for Accounts

require 'net/http'
require 'uri'
require 'date'

class Account < ActiveRecord::Base
validates_presence_of :username, :password, :on => :update
validate :valid_expiry_date, :on => :update  

def valid_expiry_date
   reply = Net::HTTP.get URI.parse("http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=getaccountdetails_v1&type=prem&login=" + username + "&password=" + password)
   account = Time.at(reply[80..90].to_i)

   if (Time.now + 2419200) <= account
     return true      
   else
     return false
     errors.add_to_base("Sorry this account isnt valid") 
   end
 end
end

I know the code works in a ruby.rb file and will return true or false, however I seem to be having rather a lot of difficultly trying to translate this code into an actual validation, any help would be much appreciated. Thanks :)

Its also defiantly at least connecting to the website as my firewall asked me if the Terminal was aloud to access it.

At the moment not only is it displaying no errors its actually letting anything through and saving it.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby