Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 8763add340c8756db6d34e75ddc16452e788a748 Yehuda Katz + Carl Lerche committed with Carl Lerche Aug 24, 2009
Showing with 17,918 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +243 −0 README
  3. +10 −0 Rakefile
  4. +34 −0 app/controllers/admin_controller.rb
  5. +57 −0 app/controllers/application_controller.rb
  6. +17 −0 app/controllers/info_controller.rb
  7. +93 −0 app/controllers/line_items_controller.rb
  8. +85 −0 app/controllers/orders_controller.rb
  9. +85 −0 app/controllers/products_controller.rb
  10. +86 −0 app/controllers/store_controller.rb
  11. +103 −0 app/controllers/users_controller.rb
  12. +2 −0 app/helpers/admin_helper.rb
  13. +3 −0 app/helpers/application_helper.rb
  14. +2 −0 app/helpers/info_helper.rb
  15. +2 −0 app/helpers/line_items_helper.rb
  16. +2 −0 app/helpers/orders_helper.rb
  17. +2 −0 app/helpers/products_helper.rb
  18. +8 −0 app/helpers/store_helper.rb
  19. +2 −0 app/helpers/users_helper.rb
  20. +32 −0 app/models/cart.rb
  21. +21 −0 app/models/cart_item.rb
  22. +17 −0 app/models/line_item.rb
  23. +39 −0 app/models/order.rb
  24. +48 −0 app/models/product.rb
  25. +72 −0 app/models/user.rb
  26. +4 −0 app/views/admin/index.html.erb
  27. +21 −0 app/views/admin/login.html.erb
  28. +2 −0 app/views/admin/logout.html.erb
  29. +39 −0 app/views/info/who_bought.atom.builder
  30. +9 −0 app/views/info/who_bought.html.erb
  31. +8 −0 app/views/info/who_bought.xml.builder
  32. +17 −0 app/views/layouts/line_items.html.erb
  33. +70 −0 app/views/layouts/store.html.erb
  34. +28 −0 app/views/line_items/edit.html.erb
  35. +26 −0 app/views/line_items/index.html.erb
  36. +27 −0 app/views/line_items/new.html.erb
  37. +23 −0 app/views/line_items/show.html.erb
  38. +28 −0 app/views/orders/edit.html.erb
  39. +26 −0 app/views/orders/index.html.erb
  40. +27 −0 app/views/orders/new.html.erb
  41. +23 −0 app/views/orders/show.html.erb
  42. +31 −0 app/views/products/edit.html.erb
  43. +34 −0 app/views/products/index.html.erb
  44. +30 −0 app/views/products/new.html.erb
  45. +24 −0 app/views/products/show.html.erb
  46. +19 −0 app/views/store/_cart.html.erb
  47. +11 −0 app/views/store/_cart_item.html.erb
  48. +11 −0 app/views/store/add_to_cart.js.rjs
  49. +50 −0 app/views/store/checkout.html.erb
  50. +21 −0 app/views/store/index.html.erb
  51. +24 −0 app/views/users/edit.html.erb
  52. +21 −0 app/views/users/index.html.erb
  53. +31 −0 app/views/users/new.html.erb
  54. +18 −0 app/views/users/show.html.erb
  55. +110 −0 config/boot.rb
  56. +22 −0 config/database.sample.yml
  57. +41 −0 config/environment.rb
  58. +19 −0 config/environments/development.rb
  59. +27 −0 config/environments/production.rb
  60. +27 −0 config/environments/test.rb
  61. +7 −0 config/initializers/backtrace_silencers.rb
  62. +8 −0 config/initializers/i18n.rb
  63. +10 −0 config/initializers/inflections.rb
  64. +5 −0 config/initializers/mime_types.rb
  65. +19 −0 config/initializers/new_rails_defaults.rb
  66. +17 −0 config/initializers/session_store.rb
  67. +64 −0 config/locales/en.yml
  68. +93 −0 config/locales/es.yml
  69. +51 −0 config/routes.rb
  70. BIN db/default/development.sqlite3
  71. +15 −0 db/migrate/20080601000001_create_products.rb
  72. +10 −0 db/migrate/20080601000002_add_price_to_product.rb
  73. +63 −0 db/migrate/20080601000003_add_test_data.rb
  74. +16 −0 db/migrate/20080601000004_create_sessions.rb
  75. +20 −0 db/migrate/20080601000005_create_orders.rb
  76. +20 −0 db/migrate/20080601000006_create_line_items.rb
  77. +15 −0 db/migrate/20080601000007_create_users.rb
  78. +59 −0 db/schema.rb
  79. +7 −0 db/seeds.rb
  80. +2 −0 doc/README_FOR_APP
  81. +219 −0 doc/app/classes/AdminController.html
  82. +105 −0 doc/app/classes/AdminHelper.html
  83. +158 −0 doc/app/classes/ApplicationController.html
  84. +112 −0 doc/app/classes/ApplicationHelper.html
  85. +249 −0 doc/app/classes/Cart.html
  86. +239 −0 doc/app/classes/CartItem.html
  87. +184 −0 doc/app/classes/InfoController.html
  88. +105 −0 doc/app/classes/InfoHelper.html
  89. +159 −0 doc/app/classes/LineItem.html
  90. +356 −0 doc/app/classes/LineItemsController.html
  91. +105 −0 doc/app/classes/LineItemsHelper.html
  92. +176 −0 doc/app/classes/Order.html
  93. +356 −0 doc/app/classes/OrdersController.html
  94. +105 −0 doc/app/classes/OrdersHelper.html
  95. +188 −0 doc/app/classes/Product.html
  96. +356 −0 doc/app/classes/ProductsController.html
  97. +105 −0 doc/app/classes/ProductsHelper.html
  98. +314 −0 doc/app/classes/StoreController.html
  99. +143 −0 doc/app/classes/StoreHelper.html
  100. +263 −0 doc/app/classes/User.html
  101. +377 −0 doc/app/classes/UsersController.html
  102. +105 −0 doc/app/classes/UsersHelper.html
  103. +1 −0 doc/app/created.rid
  104. +101 −0 doc/app/files/app/controllers/admin_controller_rb.html
  105. +109 −0 doc/app/files/app/controllers/application_controller_rb.html
  106. +101 −0 doc/app/files/app/controllers/info_controller_rb.html
  107. +101 −0 doc/app/files/app/controllers/line_items_controller_rb.html
  108. +101 −0 doc/app/files/app/controllers/orders_controller_rb.html
  109. +101 −0 doc/app/files/app/controllers/products_controller_rb.html
  110. +107 −0 doc/app/files/app/controllers/store_controller_rb.html
  111. +101 −0 doc/app/files/app/controllers/users_controller_rb.html
  112. +101 −0 doc/app/files/app/helpers/admin_helper_rb.html
  113. +108 −0 doc/app/files/app/helpers/application_helper_rb.html
  114. +101 −0 doc/app/files/app/helpers/info_helper_rb.html
  115. +101 −0 doc/app/files/app/helpers/line_items_helper_rb.html
  116. +101 −0 doc/app/files/app/helpers/orders_helper_rb.html
  117. +101 −0 doc/app/files/app/helpers/products_helper_rb.html
  118. +101 −0 doc/app/files/app/helpers/store_helper_rb.html
  119. +101 −0 doc/app/files/app/helpers/users_helper_rb.html
  120. +101 −0 doc/app/files/app/models/cart_item_rb.html
  121. +101 −0 doc/app/files/app/models/cart_rb.html
  122. +107 −0 doc/app/files/app/models/line_item_rb.html
  123. +107 −0 doc/app/files/app/models/order_rb.html
  124. +107 −0 doc/app/files/app/models/product_rb.html
  125. +108 −0 doc/app/files/app/models/user_rb.html
  126. +110 −0 doc/app/files/doc/README_FOR_APP.html
  127. +48 −0 doc/app/fr_class_index.html
  128. +49 −0 doc/app/fr_file_index.html
  129. +83 −0 doc/app/fr_method_index.html
  130. +24 −0 doc/app/index.html
  131. +208 −0 doc/app/rdoc-style.css
  132. +7 −0 lib/tasks/db_schema_migrations.rake
  133. +30 −0 public/404.html
  134. +30 −0 public/422.html
  135. +30 −0 public/500.html
  136. 0 public/favicon.ico
  137. BIN public/images/auto.jpg
  138. BIN public/images/logo.png
  139. BIN public/images/rails.png
  140. BIN public/images/svn.jpg
  141. BIN public/images/utc.jpg
  142. +280 −0 public/index.html
  143. +2 −0 public/javascripts/application.js
  144. +963 −0 public/javascripts/controls.js
  145. +973 −0 public/javascripts/dragdrop.js
  146. +1,128 −0 public/javascripts/effects.js
  147. +4,320 −0 public/javascripts/prototype.js
  148. +5 −0 public/robots.txt
  149. +276 −0 public/stylesheets/depot.css
  150. +54 −0 public/stylesheets/scaffold.css
  151. +4 −0 script/about
  152. +3 −0 script/console
  153. +3 −0 script/dbconsole
  154. +3 −0 script/destroy
  155. +3 −0 script/generate
  156. +3 −0 script/performance/benchmarker
  157. +3 −0 script/performance/profiler
  158. +3 −0 script/plugin
  159. +3 −0 script/runner
  160. +3 −0 script/server
@@ -0,0 +1,4 @@
+config/database.yml
+db/*.sqlite3
+log
+tmp
243 README
@@ -0,0 +1,243 @@
+== Welcome to Rails
+
+Rails is a web-application framework that includes everything needed to create
+database-backed web applications according to the Model-View-Control pattern.
+
+This pattern splits the view (also called the presentation) into "dumb" templates
+that are primarily responsible for inserting pre-built data in between HTML tags.
+The model contains the "smart" domain objects (such as Account, Product, Person,
+Post) that holds all the business logic and knows how to persist themselves to
+a database. The controller handles the incoming requests (such as Save New Account,
+Update Product, Show Post) by manipulating the model and directing data to the view.
+
+In Rails, the model is handled by what's called an object-relational mapping
+layer entitled Active Record. This layer allows you to present the data from
+database rows as objects and embellish these data objects with business logic
+methods. You can read more about Active Record in
+link:files/vendor/rails/activerecord/README.html.
+
+The controller and view are handled by the Action Pack, which handles both
+layers by its two parts: Action View and Action Controller. These two layers
+are bundled in a single package due to their heavy interdependence. This is
+unlike the relationship between the Active Record and Action Pack that is much
+more separate. Each of these packages can be used independently outside of
+Rails. You can read more about Action Pack in
+link:files/vendor/rails/actionpack/README.html.
+
+
+== Getting Started
+
+1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
+ and your application name. Ex: rails myapp
+2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
+3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
+4. Follow the guidelines to start developing your application
+
+
+== Web Servers
+
+By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
+with a variety of other web servers.
+
+Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
+suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
+getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
+More info at: http://mongrel.rubyforge.org
+
+Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
+Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
+FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
+
+== Apache .htaccess example for FCGI/CGI
+
+# General Apache options
+AddHandler fastcgi-script .fcgi
+AddHandler cgi-script .cgi
+Options +FollowSymLinks +ExecCGI
+
+# If you don't want Rails to look in certain directories,
+# use the following rewrite rules so that Apache won't rewrite certain requests
+#
+# Example:
+# RewriteCond %{REQUEST_URI} ^/notrails.*
+# RewriteRule .* - [L]
+
+# Redirect all requests not available on the filesystem to Rails
+# By default the cgi dispatcher is used which is very slow
+#
+# For better performance replace the dispatcher with the fastcgi one
+#
+# Example:
+# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
+RewriteEngine On
+
+# If your Rails application is accessed via an Alias directive,
+# then you MUST also set the RewriteBase in this htaccess file.
+#
+# Example:
+# Alias /myrailsapp /path/to/myrailsapp/public
+# RewriteBase /myrailsapp
+
+RewriteRule ^$ index.html [QSA]
+RewriteRule ^([^.]+)$ $1.html [QSA]
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
+
+# In case Rails experiences terminal errors
+# Instead of displaying this message you can supply a file here which will be rendered instead
+#
+# Example:
+# ErrorDocument 500 /500.html
+
+ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
+
+
+== Debugging Rails
+
+Sometimes your application goes wrong. Fortunately there are a lot of tools that
+will help you debug it and get it back on the rails.
+
+First area to check is the application log files. Have "tail -f" commands running
+on the server.log and development.log. Rails will automatically display debugging
+and runtime information to these files. Debugging info will also be shown in the
+browser on requests from 127.0.0.1.
+
+You can also log your own messages directly into the log file from your code using
+the Ruby logger class from inside your controllers. Example:
+
+ class WeblogController < ActionController::Base
+ def destroy
+ @weblog = Weblog.find(params[:id])
+ @weblog.destroy
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
+ end
+ end
+
+The result will be a message in your log file along the lines of:
+
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
+
+More information on how to use the logger is at http://www.ruby-doc.org/core/
+
+Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
+
+* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
+* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
+
+These two online (and free) books will bring you up to speed on the Ruby language
+and also on programming in general.
+
+
+== Debugger
+
+Debugger support is available through the debugger command when you start your Mongrel or
+Webrick server with --debugger. This means that you can break out of execution at any point
+in the code, investigate and change the model, AND then resume execution!
+You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
+Example:
+
+ class WeblogController < ActionController::Base
+ def index
+ @posts = Post.find(:all)
+ debugger
+ end
+ end
+
+So the controller will accept the action, run the first line, then present you
+with a IRB prompt in the server window. Here you can do things like:
+
+ >> @posts.inspect
+ => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
+ #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
+ >> @posts.first.title = "hello from a debugger"
+ => "hello from a debugger"
+
+...and even better is that you can examine how your runtime objects actually work:
+
+ >> f = @posts.first
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
+ >> f.
+ Display all 152 possibilities? (y or n)
+
+Finally, when you're ready to resume execution, you enter "cont"
+
+
+== Console
+
+You can interact with the domain model by starting the console through <tt>script/console</tt>.
+Here you'll have all parts of the application configured, just like it is when the
+application is running. You can inspect domain models, change values, and save to the
+database. Starting the script without arguments will launch it in the development environment.
+Passing an argument will specify a different environment, like <tt>script/console production</tt>.
+
+To reload your controllers and models after launching the console run <tt>reload!</tt>
+
+== dbconsole
+
+You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
+You would be connected to the database with the credentials defined in database.yml.
+Starting the script without arguments will connect you to the development database. Passing an
+argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
+Currently works for mysql, postgresql and sqlite.
+
+== Description of Contents
+
+app
+ Holds all the code that's specific to this particular application.
+
+app/controllers
+ Holds controllers that should be named like weblogs_controller.rb for
+ automated URL mapping. All controllers should descend from ApplicationController
+ which itself descends from ActionController::Base.
+
+app/models
+ Holds models that should be named like post.rb.
+ Most models will descend from ActiveRecord::Base.
+
+app/views
+ Holds the template files for the view that should be named like
+ weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
+ syntax.
+
+app/views/layouts
+ Holds the template files for layouts to be used with views. This models the common
+ header/footer method of wrapping views. In your views, define a layout using the
+ <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
+ call <% yield %> to render the view using this layout.
+
+app/helpers
+ Holds view helpers that should be named like weblogs_helper.rb. These are generated
+ for you automatically when using script/generate for controllers. Helpers can be used to
+ wrap functionality for your views into methods.
+
+config
+ Configuration files for the Rails environment, the routing map, the database, and other dependencies.
+
+db
+ Contains the database schema in schema.rb. db/migrate contains all
+ the sequence of Migrations for your schema.
+
+doc
+ This directory is where your application documentation will be stored when generated
+ using <tt>rake doc:app</tt>
+
+lib
+ Application specific libraries. Basically, any kind of custom code that doesn't
+ belong under controllers, models, or helpers. This directory is in the load path.
+
+public
+ The directory available for the web server. Contains subdirectories for images, stylesheets,
+ and javascripts. Also contains the dispatchers and the default HTML files. This should be
+ set as the DOCUMENT_ROOT of your web server.
+
+script
+ Helper scripts for automation and generation.
+
+test
+ Unit and functional tests along with fixtures. When using the script/generate scripts, template
+ test files will be generated for you and placed in this directory.
+
+vendor
+ External libraries that the application depends on. Also includes the plugins subdirectory.
+ If the app has frozen rails, those gems also go here, under vendor/rails/.
+ This directory is in the load path.
@@ -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,34 @@
+class AdminController < ApplicationController
+
+ # just display the form and wait for user to
+ # enter a name and password
+ #START:login
+ def login
+ if request.post?
+ user = User.authenticate(params[:name], params[:password])
+ if user
+ session[:user_id] = user.id
+ redirect_to(:action => "index")
+ else
+ flash.now[:notice] = "Invalid user/password combination"
+ end
+ end
+ end
+ #END:login
+
+ #START:logout
+ def logout
+#START_HIGHLIGHT
+ session[:user_id] = :logged_out
+#END_HIGHLIGHT
+ flash[:notice] = "Logged out"
+ redirect_to(:action => "login")
+ end
+ #END:logout
+
+ #START:index
+ def index
+ @total_orders = Order.count
+ end
+ #END:index
+end
@@ -0,0 +1,57 @@
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+#START:auth
+class ApplicationController < ActionController::Base
+ layout "store"
+ before_filter :authorize, :except => :login
+ #...
+
+#END:auth
+ before_filter :set_locale
+ helper :all # include all helpers, all the time
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
+
+ # Scrub sensitive parameters from your log
+ # filter_parameter_logging :password
+#START:auth
+
+protected
+ def authorize
+ unless User.find_by_id(session[:user_id])
+ #START_HIGHLIGHT
+ if session[:user_id] != :logged_out
+ #START:basic
+ authenticate_or_request_with_http_basic('Depot') do |username, password|
+ user = User.authenticate(username, password)
+ session[:user_id] = user.id if user
+ end
+ #END:basic
+ else
+ flash[:notice] = "Please log in"
+ redirect_to :controller => 'admin', :action => 'login'
+ end
+ #END_HIGHLIGHT
+ end
+ end
+
+ def set_locale
+ session[:locale] = params[:locale] if params[:locale]
+ I18n.locale = session[:locale] || I18n.default_locale
+
+ locale_path = "#{LOCALES_DIRECTORY}#{I18n.locale}.yml"
+
+ unless I18n.load_path.include? locale_path
+ I18n.load_path << locale_path
+ I18n.backend.send(:init_translations)
+ end
+
+ rescue Exception => err
+ logger.error err
+ flash.now[:notice] = "#{I18n.locale} translation not available"
+
+ I18n.load_path -= [locale_path]
+ I18n.locale = session[:locale] = I18n.default_locale
+ end
+end
+#END:auth
@@ -0,0 +1,17 @@
+class InfoController < ApplicationController
+ #START:who_bought
+ def who_bought
+ @product = Product.find(params[:id])
+ @orders = @product.orders
+ respond_to do |format|
+ format.html
+ format.xml { render :layout => false }
+ end
+ end
+ #END:who_bought
+
+protected
+
+ def authorize
+ end
+end
Oops, something went wrong.

0 comments on commit 8763add

Please sign in to comment.