Skip to content

Commit

Permalink
Database Model, REST-Json Controller, Sammy, Test- Template
Browse files Browse the repository at this point in the history
  • Loading branch information
sl80 committed Mar 7, 2011
1 parent 02b3512 commit 528866a
Show file tree
Hide file tree
Showing 55 changed files with 16,453 additions and 9,255 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gem 'rails', '3.0.4'
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'
gem 'jquery-rails', '>= 0.2.6'

# Use unicorn as the web server
# gem 'unicorn'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ GEM
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.5.0)
jquery-rails (0.2.7)
rails (~> 3.0)
thor (~> 0.14.4)
mail (2.2.15)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
Expand Down Expand Up @@ -69,5 +72,6 @@ PLATFORMS
ruby

DEPENDENCIES
jquery-rails (>= 0.2.6)
rails (= 3.0.4)
sqlite3
18 changes: 18 additions & 0 deletions app/controllers/mailing_lists_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class MailingListsController < ApplicationController

#respond_to :json

def index
@lists = MailingList.full.all

respond_to do |format|
format.json { render :json => @lists.to_json(:include => [:host, :list_type]) }
end


end




end
2 changes: 2 additions & 0 deletions app/helpers/mailing_lists_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MailingListsHelper
end
3 changes: 3 additions & 0 deletions app/models/host.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Host < ActiveRecord::Base
has_many :mailing_lists
end
3 changes: 3 additions & 0 deletions app/models/list_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ListType < ActiveRecord::Base
has_many :mailing_lists
end
14 changes: 14 additions & 0 deletions app/models/mailing_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class MailingList < ActiveRecord::Base
belongs_to :host
belongs_to :list_type

class << self

def full
includes [:host, :list_type]
end

end


end
2 changes: 2 additions & 0 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<h1>Home#index</h1>
<p>Hello World from support_tool</p>
<div id="main">
</div>
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>SupportTool</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= javascript_include_tag :defaults, 'sammy', 'plugins/sammy.template' %>
<%= csrf_meta_tag %>
</head>
<body>
Expand Down
4 changes: 4 additions & 0 deletions config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Load the rails application
require File.expand_path('../application', __FILE__)

# fix json issue
ActiveRecord::Base.include_root_in_json = false


# Initialize the rails application
SupportTool::Application.initialize!
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products

resources :mailing_lists

# Sample resource route with options:
# resources :products do
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20110226202607_create_hosts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateHosts < ActiveRecord::Migration
def self.up
create_table :hosts do |t|
t.string :name
t.timestamps
end
end

def self.down
drop_table :hosts
end
end
14 changes: 14 additions & 0 deletions db/migrate/20110226204500_create_mailing_lists.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateMailingLists < ActiveRecord::Migration
def self.up
create_table :mailing_lists do |t|
t.integer :host_id
t.integer :list_type_id
t.string :name
t.timestamps
end
end

def self.down
drop_table :mailing_lists
end
end
13 changes: 13 additions & 0 deletions db/migrate/20110226213145_create_list_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateListTypes < ActiveRecord::Migration
def self.up
create_table :list_types do |t|
t.string :name
t.string :description
t.timestamps
end
end

def self.down
drop_table :list_types
end
end
36 changes: 36 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20110226213145) do

create_table "hosts", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "list_types", :force => true do |t|
t.string "name"
t.string "description"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "mailing_lists", :force => true do |t|
t.integer "host_id"
t.integer "list_type_id"
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end

end
25 changes: 25 additions & 0 deletions public/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

(function($) {

var app = $.sammy('#main', function() {

this.use('Template');

this.get('#/', function(context) {
this.load('mailing_lists.json')
.then(function(lists) {
$.each(lists, function(i, list) {
context.render('templates/list.template', {list: list})
.appendTo(context.$element());
});
});
});


});

$(function() {
app.run('#/');
});

})(jQuery);
Loading

0 comments on commit 528866a

Please sign in to comment.