Permalink
Browse files

initial import

  • Loading branch information...
0 parents commit 65f95b2927e29d6114853604c6e9e53d063e1e2c @ryanb committed Jul 18, 2008
Showing with 8,227 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +20 −0 LICENSE
  3. +6 −0 README
  4. +10 −0 Rakefile
  5. +15 −0 app/controllers/application.rb
  6. +44 −0 app/controllers/projects_controller.rb
  7. +3 −0 app/helpers/application_helper.rb
  8. +23 −0 app/helpers/layout_helper.rb
  9. +2 −0 app/helpers/projects_helper.rb
  10. +4 −0 app/models/project.rb
  11. +4 −0 app/models/task.rb
  12. +22 −0 app/views/layouts/application.html.erb
  13. +8 −0 app/views/projects/_form.html.erb
  14. +8 −0 app/views/projects/edit.html.erb
  15. +17 −0 app/views/projects/index.html.erb
  16. +5 −0 app/views/projects/new.html.erb
  17. +20 −0 app/views/projects/show.html.erb
  18. +109 −0 config/boot.rb
  19. +19 −0 config/database.yml
  20. +67 −0 config/environment.rb
  21. +17 −0 config/environments/development.rb
  22. +22 −0 config/environments/production.rb
  23. +22 −0 config/environments/test.rb
  24. +10 −0 config/initializers/inflections.rb
  25. +5 −0 config/initializers/mime_types.rb
  26. +15 −0 config/initializers/new_rails_defaults.rb
  27. +4 −0 config/routes.rb
  28. +12 −0 db/migrate/20080718205616_create_projects.rb
  29. +14 −0 db/migrate/20080718205908_create_tasks.rb
  30. +28 −0 db/schema.rb
  31. +2 −0 doc/README_FOR_APP
  32. +30 −0 public/404.html
  33. +30 −0 public/422.html
  34. +30 −0 public/500.html
  35. +10 −0 public/dispatch.cgi
  36. +24 −0 public/dispatch.fcgi
  37. +10 −0 public/dispatch.rb
  38. 0 public/favicon.ico
  39. BIN public/images/rails.png
  40. +2 −0 public/javascripts/application.js
  41. +963 −0 public/javascripts/controls.js
  42. +972 −0 public/javascripts/dragdrop.js
  43. +1,120 −0 public/javascripts/effects.js
  44. +4,225 −0 public/javascripts/prototype.js
  45. +5 −0 public/robots.txt
  46. +82 −0 public/stylesheets/application.css
  47. +3 −0 script/about
  48. +3 −0 script/console
  49. +3 −0 script/dbconsole
  50. +3 −0 script/destroy
  51. +3 −0 script/generate
  52. +3 −0 script/performance/benchmarker
  53. +3 −0 script/performance/profiler
  54. +3 −0 script/performance/request
  55. +3 −0 script/plugin
  56. +3 −0 script/process/inspector
  57. +3 −0 script/process/reaper
  58. +3 −0 script/process/spawner
  59. +3 −0 script/runner
  60. +3 −0 script/server
  61. +5 −0 test/fixtures/projects.yml
  62. +9 −0 test/fixtures/tasks.yml
  63. +54 −0 test/functional/projects_controller_test.rb
  64. +38 −0 test/test_helper.rb
  65. +8 −0 test/unit/project_test.rb
  66. +8 −0 test/unit/task_test.rb
@@ -0,0 +1,3 @@
+log/*
+tmp/*
+*.sqlite3
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008 Ryan Bates
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 README
@@ -0,0 +1,6 @@
+Complex Form Examples
+---------------------
+
+Several different ways to handle the multi-model form problem with a
+one-to-many association. The various approaches are in git branches.
+See them for examples.
@@ -0,0 +1,10 @@
+# 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'
@@ -0,0 +1,15 @@
+# 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
+
+ # See ActionController::RequestForgeryProtection for details
+ # Uncomment the :secret if you're not using the cookie session store
+ protect_from_forgery # :secret => '942733c28af903e7eb303ba250f52f1b'
+
+ # See ActionController::Base for details
+ # Uncomment this to filter the contents of submitted sensitive data parameters
+ # from your application log (in this case, all fields with names like "password").
+ # filter_parameter_logging :password
+end
@@ -0,0 +1,44 @@
+class ProjectsController < ApplicationController
+ def index
+ @projects = Project.find(:all)
+ end
+
+ def show
+ @project = Project.find(params[:id])
+ end
+
+ def new
+ @project = Project.new
+ end
+
+ def create
+ @project = Project.new(params[:project])
+ if @project.save
+ flash[:notice] = "Successfully created project."
+ redirect_to @project
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @project = Project.find(params[:id])
+ end
+
+ def update
+ @project = Project.find(params[:id])
+ if @project.update_attributes(params[:project])
+ flash[:notice] = "Successfully updated project."
+ redirect_to @project
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @project = Project.find(params[:id])
+ @project.destroy
+ flash[:notice] = "Successfully destroyed project."
+ redirect_to projects_url
+ end
+end
@@ -0,0 +1,3 @@
+# Methods added to this helper will be available to all templates in the application.
+module ApplicationHelper
+end
@@ -0,0 +1,23 @@
+# These helper methods can be called in your template to set variables to be used in the layout
+# This module should be included in all views globally,
+# to do so you may need to add this line to your ApplicationController
+# helper :layout
+module LayoutHelper
+ def title(page_title, show_title = true)
+ @content_for_title = page_title.to_s
+ @show_title = show_title
+ end
+
+ def show_title?
+ @show_title
+ end
+
+ def stylesheet(*args)
+ content_for(:head) { stylesheet_link_tag(*args.map(&:to_s)) }
+ end
+
+ def javascript(*args)
+ args = args.map { |arg| arg == :defaults ? arg : arg.to_s }
+ content_for(:head) { javascript_include_tag(*args) }
+ end
+end
@@ -0,0 +1,2 @@
+module ProjectsHelper
+end
@@ -0,0 +1,4 @@
+class Project < ActiveRecord::Base
+ has_many :tasks
+ validates_presence_of :name
+end
@@ -0,0 +1,4 @@
+class Task < ActiveRecord::Base
+ belongs_to :project
+ validates_presence_of :name
+end
@@ -0,0 +1,22 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title><%= h(yield(:title) || "Untitled") %></title>
+ <%= stylesheet_link_tag 'application' %>
+ <%= yield(:head) %>
+ </head>
+ <body>
+ <div id="container">
+ <%- flash.each do |name, msg| -%>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <%- end -%>
+
+ <%- if show_title? -%>
+ <h1><%=h yield(:title) %></h1>
+ <%- end -%>
+
+ <%= yield %>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,8 @@
+<%= error_messages_for :project %>
+<% form_for @project do |f| %>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p><%= f.submit "Submit" %></p>
+<% end %>
@@ -0,0 +1,8 @@
+<% title "Edit Project" %>
+
+<%= render :partial => 'form' %>
+
+<p>
+ <%= link_to "Show", @project %> |
+ <%= link_to "View All", projects_path %>
+</p>
@@ -0,0 +1,17 @@
+<% title "Projects" %>
+
+<table>
+ <tr>
+ <th>Name</th>
+ </tr>
+ <% for project in @projects %>
+ <tr>
+ <td><%=h project.name %></td>
+ <td><%= link_to "Show", project %></td>
+ <td><%= link_to "Edit", edit_project_path(project) %></td>
+ <td><%= link_to "Destroy", project, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+ <% end %>
+</table>
+
+<p><%= link_to "New Project", new_project_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Project" %>
+
+<%= render :partial => 'form' %>
+
+<p><%= link_to "Back to List", projects_path %></p>
@@ -0,0 +1,20 @@
+<% title "Project" %>
+
+<p>
+ <strong>Name:</strong>
+ <%=h @project.name %>
+</p>
+
+<h3>Tasks</h3>
+
+<ul>
+ <% for task in @project.tasks %>
+ <li><%=h task.name %></li>
+ <% end %>
+</ul>
+
+<p>
+ <%= link_to "Edit", edit_project_path(@project) %> |
+ <%= link_to "Destroy", @project, :confirm => 'Are you sure?', :method => :delete %> |
+ <%= link_to "View All", projects_path %>
+</p>
@@ -0,0 +1,109 @@
+# Don't change this file!
+# Configure your app in config/environment.rb and config/environments/*.rb
+
+RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
+
+module Rails
+ class << self
+ def boot!
+ unless booted?
+ preinitialize
+ pick_boot.run
+ end
+ end
+
+ def booted?
+ defined? Rails::Initializer
+ end
+
+ def pick_boot
+ (vendor_rails? ? VendorBoot : GemBoot).new
+ end
+
+ def vendor_rails?
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
+ end
+
+ def preinitialize
+ load(preinitializer_path) if File.exist?(preinitializer_path)
+ end
+
+ def preinitializer_path
+ "#{RAILS_ROOT}/config/preinitializer.rb"
+ end
+ end
+
+ class Boot
+ def run
+ load_initializer
+ Rails::Initializer.run(:set_load_path)
+ end
+ end
+
+ class VendorBoot < Boot
+ def load_initializer
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
+ Rails::Initializer.run(:install_gem_spec_stubs)
+ end
+ end
+
+ class GemBoot < Boot
+ def load_initializer
+ self.class.load_rubygems
+ load_rails_gem
+ require 'initializer'
+ end
+
+ def load_rails_gem
+ if version = self.class.gem_version
+ gem 'rails', version
+ else
+ gem 'rails'
+ end
+ rescue Gem::LoadError => load_error
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
+ exit 1
+ end
+
+ class << self
+ def rubygems_version
+ Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
+ end
+
+ def gem_version
+ if defined? RAILS_GEM_VERSION
+ RAILS_GEM_VERSION
+ elsif ENV.include?('RAILS_GEM_VERSION')
+ ENV['RAILS_GEM_VERSION']
+ else
+ parse_gem_version(read_environment_rb)
+ end
+ end
+
+ def load_rubygems
+ require 'rubygems'
+
+ unless rubygems_version >= '0.9.4'
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
+ exit 1
+ end
+
+ rescue LoadError
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
+ exit 1
+ end
+
+ def parse_gem_version(text)
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
+ end
+
+ private
+ def read_environment_rb
+ File.read("#{RAILS_ROOT}/config/environment.rb")
+ end
+ end
+ end
+end
+
+# All that for this:
+Rails.boot!
@@ -0,0 +1,19 @@
+# SQLite version 3.x
+# gem install sqlite3-ruby (not necessary on OS X Leopard)
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ timeout: 5000
Oops, something went wrong.

0 comments on commit 65f95b2

Please sign in to comment.