Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Store

  • Loading branch information...
commit ee97811addf863e078690f7754eb8793fef52910 1 parent 70d121c
@varid007 authored
Showing with 2,824 additions and 0 deletions.
  1. +5 −0 store/.gitignore
  2. +37 −0 store/Gemfile
  3. +128 −0 store/Gemfile.lock
  4. +261 −0 store/README
  5. +7 −0 store/Rakefile
  6. BIN  store/app/assets/images/rails.png
  7. +3 −0  store/app/assets/javascripts/admin/categories.js.coffee
  8. +9 −0 store/app/assets/javascripts/application.js
  9. +3 −0  store/app/assets/javascripts/articles.js.coffee
  10. +3 −0  store/app/assets/javascripts/comments.js.coffee
  11. +3 −0  store/app/assets/javascripts/home.js.coffee
  12. +3 −0  store/app/assets/javascripts/products.js.coffee
  13. +3 −0  store/app/assets/javascripts/sessions.js.coffee
  14. +3 −0  store/app/assets/javascripts/users.js.coffee
  15. +3 −0  store/app/assets/stylesheets/admin/categories.css.scss
  16. +7 −0 store/app/assets/stylesheets/application.css
  17. +3 −0  store/app/assets/stylesheets/articles.css.scss
  18. +3 −0  store/app/assets/stylesheets/comments.css.scss
  19. +3 −0  store/app/assets/stylesheets/home.css.scss
  20. +3 −0  store/app/assets/stylesheets/products.css.scss
  21. +3 −0  store/app/assets/stylesheets/sessions.css.scss
  22. +3 −0  store/app/assets/stylesheets/style.css
  23. +3 −0  store/app/assets/stylesheets/users.css.scss
  24. +20 −0 store/app/controllers/admin/application_controller.rb
  25. +27 −0 store/app/controllers/admin/application_controller.rb~
  26. +62 −0 store/app/controllers/admin/categories_controller.rb
  27. +35 −0 store/app/controllers/admin/categories_controller.rb~
  28. +22 −0 store/app/controllers/application_controller.rb
  29. +28 −0 store/app/controllers/application_controller.rb~
  30. +61 −0 store/app/controllers/articles_controller.rb
  31. +17 −0 store/app/controllers/comments_controller.rb
  32. +6 −0 store/app/controllers/home_controller.rb
  33. +70 −0 store/app/controllers/products_controller.rb
  34. +19 −0 store/app/controllers/sessions_controller.rb
  35. +63 −0 store/app/controllers/users_controller.rb
  36. +2 −0  store/app/helpers/admin/categories_helper.rb
  37. +13 −0 store/app/helpers/application_helper.rb
  38. +2 −0  store/app/helpers/articles_helper.rb
  39. +2 −0  store/app/helpers/comments_helper.rb
  40. +2 −0  store/app/helpers/home_helper.rb
  41. +2 −0  store/app/helpers/products_helper.rb
  42. +2 −0  store/app/helpers/sessions_helper.rb
  43. +2 −0  store/app/helpers/users_helper.rb
  44. 0  store/app/mailers/.gitkeep
  45. 0  store/app/models/.gitkeep
  46. +9 −0 store/app/models/article.rb
  47. +12 −0 store/app/models/category.rb
  48. +6 −0 store/app/models/comment.rb
  49. +8 −0 store/app/models/product.rb
  50. +43 −0 store/app/models/user.rb
  51. +20 −0 store/app/views/admin/categories/edit.erb
  52. +20 −0 store/app/views/admin/categories/edit.erb~
  53. +20 −0 store/app/views/admin/categories/index.html.erb
  54. +17 −0 store/app/views/admin/categories/index.html.erb~
  55. +20 −0 store/app/views/admin/categories/new.html.erb
  56. +20 −0 store/app/views/admin/categories/new.html.erb~
  57. +5 −0 store/app/views/admin/categories/show.html.erb
  58. +3 −0  store/app/views/admin/categories/show.html.erb~
  59. +3 −0  store/app/views/articles/_comments.html.erb
  60. +16 −0 store/app/views/articles/edit.html.erb
  61. +22 −0 store/app/views/articles/index.html.erb
  62. +10 −0 store/app/views/articles/index.html.erb~
  63. +16 −0 store/app/views/articles/new.html.erb
  64. +19 −0 store/app/views/articles/show.html.erb
  65. +3 −0  store/app/views/comments/create.js.erb
  66. +12 −0 store/app/views/home/_login.html.erb
  67. +4 −0 store/app/views/home/_menu_user.html.erb
  68. +4 −0 store/app/views/home/_menu_user.html.erb~
  69. +41 −0 store/app/views/home/index.html.erb
  70. +41 −0 store/app/views/layouts/application.html.erb
  71. +29 −0 store/app/views/layouts/application.html.erb~
  72. +33 −0 store/app/views/products/edit.html.erb
  73. +34 −0 store/app/views/products/index.html.erb
  74. +33 −0 store/app/views/products/new.html.erb
  75. +33 −0 store/app/views/products/new.html.erb~
  76. +8 −0 store/app/views/products/show.html.erb
  77. +12 −0 store/app/views/sessions/anew.html.erb
  78. +45 −0 store/app/views/users/edit.html.erb
  79. +44 −0 store/app/views/users/edit.html.erb~
  80. +31 −0 store/app/views/users/index.html.erb
  81. +53 −0 store/app/views/users/new.html.erb
  82. +11 −0 store/app/views/users/show.html.erb
  83. +4 −0 store/config.ru
  84. +48 −0 store/config/application.rb
  85. +6 −0 store/config/boot.rb
  86. +42 −0 store/config/database.yml
  87. +5 −0 store/config/environment.rb
  88. +30 −0 store/config/environments/development.rb
  89. +60 −0 store/config/environments/production.rb
  90. +42 −0 store/config/environments/test.rb
  91. +7 −0 store/config/initializers/backtrace_silencers.rb
  92. +10 −0 store/config/initializers/inflections.rb
  93. +5 −0 store/config/initializers/mime_types.rb
  94. +2 −0  store/config/initializers/recaptcha.rb
  95. +7 −0 store/config/initializers/secret_token.rb
  96. +8 −0 store/config/initializers/session_store.rb
  97. +14 −0 store/config/initializers/wrap_parameters.rb
  98. +5 −0 store/config/locales/en.yml
  99. +77 −0 store/config/routes.rb
  100. +77 −0 store/config/routes.rb~
  101. +17 −0 store/db/migrate/20120508033604_create_users.rb
  102. +9 −0 store/db/migrate/20120508033622_create_categories.rb
  103. +13 −0 store/db/migrate/20120508033633_create_products.rb
  104. +10 −0 store/db/migrate/20120508033643_create_articles.rb
  105. +10 −0 store/db/migrate/20120508033654_create_comments.rb
  106. +65 −0 store/db/schema.rb
  107. +7 −0 store/db/seeds.rb
  108. +2 −0  store/doc/README_FOR_APP
  109. 0  store/lib/assets/.gitkeep
  110. 0  store/lib/tasks/.gitkeep
  111. 0  store/log/.gitkeep
  112. +26 −0 store/public/404.html
  113. +26 −0 store/public/422.html
  114. +26 −0 store/public/500.html
  115. 0  store/public/favicon.ico
  116. +241 −0 store/public/index.html
  117. +5 −0 store/public/robots.txt
  118. +6 −0 store/script/rails
  119. 0  store/test/fixtures/.gitkeep
  120. +11 −0 store/test/fixtures/articles.yml
  121. +11 −0 store/test/fixtures/categories.yml
  122. +11 −0 store/test/fixtures/comments.yml
  123. +11 −0 store/test/fixtures/products.yml
  124. +11 −0 store/test/fixtures/users.yml
  125. 0  store/test/functional/.gitkeep
  126. +7 −0 store/test/functional/admin/categories_controller_test.rb
  127. +7 −0 store/test/functional/articles_controller_test.rb
  128. +7 −0 store/test/functional/comments_controller_test.rb
  129. +7 −0 store/test/functional/home_controller_test.rb
  130. +7 −0 store/test/functional/products_controller_test.rb
  131. +9 −0 store/test/functional/sessions_controller_test.rb
  132. +9 −0 store/test/functional/users_controller_test.rb
  133. 0  store/test/integration/.gitkeep
  134. +12 −0 store/test/performance/browsing_test.rb
  135. +13 −0 store/test/test_helper.rb
  136. 0  store/test/unit/.gitkeep
  137. +7 −0 store/test/unit/article_test.rb
  138. +7 −0 store/test/unit/category_test.rb
  139. +7 −0 store/test/unit/comment_test.rb
  140. +4 −0 store/test/unit/helpers/admin/categories_helper_test.rb
  141. +4 −0 store/test/unit/helpers/articles_helper_test.rb
  142. +4 −0 store/test/unit/helpers/comments_helper_test.rb
  143. +4 −0 store/test/unit/helpers/home_helper_test.rb
  144. +4 −0 store/test/unit/helpers/products_helper_test.rb
  145. +4 −0 store/test/unit/helpers/sessions_helper_test.rb
  146. +4 −0 store/test/unit/helpers/users_helper_test.rb
  147. +7 −0 store/test/unit/product_test.rb
  148. +7 −0 store/test/unit/user_test.rb
  149. 0  store/vendor/assets/stylesheets/.gitkeep
  150. 0  store/vendor/plugins/.gitkeep
View
5 store/.gitignore
@@ -0,0 +1,5 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/
+.sass-cache/
View
37 store/Gemfile
@@ -0,0 +1,37 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.1.0'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'mysql2'
+gem 'execjs'
+gem 'therubyracer'
+gem 'bcrypt-ruby', :require => 'bcrypt'
+gem 'recaptcha', :require => 'recaptcha/rails'
+
+
+# Gems used only for assets and not required
+# in production environments by default.
+group :assets do
+ gem 'sass-rails', " ~> 3.1.0"
+ gem 'coffee-rails', "~> 3.1.0"
+ gem 'uglifier'
+end
+
+gem 'jquery-rails'
+
+# Use unicorn as the web server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'ruby-debug19', :require => 'ruby-debug'
+
+group :test do
+ # Pretty printed test output
+ gem 'turn', :require => false
+end
View
128 store/Gemfile.lock
@@ -0,0 +1,128 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.1.0)
+ actionpack (= 3.1.0)
+ mail (~> 2.3.0)
+ actionpack (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.2)
+ rack-cache (~> 1.0.3)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.0)
+ activemodel (3.1.0)
+ activesupport (= 3.1.0)
+ bcrypt-ruby (~> 3.0.0)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ arel (~> 2.2.1)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ activesupport (3.1.0)
+ multi_json (~> 1.0)
+ ansi (1.4.2)
+ arel (2.2.3)
+ bcrypt-ruby (3.0.1)
+ builder (3.0.0)
+ coffee-rails (3.1.1)
+ coffee-script (>= 2.2.0)
+ railties (~> 3.1.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.3.1)
+ erubis (2.7.0)
+ execjs (1.3.2)
+ multi_json (~> 1.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ jquery-rails (1.0.19)
+ railties (~> 3.0)
+ thor (~> 0.14)
+ json (1.7.1)
+ libv8 (3.3.10.4)
+ mail (2.3.3)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.18)
+ multi_json (1.3.4)
+ mysql2 (0.3.11)
+ polyglot (0.3.3)
+ rack (1.3.6)
+ rack-cache (1.0.3)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.1.0)
+ actionmailer (= 3.1.0)
+ actionpack (= 3.1.0)
+ activerecord (= 3.1.0)
+ activeresource (= 3.1.0)
+ activesupport (= 3.1.0)
+ bundler (~> 1.0)
+ railties (= 3.1.0)
+ railties (3.1.0)
+ actionpack (= 3.1.0)
+ activesupport (= 3.1.0)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ recaptcha (0.3.4)
+ sass (3.1.17)
+ sass-rails (3.1.6)
+ actionpack (~> 3.1.0)
+ railties (~> 3.1.0)
+ sass (>= 3.1.10)
+ tilt (~> 1.3.2)
+ sprockets (2.0.4)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ therubyracer (0.10.1)
+ libv8 (~> 3.3.10)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ turn (0.9.5)
+ ansi
+ tzinfo (0.3.33)
+ uglifier (1.2.4)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bcrypt-ruby
+ coffee-rails (~> 3.1.0)
+ execjs
+ jquery-rails
+ mysql2
+ rails (= 3.1.0)
+ recaptcha
+ sass-rails (~> 3.1.0)
+ therubyracer
+ turn
+ uglifier
View
261 store/README
@@ -0,0 +1,261 @@
+== 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, create a new Rails application:
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
+
+2. Change directory to <tt>myapp</tt> and start the web server:
+ <tt>cd myapp; rails server</tt> (run with --help for options)
+
+3. Go to http://localhost:3000/ and you'll see:
+ "Welcome aboard: You're riding Ruby on Rails!"
+
+4. Follow the guidelines to start developing your application. You can find
+the following resources handy:
+
+* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
+* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
+
+
+== 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/. There are
+several books available online as well:
+
+* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
+* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
+
+These two 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 <tt>sudo gem install ruby-debug</tt>. Example:
+
+ class WeblogController < ActionController::Base
+ def index
+ @posts = Post.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", "body"=>"Only ten..", "id"=>"2"}>]"
+ >> @posts.first.title = "hello from a debugger"
+ => "hello from a debugger"
+
+...and even better, 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 can enter "cont".
+
+
+== Console
+
+The console is a Ruby shell, which allows you to interact with your
+application's domain model. 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.
+
+To start the console, run <tt>rails console</tt> from the application
+directory.
+
+Options:
+
+* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
+ made to the database.
+* Passing an environment name as an argument will load the corresponding
+ environment. Example: <tt>rails console production</tt>.
+
+To reload your controllers and models after launching the console run
+<tt>reload!</tt>
+
+More information about irb can be found at:
+link:http://www.rubycentral.org/pickaxe/irb.html
+
+
+== dbconsole
+
+You can go to the command line of your database directly through <tt>rails
+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>rails dbconsole production</tt>. Currently works for MySQL,
+PostgreSQL and SQLite 3.
+
+== Description of Contents
+
+The default directory structure of a generated Ruby on Rails application:
+
+ |-- app
+ | |-- assets
+ | |-- images
+ | |-- javascripts
+ | `-- stylesheets
+ | |-- controllers
+ | |-- helpers
+ | |-- mailers
+ | |-- models
+ | `-- views
+ | `-- layouts
+ |-- config
+ | |-- environments
+ | |-- initializers
+ | `-- locales
+ |-- db
+ |-- doc
+ |-- lib
+ | `-- tasks
+ |-- log
+ |-- public
+ |-- script
+ |-- test
+ | |-- fixtures
+ | |-- functional
+ | |-- integration
+ | |-- performance
+ | `-- unit
+ |-- tmp
+ | |-- cache
+ | |-- pids
+ | |-- sessions
+ | `-- sockets
+ `-- vendor
+ |-- assets
+ `-- stylesheets
+ `-- plugins
+
+app
+ Holds all the code that's specific to this particular application.
+
+app/assets
+ Contains subdirectories for images, stylesheets, and JavaScript files.
+
+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. Models descend from
+ ActiveRecord::Base by default.
+
+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 by default.
+
+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 generators 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. 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 rails generate
+ command, 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.
View
7 store/Rakefile
@@ -0,0 +1,7 @@
+#!/usr/bin/env rake
+# 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__)
+
+Store::Application.load_tasks
View
BIN  store/app/assets/images/rails.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
3  store/app/assets/javascripts/admin/categories.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
9 store/app/assets/javascripts/application.js
@@ -0,0 +1,9 @@
+// This is a manifest file that'll be compiled into including all the files listed below.
+// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
+// be included in the compiled file accessible from http://example.com/assets/application.js
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+//= require jquery
+//= require jquery_ujs
+//= require_tree .
View
3  store/app/assets/javascripts/articles.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  store/app/assets/javascripts/comments.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  store/app/assets/javascripts/home.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  store/app/assets/javascripts/products.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  store/app/assets/javascripts/sessions.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  store/app/assets/javascripts/users.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  store/app/assets/stylesheets/admin/categories.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the admin/categories controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
7 store/app/assets/stylesheets/application.css
@@ -0,0 +1,7 @@
+/*
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
+ *= require_self
+ *= require_tree .
+*/
View
3  store/app/assets/stylesheets/articles.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the articles controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
3  store/app/assets/stylesheets/comments.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the comments controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
3  store/app/assets/stylesheets/home.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the home controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
3  store/app/assets/stylesheets/products.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the products controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
3  store/app/assets/stylesheets/sessions.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the sessions controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
3  store/app/assets/stylesheets/style.css
@@ -0,0 +1,3 @@
+.error{
+ background-color:red;
+}
View
3  store/app/assets/stylesheets/users.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the users controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
20 store/app/controllers/admin/application_controller.rb
@@ -0,0 +1,20 @@
+class Admin::ApplicationController < ApplicationController
+ protect_from_forgery
+ helper_method :current_user
+
+ def require_admin_login
+ if current_user.nil? || !current_user.is_admin
+ flash[:error] = "Only admin are permitted"
+ redirect_to articles_path
+ else
+ return current_user
+ end
+ end
+ private
+ def current_user
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
+ end
+
+end
+
+
View
27 store/app/controllers/admin/application_controller.rb~
@@ -0,0 +1,27 @@
+class Admin::ApplicationController < ApplicationController
+ protect_from_forgery
+ helper_method :current_user
+
+ def require_admin_login
+ if current_user.nil? || is_admin
+ flash[:error] = "Only admin are permitted"
+ redirect_to articles_path
+ else
+ return current_user
+ end
+ end
+ private
+ def current_user
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
+ end
+
+ def is_admin
+ if current_user.email == "farid@gmail.com"
+ true
+ else
+ false
+ end
+ end
+end
+
+
View
62 store/app/controllers/admin/categories_controller.rb
@@ -0,0 +1,62 @@
+class Admin::CategoriesController < Admin::ApplicationController
+ before_filter :require_admin_login, :only => [:index,:show, :edit, :update,:destroy]
+ before_filter :find_category, :only => [:edit,:update,:show, :edit,:update, :delete, :update,:destroy]
+
+
+ def new
+ @category = Category.new
+ @parent_category = Category.where(["parent_id IS NULL"]).map{|x| [x.name, x.id ]}
+
+ end
+
+ def show
+
+ end
+ def index
+ @categories = Category.all
+ end
+
+ def create
+ @category = Category.new(params[:category])
+
+ if @category.save
+ flash[:notice] = 'Category was succesful create'
+ redirect_to admin_categories_path
+ else
+ flash[:error] = 'Category Faild to create'
+ render new_admin_category_path
+ end
+ end
+
+ def edit
+ # @parent_category = Category.where(["parent_id IS NULL"]).map{|x| [x.name, x.id ]}
+
+ end
+
+ def update
+ if @category.update_attributes(params[:category])
+ flash[:notice] = "Category was successfully updated"
+ redirect_to admin_categories_path
+ else
+ flash[:error] = "Category was failed to update"
+ render :edit
+ end
+ end
+
+ def destroy
+ @category = Category.find(params[:id])
+ @category.destroy
+ flash[:notice] = "Category was successfully deleted"
+ redirect_to admin_categories_path
+ end
+
+ private
+ def find_category
+ @parent_category = Category.where(["parent_id IS NULL"]).map{|x| [x.name, x.id ]}
+ @category = Category.find_by_id(params[:id])
+ if @category.nil?
+ flash[:notice] = 'Category not found'
+ redirect_to admin_categories_path
+ end
+ end
+end
View
35 store/app/controllers/admin/categories_controller.rb~
@@ -0,0 +1,35 @@
+class Admin::CategoriesController < Admin::ApplicationController
+ before_filter :find_category, :only => [:show, :edit, :delete, :update,:destroy]
+
+ def new
+ @category = Category.new
+ @parent_category = Category.where(["parent_id IS NULL"]).map{|x| [x.name, x.id ]}
+ end
+
+ def show
+
+ end
+ def index
+ @categories = Category.all
+ end
+
+ def create
+ @category = Category.new(params[:category])
+
+ if @category.save
+ flash[:notice] = 'Category was succesful create'
+ redirect_to admin_categories_path
+ else
+ flash[:error] = 'Category Faild to create'
+ render new_admin_category_path
+ end
+ end
+
+ def find_category
+ @category = Category.find_by_id(params[:id])
+ if @category.nil?
+ flash[:notice] = 'Article not found'
+ redirect_to category_path
+ end
+ end
+end
View
22 store/app/controllers/application_controller.rb
@@ -0,0 +1,22 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+ helper_method :current_user
+ def require_login
+ if current_user.nil?
+ flash[:error] = "You are not permited, please login first"
+ redirect_to home_index_path
+ else
+ return current_user
+ end
+ end
+
+ private
+ def current_user
+ @current_user ||= User.find(session[:user_id]) if
+ session[:user_id]
+ end
+
+
+end
+
+
View
28 store/app/controllers/application_controller.rb~
@@ -0,0 +1,28 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+ helper_method :current_user
+ def require_login
+ if current_user.nil?
+ flash[:error] = "You are not permited, please login first"
+ redirect_to new_session_path
+ else
+ return current_user
+ end
+ end
+
+ private
+ def current_user
+ @current_user ||= User.find(session[:user_id]) if
+ session[:user_id]
+ end
+
+ def is_admin
+ if current_user.email == "sadewa44@gmail.com"
+ true
+ else
+ false
+ end
+ end
+end
+
+
View
61 store/app/controllers/articles_controller.rb
@@ -0,0 +1,61 @@
+class ArticlesController < ApplicationController
+ before_filter :require_login, :only => [ :new,:edit, :update,:delete,:destroy]
+ before_filter :find_article, :only => [:show,:edit, :update,:delete,:destroy]
+ before_filter :your_article, :only => [:edit, :update,:delete,:destroy]
+
+ def index
+ @articles =Article.all
+ end
+ def new
+ @article = Article.new
+ end
+ def edit
+ end
+ def create
+ @user = User.find_by_email(current_user.email)
+ @article =@user.articles.new(params[:article])
+ if @article.save
+ flash[:notice] = 'Article was succesful create'
+ redirect_to articles_path
+ else
+ flash[:error] = 'Article was Error'
+ render new_article_path
+ end
+ end
+ def show
+ @comments=@article.comments
+ @comment=@article.comments.new
+ end
+
+ def update
+ if @article.update_attributes(params[:article])
+ flash[:notice] = 'Article was succesful Update'
+ redirect_to articles_path
+ else
+
+ render edit_article_path
+ end
+ end
+
+ def destroy
+ @article.destroy
+ redirect_to articles_path
+ end
+
+ private
+ def find_article
+ @article = Article.find_by_id(params[:id])
+ if @article.nil?
+ flash[:notice] = 'Article not found'
+ redirect_to articles_path
+ end
+ end
+ def your_article
+ user=User.find_by_email(current_user.email)
+ unless @article.user_id == user.id || current_user.is_admin
+ flash[:notice]="its not your article"
+ redirect_to articles_path
+ end
+ end
+
+end
View
17 store/app/controllers/comments_controller.rb
@@ -0,0 +1,17 @@
+class CommentsController < ApplicationController
+
+ def create
+ @user = User.find_by_email(current_user.email)
+ @comment = @user.comments.new(params[:comment])
+ @article = Article.find_by_id(params[:comment][:article_id])
+ @comments=@article.comments
+
+ respond_to do |format|
+ if @comment.save
+
+ format.html { redirect_to(article_path(article), :notice => 'Comment was successfully created.') }
+ format.js
+ end
+ end
+ end
+end
View
6 store/app/controllers/home_controller.rb
@@ -0,0 +1,6 @@
+class HomeController < ApplicationController
+ def index
+ @products = Product.last(6).reverse
+ @articles = Article.last(3).reverse
+ end
+end
View
70 store/app/controllers/products_controller.rb
@@ -0,0 +1,70 @@
+class ProductsController < ApplicationController
+ before_filter :require_login, :only => [ :new,:edit, :update,:delete,:destroy]
+ before_filter :find_product, :only => [:show, :edit, :update, :delete, :destroy]
+ before_filter :your_product, :only => [ :edit, :update, :delete, :destroy]
+ def index
+ @products = Product.all
+ end
+
+ def new
+ @product= Product.new
+ @child_category = Category.where(["parent_id IS NOT NULL"]).map{|x| [x.name, x.id ]}
+ end
+
+ def create
+
+ @user = User.find_by_email(current_user.email)
+ @product = @user.products.create(params[:product])
+ if @product.save
+ flash[:notice] = "Article was successfully created"
+ redirect_to products_path
+ else
+ flash[:error] = "Article was failed created"
+ render :new
+ end
+ end
+
+ def show
+
+ end
+
+ def edit
+
+ @child_category = Category.where(["parent_id IS NOT NULL"]).map{|x| [x.name, x.id ]}
+ end
+
+ def update
+
+ if @product.update_attributes(params[:product])
+ flash[:notice] = "Article was successfully updated"
+ redirect_to products_path
+ else
+ flash[:error] = "Article was failed to update"
+ render :edit
+ end
+ end
+
+ def destroy
+
+ @product.destroy
+ flash[:notice] = "Article was successfully deleted"
+ redirect_to products_path
+ end
+
+ private
+ def find_product
+ @product = Product.find_by_id(params[:id])
+ if @product.nil?
+ flash[:notice] = 'product not found'
+ redirect_to products_path
+ end
+ end
+
+ def your_product
+ user=User.find_by_email(current_user.email)
+ unless @product.id == user.id || current_user.is_admin
+ flash[:notice]="its not your product"
+ redirect_to products_path
+ end
+ end
+end
View
19 store/app/controllers/sessions_controller.rb
@@ -0,0 +1,19 @@
+class SessionsController < ApplicationController
+ def new
+ end
+
+ def create
+ user = User.authenticate(params[:email], params[:password])
+ if user
+ session[:user_id] = user.id
+ redirect_to user_path(current_user.id), :notice => "Logged in!"
+ else
+ flash[:notice] = "Invalid email or password"
+ redirect_to home_index_path
+ end
+ end
+ def destroy
+ session[:user_id] = nil
+ redirect_to home_index_path, :notice => "Logged out!"
+ end
+end
View
63 store/app/controllers/users_controller.rb
@@ -0,0 +1,63 @@
+class UsersController < ApplicationController
+ before_filter :find_user, :only => [:show, :edit, :update,:destroy]
+ before_filter :your_acount, :only => [:edit, :update,:destroy]
+
+ def index
+ @users = User.all
+ end
+
+ def new
+ @user = User.new
+ end
+
+ def show
+ end
+
+ def create
+ @user = User.new(params[:user])
+ if verify_recaptcha
+ if @user.save
+
+ flash[:notice] = 'Account was Created, Log in ?'
+ redirect_to new_session_path, :notice => "Signed up!"
+ else
+ render :new
+ end
+ else
+ flash[:error]= "There was an error with the recaptcha code"
+ render :new
+ end
+ end
+ def edit
+ end
+ def update
+ if @user.update_attributes(params[:user])
+ flash[:notice] = 'Article was succesful Update'
+ redirect_to user_path
+ else
+ flash[:notice] = 'User faild Update'
+ render :edit
+ end
+ end
+
+ def destroy
+ @user.destroy
+ redirect_to users_path
+ end
+ private
+ def find_user
+ @user = User.find_by_id(params[:id])
+ if @user.nil?
+ flash[:notice] = 'User not found'
+ redirect_to users_path
+ end
+ end
+
+ def your_acount
+ user=User.find_by_email(current_user.email)
+ unless @user.id == user.id || current_user.is_admin
+ flash[:notice]="its not your Acount"
+ redirect_to users_path
+ end
+ end
+end
View
2  store/app/helpers/admin/categories_helper.rb
@@ -0,0 +1,2 @@
+module Admin::CategoriesHelper
+end
View
13 store/app/helpers/application_helper.rb
@@ -0,0 +1,13 @@
+module ApplicationHelper
+
+ def welcome_text
+ str = "" #jika user telah login, tampilkan welcome textnya
+ if current_user
+ str = "Welcome, #{current_user.email} | "
+ str += link_to "Logout", log_out_path
+ else
+ str = "#{link_to "Login", log_in_path} | "
+ str += link_to "Signup", sign_up_path
+ end
+ end
+end
View
2  store/app/helpers/articles_helper.rb
@@ -0,0 +1,2 @@
+module ArticlesHelper
+end
View
2  store/app/helpers/comments_helper.rb
@@ -0,0 +1,2 @@
+module CommentsHelper
+end
View
2  store/app/helpers/home_helper.rb
@@ -0,0 +1,2 @@
+module HomeHelper
+end
View
2  store/app/helpers/products_helper.rb
@@ -0,0 +1,2 @@
+module ProductsHelper
+end
View
2  store/app/helpers/sessions_helper.rb
@@ -0,0 +1,2 @@
+module SessionsHelper
+end
View
2  store/app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
+module UsersHelper
+end
View
0  store/app/mailers/.gitkeep
No changes.
View
0  store/app/models/.gitkeep
No changes.
View
9 store/app/models/article.rb
@@ -0,0 +1,9 @@
+class Article < ActiveRecord::Base
+ belongs_to :user
+ has_many :comments ,:dependent => :destroy
+
+ validates :title, :uniqueness => true,
+ :presence => true,
+ :length => {:minimum => 1, :maximum => 15},
+ :format => {:with => /[a-zA-Z\s]+$/}
+end
View
12 store/app/models/category.rb
@@ -0,0 +1,12 @@
+class Category < ActiveRecord::Base
+ has_many :products, :dependent => :destroy
+ has_many :categories
+
+ has_many :child_categories
+
+ belongs_to :parent_category
+ validates :name, :uniqueness => true,
+ :presence => true,
+ :length => {:minimum => 1, :maximum => 15},
+ :format => {:with => /[a-zA-Z\s]+$/}
+end
View
6 store/app/models/comment.rb
@@ -0,0 +1,6 @@
+class Comment < ActiveRecord::Base
+ belongs_to :user
+ belongs_to :article
+
+
+end
View
8 store/app/models/product.rb
@@ -0,0 +1,8 @@
+class Product < ActiveRecord::Base
+ belongs_to :user
+ belongs_to :category
+ validates :name, :uniqueness => true,
+ :presence => true,
+ :length => {:minimum => 1, :maximum => 15},
+ :format => {:with => /[a-zA-Z\s]+$/}
+end
View
43 store/app/models/user.rb
@@ -0,0 +1,43 @@
+class User < ActiveRecord::Base
+ has_many :products
+ has_many :articles
+ has_many :comments
+
+ has_many :shared_articles,
+ :class_name => "Article",
+ :foreign_key => "user_id",
+ :conditions =>"title like '%share%'"
+
+ attr_accessor :password
+ before_save :encrypt_password
+
+ validates :password, :presence => {:on => :create},
+ :confirmation => true
+ validates :email, :presence => true,
+ :length => {:minimum => 3, :maximum => 254},
+ :uniqueness => true,
+ :format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i}
+
+ def encrypt_password
+ if password.present?
+ self.password_salt = BCrypt::Engine.generate_salt
+ self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
+ end
+ end
+ def self.authenticate(email, password)
+ user = find_by_email(email)
+ if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
+ user
+ else
+ nil
+ end
+ end
+
+ def is_admin
+ if self.email == "farid@gmail.com"
+ true
+ else
+ false
+ end
+ end
+end
View
20 store/app/views/admin/categories/edit.erb
@@ -0,0 +1,20 @@
+<h1>Update Category</h1>
+
+<%= form_for @category, :url => admin_category_path do |f| %>
+ <table >
+ <tr>
+ <td><%= f.label :name %></td>
+ <td>: <%= f.text_field :name, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td>Category :</td>
+ <td>:<%= f.select :parent_id, @parent_category, { :include_blank => true } %> </td>
+ </tr>
+ <tr>
+ <td></td>
+
+ <td><%= f.submit "Update" %> </td>
+ </tr>
+<% end %>
+<%= link_to "Back",admin_categories_path %>
+ </table>
View
20 store/app/views/admin/categories/edit.erb~
@@ -0,0 +1,20 @@
+<h1>New Category</h1>
+
+<%= form_for @category, :url => admin_category_path do |f| %>
+ <table >
+ <tr>
+ <td><%= f.label :name %></td>
+ <td>: <%= f.text_field :name, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td>Category :</td>
+ <td>:<%= f.select :parent_id, @parent_category, { :include_blank => true } %> </td>
+ </tr>
+ <tr>
+ <td></td>
+
+ <td><%= f.submit "Update" %> </td>
+ </tr>
+<% end %>
+<%= link_to "Back",admin_categories_path %>
+ </table>
View
20 store/app/views/admin/categories/index.html.erb
@@ -0,0 +1,20 @@
+<%= link_to "Add Category", new_admin_category_path %>
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Parent Category</th>
+ <th>Manage</th>
+
+ </tr>
+ <tr>
+
+ <% @categories.each do |category| %>
+
+ <td><%= category.name %></td>
+
+ <td></td>
+ <td><%= link_to "Show", admin_category_path(category.id) %> | <%= link_to "Edit", edit_admin_category_path(category.id) %> | <%= link_to "delete", admin_category_path(category.id), confirm:'yakin Hapus ?',method: :delete %></td>
+ </tr>
+ <% end %>
+
+ </table>
View
17 store/app/views/admin/categories/index.html.erb~
@@ -0,0 +1,17 @@
+<%= link_to "Add Category", new_admin_category_path %>
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Parent Category</th>
+ <th>Manage</th>
+ </tr>
+
+ <% @categories.each do |category| %>
+ <tr>
+ <td><%= category.name %></td>
+ <td><%= category.parent_id %></td>
+ <td><%= link_to "Show", admin_category_path(category.id) %> | Edit | Delete</td>
+ </tr>
+ <% end %>
+ <%- link_to "Back",admin_categories_path %>
+ </table>
View
20 store/app/views/admin/categories/new.html.erb
@@ -0,0 +1,20 @@
+<h1>New Category</h1>
+
+<%= form_for @category, :url => admin_categories_path do |f| %>
+ <table >
+ <tr>
+ <td><%= f.label :name %></td>
+ <td>: <%= f.text_field :name, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td>Category :</td>
+ <td>:<%= f.select :parent_id, @parent_category, { :include_blank => true } %> </td>
+ </tr>
+ <tr>
+ <td></td>
+
+ <td><%= f.submit "Add" %> </td>
+ </tr>
+<% end %>
+<%= link_to "Back",admin_categories_path %>
+ </table>
View
20 store/app/views/admin/categories/new.html.erb~
@@ -0,0 +1,20 @@
+<h1>New Category</h1>
+
+<%= form_for @category, :url => admin_category_path do |f| %>
+ <table >
+ <tr>
+ <td><%= f.label :name %></td>
+ <td>: <%= f.text_field :name, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td>Category :</td>
+ <td>:<%= f.select :parent_id, @parent_category, { :include_blank => true } %> </td>
+ </tr>
+ <tr>
+ <td></td>
+
+ <td><%= f.submit "Add" %> </td>
+ </tr>
+<% end %>
+<%= link_to "Back",admin_categories_path %>
+ </table>
View
5 store/app/views/admin/categories/show.html.erb
@@ -0,0 +1,5 @@
+<%= @category.id%><br/>
+<%= @category.name%><br/>
+<%= @category.parent_id%><br/>
+
+<%= link_to "Back",admin_categories_path %>
View
3  store/app/views/admin/categories/show.html.erb~
@@ -0,0 +1,3 @@
+<%= @category.id%><br/>
+<%= @category.name%><br/>
+<%= @category.parent_id%><br/>
View
3  store/app/views/articles/_comments.html.erb
@@ -0,0 +1,3 @@
+<% comments.each do |comment| %>
+ <%= comment.comment %><br />
+<% end %>
View
16 store/app/views/articles/edit.html.erb
@@ -0,0 +1,16 @@
+<%= form_for @article do |f| %>
+ <table >
+ <tr>
+ <td><%= f.label :title %></td>
+ <td>: <%= f.text_field :title, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><div ><%= f.label :body %></div></td>
+ <td><%= f.text_area :body %></td>
+ </tr>
+
+ <tr>
+ <td><%= f.submit %> </td>
+ <td><%= link_to "Back",articles_path %> </td>
+ </tr>
+<% end %>
View
22 store/app/views/articles/index.html.erb
@@ -0,0 +1,22 @@
+
+<h1>List Article</h1>
+<%= link_to "Add Article",new_article_path %>
+<table>
+<tr>
+ <th>Title</th>
+ <th>Body</th>
+ <th>User</th>
+ <th>Manage</th>
+ </tr>
+ <hr>
+<% @articles.each do |article| %>
+
+ <tr>
+ <td><%= article.title %></td>
+ <td><%= article.body %></td>
+ <td><%= article.user_id %></td>
+ <td><%= link_to "Show",article_path(article.id) %> | <%= link_to "Edit",edit_article_path(article.id) %> | <%= link_to "delete", article_path(article.id), confirm:'yakin Hapus ?',method: :delete %> </td>
+ </tr>
+
+<% end %>
+ </table>
View
10 store/app/views/articles/index.html.erb~
@@ -0,0 +1,10 @@
+<h1>List Article</h1>
+<% @articles.each do |article| %>
+ <table>
+ <tr>
+ <td><%= article.title %></td>
+ <td><%= article.body %></td>
+ <td><%= article.user_id %></td>
+ </tr>
+ </table>
+<% end %>
View
16 store/app/views/articles/new.html.erb
@@ -0,0 +1,16 @@
+<%= form_for @article do |f| %>
+ <table >
+ <tr>
+ <td><%= f.label :title %></td>
+ <td>: <%= f.text_field :title, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><div ><%= f.label :body %></div></td>
+ <td><%= f.text_area :body %></td>
+ </tr>
+
+ <tr>
+ <td><%= f.submit %> </td>
+ <td><%= link_to "Back",articles_path %> </td>
+ </tr>
+<% end %>
View
19 store/app/views/articles/show.html.erb
@@ -0,0 +1,19 @@
+<%= @article.id %></br>
+Body :<br/><%= @article.body %></br>
+Created by : <%= @article.user_id %>
+<br/>
+<%= link_to "Back", articles_path %>
+
+<!--bagian ini untuk menampilkan comment yang dimiliki oleh article tersebut -->
+<div id="comments">
+ <%= render :partial => "comments", :locals => {:comments => @comments} %>
+</div><br /><br />
+
+<% unless(current_user.nil?)%>
+ <%= form_for @comment, :url => comments_path, :remote => true do |f| %>
+ <%= f.text_area :comment %>
+ <%= f.hidden_field :article_id, :value => @article.id %>
+
+ <%= submit_tag "comment" %>
+ <% end %>
+<% end %>
View
3  store/app/views/comments/create.js.erb
@@ -0,0 +1,3 @@
+$("#comments").html(" <%= j( render :partial => "articles/comments",
+ :locals => {:comments => @comments} ) %>")
+$("#comment_content").val("");
View
12 store/app/views/home/_login.html.erb
@@ -0,0 +1,12 @@
+<h1>Log in</h1>
+ <%= form_tag sessions_path do %>
+ <p>
+ <%= label_tag :email %><br />
+ <%= text_field_tag :email, params[:email] %>
+ </p>
+ <p>
+ <%= label_tag :password %><br />
+ <%= password_field_tag :password %>
+ </p>
+ <p class="button"><%= submit_tag "Log in"%></p>
+<% end %>
View
4 store/app/views/home/_menu_user.html.erb
@@ -0,0 +1,4 @@
+<%= link_to "Edit", edit_user_path(current_user.id) %><br/>
+<%= link_to "Sell a product", new_product_path %><br/>
+<%= link_to "Share an Article", new_article_path %><br/>
+<%= link_to "Log Out", log_out_path %><br/>
View
4 store/app/views/home/_menu_user.html.erb~
@@ -0,0 +1,4 @@
+<%= link_to "Edit", user_path(current_user.id) %><br/>
+<%= link_to "Sell a product", new_product_path %><br/>
+<%= link_to "Share an Article", new_article_path %><br/>
+<%= link_to "Log Out", log_out_path %><br/>
View
41 store/app/views/home/index.html.erb
@@ -0,0 +1,41 @@
+<p><b>Listing Products</b></p>
+</hr>
+<% i=1 %>
+<table>
+ <tr>
+ <% @products.each do |product| %>
+ <% if i <= 3 %>
+ <td width="300px" id="table-product">
+ <b>Name : </b><%= product.name %><br>
+ <b>Price($) : </b><%= product.price %><br>
+ <%= link_to "Show Details", product_path(product.id) %>
+ </td>
+ <% else %>
+ </tr>
+ <tr>
+ <td>
+ Name : <%= product.name %><br>
+ Price : <%= product.price %><br>
+ <%= link_to "Show Details", product_path(product.id) %>
+ </td>
+ </tr><% i+=1 %>
+ <% end %>
+
+ <% end %>
+</table>
+<br />
+<hr />
+<p><b>Listing Articles</b></p>
+<hr />
+
+<table>
+ <tr>
+ <% @articles.each do |article| %>
+ <td>
+ <b><%= article.title %></b><br />
+ <%= truncate(article.body, :length => 150) %> <br /><br />
+ <%= link_to "Read More", article_path(article.id) %><br /><br/><hr> <br />
+ </td>
+ </tr>
+ <% end %>
+</table>
View
41 store/app/views/layouts/application.html.erb
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Store</title>
+ <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" %>
+ <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" %>
+ <%= javascript_include_tag "jquery-rails.js" %>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag "application" %>
+ <link rel="stylesheet" type="text/css" href="style.css" />
+ <%= csrf_meta_tags %>
+</head>
+<body>
+ <div id="user_nav">
+ <%= raw(welcome_text) %>
+
+ </div>
+ <center><h1>Welcome to my store</h1></center>
+ <hr>
+ <%= link_to "Home", home_index_path %> | <%= link_to "Product", products_path %> | <%= link_to "Article", articles_path %> |
+ <% unless current_user.nil? %>
+ <% if current_user.is_admin %>
+ <%= link_to "Categories", admin_categories_path %> |
+ <% end %>
+ <% end %>
+ <table align="center" width="1000">
+ <tr>
+ <td width="25%">
+ <% if (current_user.nil?) %>
+ <%= render :partial => "home/login"%>
+ <% else%>
+ <%= render :partial => "home/menu_user"%><br/>
+ </td>
+ <% end %>
+ <td > <p class="error"><%= flash[:notice]|| flash[:error]%></p><br/><%= yield %></td>
+ </tr>
+ </table>
+
+
+</body>
+</html>
View
29 store/app/views/layouts/application.html.erb~
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Store</title>
+ <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" %>
+ <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" %>
+ <%= javascript_include_tag "jquery-rails.js" %>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag "application" %>
+ <%= csrf_meta_tags %>
+</head>
+<body>
+ <div id="user_nav">
+ <%= raw(welcome_text) %>
+
+ </div>
+ <center><h1>Welcome to my store</h1></center>
+
+ <center> Home | <%= link_to "Product", products_path %> | <%= link_to "Article", articles_path %> | <%= link_to "Category", admin_categories_path %> </center><br/>
+ <table border="1" align="center" width="1000">
+ <tr>
+ <td width="25%">sidebar</td>
+ <td> <%= flash[:notice]|| flash[:error]%><%= yield %></td>
+ </tr>
+ </table>
+
+
+</body>
+</html>
View
33 store/app/views/products/edit.html.erb
@@ -0,0 +1,33 @@
+<h1>Edit Product</h1>
+
+<%= form_for @product do |f| %>
+ <table >
+ <tr>
+ <td><%= f.label :name, "Name" %></td>
+ <td>: <%= f.text_field :name, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :description, "Description" %></td>
+ <td>: <%= f.text_field :description, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :price, "Price ($)"%></td>
+ <td>: <%= f.text_field :price, :size => 15 %> </td>
+ </tr>
+
+ <tr>
+ <td><%= f.label :weight, "Weight" %></td>
+ <td>: <%= f.text_field :weight, :size => 15 %> </td>
+ </tr>
+
+ <tr>
+ <td><%= f.label :category_id %></td>
+ <td>: <%= f.select :category_id, @child_category, { :include_blank => false } %></td>
+ <tr/>
+
+ <tr>
+ <td></td>
+ <td>: <%= f.submit "Add" %> </td>
+ </tr>
+<% end %>
+<%= link_to "Back", products_path %>
View
34 store/app/views/products/index.html.erb
@@ -0,0 +1,34 @@
+<h1>List Products</h1>
+<hr>
+<%= link_to "Add Product", new_product_path %>
+ <table>
+ <tr>
+ <th>id</th>
+ <th>Name</th>
+ <th>Description</th>
+ <th>Price</th>
+ <th>Weight</th>
+ <th>User Id</th>
+ <th>Category</th>
+ <th>Manage</th>
+ </tr>
+
+ <% @products.each do |product| %>
+ <tr>
+ <td><%= product.id %></td>
+ <td><%= product.name %></td>
+ <td><%= product.description %></td>
+ <td><%= product.price %></td>
+ <td><%= product.weight %></td>
+ <td><%= product.user_id %></td>
+ <td>
+ <% unless (product.category.nil?)%>
+ <%= product.category.name %></td>
+ <% else %>
+ -
+ <% end %>
+ <td><%= link_to "Show" ,product_path(product.id) %> |<%= link_to "Edit", edit_product_path(product.id) %> | <%= link_to "Delete", product_path(product.id), confirm:'Delete This Product ?',method: :delete %> </td>
+ </tr>
+ <% end %>
+
+ </table>
View
33 store/app/views/products/new.html.erb
@@ -0,0 +1,33 @@
+<h1>New product</h1>
+
+<%= form_for @product do |f| %>
+ <table >
+ <tr>
+ <td><%= f.label :name, "Name" %></td>
+ <td>: <%= f.text_field :name, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :description, "Description" %></td>
+ <td>: <%= f.text_area :description, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :price, "Price ($)"%></td>
+ <td>: <%= f.text_field :price, :size => 15 %> </td>
+ </tr>
+
+ <tr>
+ <td><%= f.label :weight, "Weight" %></td>
+ <td>: <%= f.text_field :weight, :size => 15 %> </td>
+ </tr>
+
+ <tr>
+ <td><%= f.label :category_id %></td>
+ <td>: <%= f.select :category_id, @child_category, { :include_blank => false } %></td>
+ <tr/>
+
+ <tr>
+ <td></td>
+ <td>: <%= f.submit "Add" %> </td>
+ </tr>
+<% end %>
+<%= link_to "Back", products_path %>
View
33 store/app/views/products/new.html.erb~
@@ -0,0 +1,33 @@
+<h1>New product</h1>
+
+<%= form_for @product do |f| %>
+ <table >
+ <tr>
+ <td><%= f.label :name, "Name" %></td>
+ <td>: <%= f.text_field :name, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :description, "Description" %></td>
+ <td>: <%= f.text_field :description, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :price, "Price ($)"%></td>
+ <td>: <%= f.text_field :price, :size => 15 %> </td>
+ </tr>
+
+ <tr>
+ <td><%= f.label :weight, "Weight" %></td>
+ <td>: <%= f.text_field :weight, :size => 15 %> </td>
+ </tr>
+
+ <tr>
+ <td><%= f.label :category_id %></td>
+ <td>: <%= f.select :category_id, @child_category, { :include_blank => false } %></td>
+ <tr/>
+
+ <tr>
+ <td></td>
+ <td>: <%= f.submit "Add" %> </td>
+ </tr>
+<% end %>
+<%= link_to "Back", products_path %>
View
8 store/app/views/products/show.html.erb
@@ -0,0 +1,8 @@
+Id : <%= @product.id %><br/>
+Name : <%= @product.name %><br/>
+Description : <%= @product.description %><br/>
+Price : <%= @product.price %><br/>
+Weight : <%= @product.weight %><br/>
+user id : <%= @product.user_id %><br/>
+Category : <%= @product.category.name %><br/>
+<%= link_to "Back", products_path%>
View
12 store/app/views/sessions/anew.html.erb
@@ -0,0 +1,12 @@
+<h1>Log in</h1>
+ <%= form_tag sessions_path do %>
+ <p>
+ <%= label_tag :email %><br />
+ <%= text_field_tag :email, params[:email] %>
+ </p>
+ <p>
+ <%= label_tag :password %><br />
+ <%= password_field_tag :password %>
+ </p>
+ <p class="button"><%= submit_tag "Log in"%></p>
+<% end %>
View
45 store/app/views/users/edit.html.erb
@@ -0,0 +1,45 @@
+
+<%= form_for @user do |f| %>
+ <table >
+ <tr>
+ <td><%= f.label :email %></td>
+ <td>: <%= f.text_field :email, :size => 15 %> </td>
+ </tr>
+
+ <tr>
+ <td><%= f.label :name %></td>
+ <td>: <%= f.text_field :name, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :address %></td>
+ <td>: <%= f.text_area :address, :rows => "2", :cols => "40"%> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :phone %></td>
+ <td>: <%= f.text_field :phone, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :birthday %></td>
+ <td>: <%= f.date_select(:birthday ,:star_year => 1970) %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :gender %></td>
+ <td>: <%= f.radio_button(:gender, "1") %> Male
+ <%= f.radio_button(:gender, nil ) %> Female </td>
+ </tr>
+ <tr>
+ <td><%= f.label :facebook %></td>
+ <td>: <%= f.text_field :facebook,:size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :blog %></td>
+ <td>: <%= f.text_field :blog,:size => 15 %> </td>
+ </tr>
+
+ <tr>
+ <td><%= f.submit "Save"%></td>
+
+
+ </tr>
+<% end %>
+ </table>
View
44 store/app/views/users/edit.html.erb~
@@ -0,0 +1,44 @@
+
+<%= form_for @user do |f| %>
+ <table >
+ <tr>
+ <td><%= f.label :email %></td>
+ <td>: <%= f.text_field :email, :size => 15 %> </td>
+ </tr>
+
+ <tr>
+ <td><%= f.label :name %></td>
+ <td>: <%= f.text_field :name, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :address %></td>
+ <td>: <%= f.text_area :address, :rows => "2", :cols => "40"%> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :phone %></td>
+ <td>: <%= f.text_field :phone, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :birthday %></td>
+ <td>: <%= f.date_select(:birthday ,:star_year => 1970) %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :gender %></td>
+ <td>: <%= f.text_field :gender %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :facebook %></td>
+ <td>: <%= f.text_field :facebook,:size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :blog %></td>
+ <td>: <%= f.text_field :blog,:size => 15 %> </td>
+ </tr>
+
+ <tr>
+ <td><%= f.submit "Save"%></td>
+
+
+ </tr>
+<% end %>
+ </table>
View
31 store/app/views/users/index.html.erb
@@ -0,0 +1,31 @@
+<h1>List User</h1>
+ <table>
+ <tr>
+ <th>id</th>
+ <th>email</th>
+ <th>Name</th>
+ <th>Address</th>
+ <th>Phone</th>
+ <th>Birthday</th>
+ <th>Gender</th>
+ <th>Facebook</th>
+ <th>blog</th>
+ <th>Manage</th>
+ </tr>
+
+ <% @users.each do |user| %>
+ <tr>
+ <td><%= user.id %></td>
+ <td><%= user.email %></td>
+ <td><%= user.name %></td>
+ <td><%= user.address %></td>
+ <td><%= user.phone %></td>
+ <td><%= user.birthday %></td>
+ <td><%= user.gender %></td>
+ <td><%= user.facebook %></td>
+ <td><%= user.blog %></td>
+ <td><%= link_to "Show", user_path(user.id) %> |<%= link_to "Edit", edit_user_path(user.id) %> | <%= link_to "Delete", user_path(user.id), confirm:'yakin Hapus ?',method: :delete %></td>
+ </tr>
+ <% end %>
+
+ </table>
View
53 store/app/views/users/new.html.erb
@@ -0,0 +1,53 @@
+<h1>Sign Up </h1>
+
+<%= form_for @user do |f| %>
+ <table >
+ <tr>
+ <td><%= f.label :email %></td>
+ <td>: <%= f.text_field :email, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :password %></td>
+ <td>: <%= f.password_field :password, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :password_confirmation %></td>
+ <td>: <%= f.password_field :password_confirmation, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :name %></td>
+ <td>: <%= f.text_field :name, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :address %></td>
+ <td>: <%= f.text_area :address, :rows => "2", :cols => "40"%> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :phone %></td>
+ <td>: <%= f.text_field :phone, :size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :birthday %></td>
+ <td>: <%= f.date_select(:birthday ,:star_year => 1970) %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :gender %></td>
+ <td>: <%= f.radio_button(:gender, "1") %> Male
+ <%= f.radio_button(:gender, nil ) %> Female </td>
+ </tr>
+ <tr>
+ <td><%= f.label :facebook %></td>
+ <td>: <%= f.text_field :facebook,:size => 15 %> </td>
+ </tr>
+ <tr>
+ <td><%= f.label :blog %></td>
+ <td>: <%= f.text_field :blog,:size => 15 %> </td>
+ </tr>
+
+ <tr>
+ <td></td>
+
+ <td><%= recaptcha_tags %><%= f.submit "Sign Up" %> </td>
+ </tr>
+<% end %>
+ </table>
View
11 store/app/views/users/show.html.erb
@@ -0,0 +1,11 @@
+
+ id :<%= @user.id %><br/>
+ Email :<%= @user.email %><br/>
+ Name :<%= @user.name %><br/>
+ Address :<%= @user.address %><br/>
+ Phone :<%= @user.phone %><br/>
+ Birthday :<%= @user.birthday %><br/>
+ Gender :<%= @user.gender %><br/>
+ facebook :<%= @user.facebook %><br/>
+ Blog :<%= @user.blog %><br/>
+<%= link_to "Back", articles_path %>
View
4 store/config.ru
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Store::Application
View
48 store/config/application.rb
@@ -0,0 +1,48 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+if defined?(Bundler)
+ # If you precompile assets before deploying to production, use this line
+ Bundler.require *Rails.groups(:assets => %w(development test))
+ # If you want your assets lazily compiled in production, use this line
+ # Bundler.require(:default, :assets, Rails.env)
+end
+
+module Store
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ # config.autoload_paths += %W(#{config.root}/extras)
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named.
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running.
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+
+ # Enable the asset pipeline
+ config.assets.enabled = true
+
+ # Version of your assets, change this if you want to expire all your assets
+ config.assets.version = '1.0'
+ end
+end
View
6 store/config/boot.rb
@@ -0,0 +1,6 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
View
42 store/config/database.yml
@@ -0,0 +1,42 @@
+# MySQL. Versions 4.1 and 5.0 are recommended.
+#
+# Install the MYSQL driver
+# gem install mysql2
+#
+# Ensure the MySQL gem is defined in your Gemfile
+# gem 'mysql2'
+#
+# And be sure to use new-style password hashing:
+# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
+development:
+ adapter: mysql2
+ encoding: utf8
+ reconnect: false
+ database: store_development
+ pool: 5
+ username: root
+ password: root
+ socket: /var/run/mysqld/mysqld.sock
+
+# 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: mysql2
+ encoding: utf8
+ reconnect: false
+ database: store_test
+ pool: 5
+ username: root
+ password: root
+ socket: /var/run/mysqld/mysqld.sock
+
+production:
+ adapter: mysql2
+ encoding: utf8
+ reconnect: false
+ database: store_production
+ pool: 5
+ username: root
+ password: root
+ socket: /var/run/mysqld/mysqld.sock
View
5 store/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Store::Application.initialize!
View
30 store/config/environments/development.rb
@@ -0,0 +1,30 @@
+Store::Application.configure do
+ #