code
stringlengths
1
1.73M
language
stringclasses
1 value
## blat = ARGV[0] targeted = ARGV[1] $gray = 200 $ranges = {} File.new(targeted, 'r').each do |line| if line=~ /^(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)/ tag, chr, offset, s,e =$1, $2, $3.to_i, $4.to_i, $5.to_i ref = "chr" + chr $ranges[ref] = [] unless $ranges.key?(ref) $ranges[ref] << Range.ne...
Ruby
## model: ## the duplicated regions must have: ## 1. significantly higher coverage than average ## 2. increase of "heterozygosity", i.e., the ratio of SNP reads / coverage is lower; ## 3. heterogenity of reads: the reads show SNPs have overall higher mismatch rate ## 4. tails class Snp attr_accessor :chr,...
Ruby
## $chromosome_change={"M"=>"DDB0169550","2F"=>"DDB0215018", "BF"=>"DDB0220052", "3F"=>"DDB0215151", "1"=>"DDB0232428", "2"=>"DDB0232429","3"=>"DDB0232430", "4"=>"DDB0232431", "5"=>"DDB0232432", "6"=>"DDB0232433"} while line = ARGF.gets do cols = line.split(/\s+/) chr = cols[2] if $chromosome_change.key...
Ruby
## compute correlation coefficient between two lists of genes # pseudo-code: # sum_sq_x = 0 # sum_sq_y = 0 # sum_coproduct = 0 # mean_x = x[1] # mean_y = y[1] # for i in 2 to N: # sweep = (i - 1.0) / i # delta_x = x[i] - mean_x # delta_y = y[i] - mean_y # sum_sq_x += delta_x * delta_x * sweep # sum_sq_y...
Ruby
## given a SNP list from the whole genome and targeted genomic region, grab all the SNPs in the targeted region ## sorry, the format now is specifically for Dicty require 'getoptlong' opts = GetoptLong.new( ["--input", "-i", GetoptLong::REQUIRED_ARGUMENT], ["--target", "-t", GetoptLong::REQUIRED_ARGUMENT],...
Ruby
## limit the length of each line to 80 input = ARGV[0] output = input + '.mod.fa' $fin = File.new(input, 'r') $fout = File.new(output, 'w') def format(seq) return if seq == '' s = seq.size 0.upto(s/80) do |i| $fout.syswrite(seq[i*80..(i+1)*80-1] + "\n") # $fout.syswrite(seq.slice!(0,80) + "\n") end...
Ruby
## call genotype after determine het_hom while line=ARGF.gets do cols=line.split(/\s+/) if cols[9].to_f >= cols[5].to_f*0.9 # or cols[-1].to_f <0.01 # homo gt = "#{cols[6]}#{cols[6]}" else # het ref = cols[2].upcase gt = [ref, cols[6]].sort.join() end puts "#{line.chomp}\t#{gt}" end
Ruby
## convert encode info to a format that can be used for atlas-mapper-coverage.rb # original format: # ENm010 7 200000 27124046 27224045 BCM Old HOXA_cluster # target format: # target_name reference_name start_on_ref end_on_ref direction(1 or -1) while line=ARGF.gets do cols = line.s...
Ruby
# simulate shotgun reads from reference genomes require 'getoptlong' opts = GetoptLong.new( ["--input", "-i", GetoptLong::REQUIRED_ARGUMENT], ["--coverage", "-c", GetoptLong::REQUIRED_ARGUMENT], ["--readSize", "-s", GetoptLong::OPTIONAL_ARGUMENT], ["--fixedSize", "-f", GetoptLong::OPTIONAL_ARGUMENT], ["--help", ...
Ruby
## OLD: minor allele >20 % --> heterozygous SNP ## NEW: based on probability from binomial distribution # Null hypothesis: the SNP is heterozygous, alterative: the SNP is homozygous. ## suggest Cutoff value: if Pr < 0.02, reject the null hypothesis ==> the SNP is homozygous. def factorial(k) if k <= 1 return...
Ruby
## # input format: # ENm010 1955 9 chr7 27126000 def mean(a) return -1 if a.size == 0 t = 0 a.map {|i| t+= i} return t/a.size.to_f end pqueue = [] cqueue = [] while line = ARGF.gets do cols = line.split(/\s+/) name, pos, cov, chr, gpos = cols[0], cols[1].to_i, cols[2].to_i, cols[3...
Ruby
## given a SNP list from the whole genome and targeted genomic region, grab all the SNPs in the targeted region snplist = ARGV[0] targeted = ARGV[1] $gray = 200 $ranges = {} File.new(targeted, 'r').each do |line| if line=~ /^(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)/ tag, chr, offset, s,e =$1, $2, $3.to_i, $4.to_i...
Ruby
## realcc = ARGV[0] simufof = ARGV[1] hash = {} avgs = {} File.new(simufof, 'r').each do |line| if line=~/^(\S+)/ ff = $1 File.new(ff,'r').each do |j| if j=~ /^(\S+)\s+(\S+)\s+(\d+)/ gene, cc, ss = $1, $2, $3.to_i if cc != 'NaN' hash[gene] = [] unless hash.key?(gene) ...
Ruby
# format reference sequence: # 1. generate ooc file for BLAT # 2. divide reference sequences into 100K overlapping pieces ## TODO: # 1. consider circular genomes (microbes) # Done 2. [perhaps] split huge genomes, such human genome,into smaller pieces for blat, in order to run BLAT with <=2G RAM. require 'getoptlong' ...
Ruby
require 'getoptlong' opts = GetoptLong.new( ["--source", "-s", GetoptLong::REQUIRED_ARGUMENT], ["--list", "-l", GetoptLong::OPTIONAL_ARGUMENT], ["--name", "-n", GetoptLong::OPTIONAL_ARGUMENT], # ["--qual", "-q", GetoptLong::NO_ARGUMENT], ["--output", "-o", GetoptLong::OPTIONAL_ARGUMENT], ["--he...
Ruby
require 'zlib' blatResult = ARGV[0] $reads = {} def processLine(line) cols = line.split(/\s+/) return if cols.size < 18 hit = {} hit[:match], qgap,tgap,dir, query,qsize,hit[:qstart],hit[:qend],hit[:target],hit[:tsize],hit[:tstart],hit[:tend],hit[:blocks] =cols[0].to_i,cols[5].to_i,cols[7].to_i,cols[8],col...
Ruby
## call genotypes at SNP sites based on Maximum Likelihood. # the paramemter in question is the genotype. require 'getoptlong' opts = GetoptLong.new( ["--snp", "-s", GetoptLong::REQUIRED_ARGUMENT], ["--hapmap", "-m", GetoptLong::OPTIONAL_ARGUMENT], ["--help", "-h", GetoptLong::NO_ARGUMENT] ) optHash = {...
Ruby
## try to model the accurary of SNPs reported by single reads snplist = ARGV[0] # xm = ARGV[1] transition = {'C' => 'T', 'A' => 'G', 'T' => 'C', "G" => 'A'} snps = {} num = 0 # count the occurence of homo-polymer runs in a short sequence def homocount(str) s = str.size lasts = '' homo = {} st = 0 flag ...
Ruby
## convert into a format that can be used by R to do glm or support vector machine # features: # 1. homopolymer size # 2. original quality score # 3. distance to 3' end # 4. basechange type # todo: # upstream or downstream of homopolymer? ## base swap (consecutive or 1bp apart)? trueS = ARGV[0] falseS ...
Ruby
## str = [] n = 0 while line = ARGF.gets do if line=~ /^(\d+)\s+/ s = $1.to_i if s > n # choose one puts str.sort_by {rand}[0] n = s str = [] end str << line.chomp end end
Ruby
## input: cross_match -discrep_lists output # note: this is for one-block alignment only # ignoring 1bp indels class Indel attr_accessor :ref, :query, :tstart, :tend, :qstart, :qend, :dir,:sub, :dels,:ins,:envs, :type def initialize(query, ref, qstart, qend, tstart, tend, dir,sub,dels,ins,l,envs,type) @q...
Ruby
## try to model the accurary of SNPs reported by single reads snplist = ARGV[0] # xm = ARGV[1] transition = {'C' => 'T', 'A' => 'G', 'T' => 'C', "G" => 'A'} snps = {} num = 0 # count the occurence of homo-polymer runs in a short sequence def homocount(str) s = str.size lasts = '' homo = {} st = 0 flag ...
Ruby
# distribute the reads in a top-down fashion fa = ARGV[0] blatB = ARGV[1] File.new(blatB, 'r').each do |line|
Ruby
## for longer homopolymer runs, make the first and last bases be the lowest quality fa = ARGV[0] qual = ARGV[1] $order= [] $reads = {} name = '' File.new(fa, 'r').each do |line| if line=~ /^>(\S+)/ name = $1 $reads[name] = {} $order << name $reads[name][:desc] = line.chomp $reads[name][:s...
Ruby
refList = ARGV[0] File.new(refList, 'r').each do |line| if line=~ /^(\S+)/ ref = $1 cmd = "time ruby ~/work/ruby/atlas-snp/atlas-mapper.rb -r #{ref} -q div_9.fa -z" system(cmd) end end
Ruby
## compare SNP calls with Affy data class Affy attr_accessor :ref, :pos, :genotype, :alleles, :rs def initialize(ref,pos,rs, gtype,alleles) @ref, @pos, @genotype, @alleles,@rs = ref, pos, gtype, alleles,rs end end require 'getoptlong' opts = GetoptLong.new( ["--affy", "-a" , GetoptLong::REQUIRED_AR...
Ruby
## fa = ARGV[0] ss = ARGV[1].to_i pp = ARGV[2] flags = {} files = [] num = 1 fo = pp+'_'+num.to_s+ '.fa' fout = File.new(fo, "w") files << fo seq = 0 File.new(fa,'r').each do |line| if line=~ /^>(\S+)/ name = $1 if seq >= ss flags[name] = 1 seq = 0 fout.close num += 1 fo ...
Ruby
## draw random 13-bp windows from the genome, to simulate "random" env for
Ruby
## input: cross_match -discrep_lists output # limitations: ## 1. cross_match one-block alignment only # 2. ignoring 1bp indels by default # the quality of the indel: # the accuracy of the gap size is important, therefore the quality of indels should reflect the confidence of the gap size require 'getoptlong'...
Ruby
## prefix = ARGV[0] # prefix of output ref = ARGV[1] # reference .bfa file maps = ARGV[2..-1].join("\t") ## all the .map files, DIR/s*.map would do # puts maps # merge all .map files system("maq mapmerge #{prefix}.map #{maps}") # assemble system("maq assemble #{prefix}.cns #{ref} #{prefix}.map 2> #{prefix}.c...
Ruby
$maq = File.expand_path(`which maq`.chomp) require 'getoptlong' def main optHash = getoptions() if optHash.key?("--help") help() exit end dir = optHash["--dir"] ref = optHash["--ref"] flag = 1 log = "Maq.log" maxMismatch = 3 maxDist = 250 ## pe = findPairedEnds(dir) pairedEndMapping(di...
Ruby
# Author: Yufeng "Joshua" Shen # split Solexa fastq into batches, each with 4 million lines # (thus 1 million reads) require 'getoptlong' $maq = '' def main # logic of the program maq = tryMaq() if (maq == false) exit else $maq = File.expand_path(maq) end optHash = getOptions() ## "--inputDir"...
Ruby
# Author: Yufeng "Joshua" Shen # convert solexa export file to fastq, and split into batches, each with 4 million lines # (thus 1 million reads) require 'getoptlong' $maq = '' def main # logic of the program maq = tryMaq() if (maq == false) exit else $maq = File.expand_path(maq) end optHash = ...
Ruby
#!/usr/bin/env ruby homeDir=Dir.pwd #$stderr.puts homeDir #homeDir=File.dirname(File.expand_path($1)) $stderr.puts homeDir outputDir=homeDir+'/output/' concensusDir=homeDir+'/consensus/' inputDir=homeDir+'/input/' parDir=homeDir+'/par/' refDir=homeDir+'/references/' #refDir=homeDir+'/references/' file_pa...
Ruby
require 'getoptlong' require 'bigdecimal' #Program overview # 'atlasSNPEvaluate.rb' is used to evalute substitutions by looking at the posterior probability of # a substitution site to be a true SNP (Posterior(SNP|Sj,Cov)j), which is appended in the last column of the output. # #Baysian's framework # P...
Ruby
#!/usr/bin/env ruby require 'getoptlong' require 'bigdecimal' opts = GetoptLong.new( ["--input", "-i", GetoptLong::REQUIRED_ARGUMENT] ) optHash = {} opts.each do |opt, arg| optHash[opt] = arg end homeDir=Dir.pwd outputDir=homeDir+'/output/' file_name=File.basename(optHash["--input"]) file_pat...
Ruby
## parse gff or gtf file # description of gff format: http://www.sanger.ac.uk/Software/formats/GFF/GFF_Spec.shtml # gtf: http://mblab.wustl.edu/GTF2.html ## <seqname> <source> <feature> <start> <end> <score> <strand> <frame> [attributes] [comments] # DDB0232428 . gene 238722 242663 . + ...
Ruby
# do blat and cross_match require 'getoptlong' opts = GetoptLong.new( ["--reference", "-r", GetoptLong::REQUIRED_ARGUMENT], ["--query", "-q", GetoptLong::REQUIRED_ARGUMENT], # ["--output", "-o", GetoptLong::OPTIONAL_ARGUMENT], ["--minscore", "-m", GetoptLong::OPTIONAL_ARGUMENT], ["--cutoff", "-c", Ge...
Ruby
# do blat and cross_match require 'getoptlong' opts = GetoptLong.new( ["--reference", "-r", GetoptLong::REQUIRED_ARGUMENT], ["--query", "-q", GetoptLong::REQUIRED_ARGUMENT], # ["--output", "-o", GetoptLong::OPTIONAL_ARGUMENT], ["--minscore", "-m", GetoptLong::OPTIONAL_ARGUMENT], ["--cutoff", "-c", Ge...
Ruby
# format reference sequence: # 1. generate ooc file for BLAT # 2. divide reference sequences into 100K overlapping pieces ## TODO: # 1. consider circular genomes (microbes) # 2. [perhaps] split huge genomes, such human genome,into smaller pieces for blat, in order to run BLAT with <=2G RAM. require 'getoptlong' opts...
Ruby
# input: cross_match -discrep_lists output and the reference sequence # output: 1. SNP list with useful information # 2. a quality-like file storing coverage on each base of reference # some part modified from Lei Chen's program # only do substitutions require 'getoptlong' opts = GetoptLong.new( ["--cros...
Ruby
# do blat and cross_match require 'getoptlong' opts = GetoptLong.new( ["--reference", "-r", GetoptLong::REQUIRED_ARGUMENT], ["--query", "-q", GetoptLong::REQUIRED_ARGUMENT], # ["--output", "-o", GetoptLong::OPTIONAL_ARGUMENT], ["--minscore", "-m", GetoptLong::OPTIONAL_ARGUMENT], ["--cutoff", "-c", Ge...
Ruby
# Copyright © 2010, EMC Corporation. # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: # # + Redistributions of source code must retain the above copyright notice, # this list of conditions and the following dis...
Ruby
require 'rubygems' require 'rake/testtask' require 'rake/gempackagetask' task :default => [:gem] spec = Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.summary = "Ruby API wrapper for EMC Atmos" s.name = 'atmos-ruby' s.version = "1.4.0.7" s.homepage = "http://code.google.com/p/atmos-ruby" ...
Ruby
# Copyright © 2010, EMC Corporation. # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: # # + Redistributions of source code must retain the above copyright notice, # this list of conditions and the following dis...
Ruby
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel...
Ruby
class CreateArticles < ActiveRecord::Migration def change create_table :articles do |t| t.string :title t.text :text t.timestamps null: false end end end
Ruby
ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all # Add more helper methods to be used by all tests here... end
Ruby
source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.0' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use Cof...
Ruby
module WelcomeHelper end
Ruby
module ApplicationHelper end
Ruby
module ArticlesHelper end
Ruby
class Article < ActiveRecord::Base validates :title, presence: true, length: { minimum: 5 } end
Ruby
class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception end
Ruby
class WelcomeController < ApplicationController def index end end
Ruby
class ArticlesController < ApplicationController def index @articles = Article.all end def show @article = Article.find(params[:id]) end def new end def edit end def create @article = Article.new(article_params) @article.save redirect_to @article end def update end def destroy end...
Ruby
# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: # ActiveSupport::Inflector.inflections(:en) do |inflec...
Ruby
# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a probl...
Ruby
# Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters f...
Ruby
# Be sure to restart your server when you modify this file. Rails.application.config.action_dispatch.cookies_serializer = :json
Ruby
# Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. Rails.application.config.assets.version = '1.0' # Add additional assets to the asset load path # Rails.application.config.assets.paths << Emoji.images_path # Precompile additional ...
Ruby
# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf
Ruby
# Be sure to restart your server when you modify this file. Rails.application.config.session_store :cookie_store, key: '_blog_session'
Ruby
# Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. Rails.application.config.filter_parameters += [:password]
Ruby
Rails.application.routes.draw do get 'welcome/index' resources :articles # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". # You can have the root of your site routed with "root" root 'welcome#index' # Example of ...
Ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' # Set up gems listed in the Gemfile.
Ruby
require File.expand_path('../boot', __FILE__) require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module Blog class Application < Rails::Application # Settings in config/environments/* take preceden...
Ruby
# Load the Rails application. require File.expand_path('../application', __FILE__) # Initialize the Rails application. Rails.application.initialize!
Ruby
Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web serve...
Ruby
Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web serv...
Ruby
Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suit...
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Rails.application
Ruby
# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) Rails.application.load_tasks
Ruby
# $ext_path: This should be the path of where the ExtJS SDK is installed # Generally this will be in a lib/extjs folder in your applications root # <root>/lib/extjs $ext_path = "../../" # sass_path: the directory your Sass files are in. THIS file should also be in the Sass folder # Generally this will be in a resource...
Ruby
# include the utils rb file which has extra functionality for the ext theme dir = File.dirname(__FILE__) require File.join(dir, 'lib', 'utils.rb') # register ext4 as a compass framework Compass::Frameworks.register 'ext4', dir
Ruby
# $ext_path: This should be the path of where the ExtJS SDK is installed # Generally this will be in a lib/extjs folder in your applications root # <root>/lib/extjs $ext_path = "../../lib/extjs" # sass_path: the directory your Sass files are in. THIS file should also be in the Sass folder # Generally this will be in a...
Ruby
module ExtJS4 module SassExtensions module Functions module Utils def parsebox(list, n) assert_type n, :Number if !n.int? raise ArgumentError.new("List index #{n} must be an integer") elsif n.to_i < 1 raise ArgumentError.new("List index #{n} must...
Ruby
# Add new inflection rules using the following format # (all these examples are active by default): # Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end
Ruby
# Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register "application/x-mobile", :mobile
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Use a different logger for distributed setups # config.logger = SyslogLogger.new # Full error repor...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.ca...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between...
Ruby
# Be sure to restart your web server when you modify this file. # Uncomment below to force Rails into production mode when # you don't control web/app server and can't set it the proper way # ENV['RAILS_ENV'] ||= 'production' # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION ...
Ruby
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) unless defined?(Rails::Initializer) if File.directory?("#{RAILS_ROOT}/vendor/rails") require "#{RAILS_ROOT}/vendor/rails/railties/lib/init...
Ruby
ActionController::Routing::Routes.draw do |map| map.resources :interests, :member => {:order => :post} map.resources :conferences map.resources :users map.resource :sessions # The priority is based upon order of creation: first created -> highest priority. # Sample of regular route: # map.connect 'pr...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper end
Ruby
module UsersHelper end
Ruby
module SessionsHelper end
Ruby
module ConferencesHelper end
Ruby
module InterestsHelper end
Ruby
class Conference < ActiveRecord::Base has_many :interests, :dependent => :destroy end
Ruby
require 'digest/sha1' class User < ActiveRecord::Base has_many :interests, :order => 'position' has_many :conferences, :through => :interests, :order => 'position' # Virtual attribute for the unencrypted password attr_accessor :password validates_presence_of :login, :email validates_presence_of ...
Ruby
class Interest < ActiveRecord::Base belongs_to :conference def self.reorder(user, conference_ids) transaction do user.interests.destroy_all conference_ids.each_with_index do |conference_id, n| user.interests.create! :conference_id => conference_id, :position => n+1 end end end...
Ruby
class ConferencesController < ApplicationController before_filter :login_required # GET /conferences # GET /conferences.xml def index @conferences = Conference.find :all @my_conferences = current_user.conferences @conferences = @conferences - @my_conferences respond_to do |format| format...
Ruby
class InterestsController < ApplicationController before_filter :login_required # GET /interests # GET /interests.xml def index @interests = Interest.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @interests } end end # GET /interests/1...
Ruby
# This controller handles the login/logout function of the site. class SessionsController < ApplicationController # Be sure to include AuthenticationSystem in Application Controller instead include AuthenticatedSystem # render new.rhtml def new end def create self.current_user = User.authenticate(pa...
Ruby
# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base helper :all # include all helpers, all the time include AuthenticatedSystem end
Ruby
class UsersController < ApplicationController # render new.rhtml def new end def create @user = User.new(params[:user]) @user.save! self.current_user = @user redirect_back_or_default('/') flash[:notice] = "Thanks for signing up!" rescue ActiveRecord::RecordInvalid render :action => 'n...
Ruby
# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require(File.join(File.dirname(__FILE__), 'config', 'boot')) require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'tasks/rails'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby