Permalink
Browse files

import classes, start of gui

  • Loading branch information...
agrobbin committed Mar 6, 2011
1 parent 48d1822 commit 7045e4e338c8a2c6d8e192ed5195b3101c968cf6
@@ -1,3 +1,5 @@
class ApplicationController < ActionController::Base
+
protect_from_forgery
+
end
@@ -0,0 +1,2 @@
+class CorporateController < ApplicationController
+end
@@ -0,0 +1,2 @@
+class InstitutionsController < SubdomainController
+end
@@ -0,0 +1,16 @@
+class SubdomainController < ApplicationController
+
+ helper_method :current_institution
+
+ before_filter :check_if_institution_exists
+
+ private
+ def current_institution
+ Institution.find_by_subdomain(request.subdomain)
+ end
+
+ def check_if_institution_exists
+ redirect_to root_url(:subdomain => nil) and return if current_institution.nil?
+ end
+
+end
@@ -0,0 +1,2 @@
+module CorporateHelper
+end
@@ -0,0 +1,2 @@
+module InstitutionsHelper
+end
@@ -0,0 +1,2 @@
+module SubdomainHelper
+end
View
@@ -5,6 +5,8 @@ class Section < ActiveRecord::Base
has_many :sectionships
has_many :students, :through => :sectionships
+ serialize :days, Array
+
def semester
"#{semester_season} #{semester_year}"
end
View
@@ -4,9 +4,9 @@ class Upload < ActiveRecord::Base
scope :files, :conditions => "upload_content_type NOT REGEXP '^image\/'"
has_attached_file :upload,
- :styles => { :normal => "250x250>", :normal_square => "250x250#", :thumb => "100x100>", :thumb_square => "100x100#" },
- :url => "/:class/:id/:folders/:substituted_basename.:extension",
- :path => ":rails_root/public/:class/:id/:folders/:substituted_basename.:extension"
+ :styles => { :normal => "250x250>", :thumb => "100x100>" },
+ :url => "/:class/:id/:folders/:sha1d_basename.:extension",
+ :path => ":rails_root/public/:class/:id/:folders/:sha1d_basename.:extension"
belongs_to :user
belongs_to :resource, :polymorphic => true
@@ -0,0 +1,4 @@
+%h1 This is a header.
+%p This is some random text.
+%p This is some random text.
+%p This is some random text.
@@ -3,8 +3,17 @@
%head
%meta{'http-equiv' => 'content-type', :content => 'text/html; charset=utf-8'}/
%link{:rel => 'shortcut icon', :type => 'image/x-icon', :href => '/favicon.ico'}/
- %title UClass.Me
+ %title= "#{current_institution.name} - UClass"
= stylesheet_link_tag 'application'
- = javascript_include_tag :jquery
+ = javascript_include_tag :defaults
= csrf_meta_tag
- %body= yield
+ %body
+ #well
+ #header
+ #institution.left
+ = image_tag 'bryant.png', :class => 'left'
+ %p= "Welcome back, Alex Robbin"
+ %h2= current_institution.name
+ = link_to 'UClass.Me', root_url(:subdomain => nil), :class => 'right', :id => 'uclassme'
+ .clear
+ #content= yield
@@ -2,6 +2,6 @@
"#{attachment.instance.updated_at.to_s(:number)}/#{style_name.to_s.split("_").collect {|w| w.first}}"
end
-Paperclip.interpolates :substituted_basename do |attachment, style_name|
- attachment.original_filename.gsub(/#{File.extname(attachment.original_filename)}$/, "").gsub(/%/, "")
+Paperclip.interpolates :sha1d_basename do |attachment, style_name|
+ Digest::SHA1.hexdigest(attachment.original_filename)
end
@@ -0,0 +1,38 @@
+# Adapted from
+# http://bcardarella.com/post/716951242/custom-subdomains-in-rails-3
+# Brian Cardarella 19 June 2010
+
+class Subdomain
+
+ def self.matches?(request)
+ case request.subdomain
+ when 'www', 'development', '', nil
+ false
+ else
+ true
+ end
+ end
+
+end
+
+module ActionView
+ module Helpers
+ module UrlHelper
+
+ def url_for(options = {})
+ if options.is_a?(Hash) && options.has_key?(:subdomain)
+ subdomain = options.delete(:subdomain)
+ subdomain ||= 'development' if Rails.env == 'development'
+ options[:host] = if subdomain.nil?
+ request.host_with_port.sub("#{request.subdomain}.", '')
+ else
+ request.subdomain.empty? ? "#{subdomain}.#{request.host_with_port}" : request.host_with_port.sub(request.subdomain, subdomain)
+ end
+ end
+
+ super
+ end
+
+ end
+ end
+end
View
@@ -1,4 +1,11 @@
Uclassme::Application.routes.draw do
+
+ constraints(Subdomain) do
+ root :to => "institutions#index"
+ end
+
+ root :to => "corporate#index"
+
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -1,9 +1,10 @@
class CreateBase < ActiveRecord::Migration
def self.up
create_table :courses do |t|
- t.string :subject, :number, :title
- t.text :description, :attributes
- t.integer :credits
+ t.belongs_to :institution
+ t.string :subject, :number, :title
+ t.text :description, :course_attributes
+ t.integer :credits
t.timestamps
end
@@ -24,8 +25,8 @@ def self.up
create_table :sections do |t|
t.belongs_to :course, :professor
- t.string :name
- t.integer :identifier, :semester_season, :semester_year, :total_seats
+ t.string :name, :identifier, :semester_season
+ t.integer :semester_year, :total_seats
t.string :location, :days
t.time :start, :end
View
@@ -13,11 +13,12 @@
ActiveRecord::Schema.define(:version => 20110301010754) do
create_table "courses", :force => true do |t|
+ t.integer "institution_id"
t.string "subject"
t.string "number"
t.string "title"
t.text "description"
- t.text "attributes"
+ t.text "course_attributes"
t.integer "credits"
t.datetime "created_at"
t.datetime "updated_at"
@@ -45,8 +46,8 @@
t.integer "course_id"
t.integer "professor_id"
t.string "name"
- t.integer "identifier"
- t.integer "semester_season"
+ t.string "identifier"
+ t.string "semester_season"
t.integer "semester_year"
t.integer "total_seats"
t.string "location"
View
@@ -1,7 +1,4 @@
-# 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 => 'Daley', :city => cities.first)
+print "Institutions"
+Institution.create(:name => "Bryant University", :subdomain => "bryant", :email_domain => "bryant.edu"); print "."
+
+print "\n"
Oops, something went wrong.

0 comments on commit 7045e4e

Please sign in to comment.