Skip to content

Instantly share code, notes, and snippets.

@TylerLH
Created August 1, 2012 20:17
Show Gist options
  • Save TylerLH/3230339 to your computer and use it in GitHub Desktop.
Save TylerLH/3230339 to your computer and use it in GitHub Desktop.
Trial example URL generation
class Trial < ActiveRecord::Base
TRIAL_TYPES = ["usability","clickmap","interview","survey"]
has_many :stints, :dependent => :nullify
has_many :tasks, :dependent => :destroy
before_validation :generate_access_token
attr_accessible :url, :access_token, :trial_type, :title, :description
validates_presence_of :access_token, :trial_type, :title, :description
validates_uniqueness_of :access_token
accepts_nested_attributes_for :tasks
protected
def generate_access_token
self.access_token = rand(36**8).to_s(36) if self.new_record? and self.access_token.nil?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment