├── .gitignore ├── .rspec ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── README ├── README.md ├── Rakefile ├── app ├── controllers │ ├── application_controller.rb │ ├── customers_controller.rb │ ├── debts_controller.rb │ ├── invoices_controller.rb │ ├── line_items_controller.rb │ ├── messages_controller.rb │ ├── products_controller.rb │ ├── purchases_controller.rb │ └── suppliers_controller.rb ├── helpers │ ├── application_helper.rb │ ├── customers_helper.rb │ ├── debts_helper.rb │ ├── invoices_helper.rb │ ├── line_items_helper.rb │ ├── messages_helper.rb │ ├── products_helper.rb │ ├── purchases_helper.rb │ └── suppliers_helper.rb ├── models │ ├── customer.rb │ ├── debt.rb │ ├── invoice.rb │ ├── line_item.rb │ ├── message.rb │ ├── product.rb │ ├── purchase.rb │ └── supplier.rb └── views │ ├── customers │ ├── _form.html.erb │ ├── edit.html.erb │ ├── index.html.erb │ ├── new.html.erb │ └── show.html.erb │ ├── debts │ ├── _form.html.erb │ ├── edit.html.erb │ ├── index.html.erb │ ├── new.html.erb │ └── show.html.erb │ ├── invoices │ ├── _form.html.erb │ ├── edit.html.erb │ ├── index.html.erb │ ├── new.html.erb │ └── show.html.erb │ ├── layouts │ └── application.html.erb │ ├── line_items │ ├── _form.html.erb │ ├── edit.html.erb │ ├── index.html.erb │ ├── new.html.erb │ └── show.html.erb │ ├── messages │ ├── _message.html.erb │ ├── create.js.erb │ ├── create.js.rjs │ ├── index.html.erb │ └── message_table.js.erb │ ├── products │ ├── _form.html.erb │ ├── _hr.html.erb │ ├── _item.html.erb │ ├── edit.html.erb │ ├── index.html.erb │ ├── new.html.erb │ ├── search.html.erb │ └── show.html.erb │ ├── purchases │ ├── _form.html.erb │ ├── _invoice.html.erb │ ├── _no_invoice.html.erb │ ├── edit.html.erb │ ├── index.html.erb │ ├── new.html.erb │ └── show.html.erb │ └── suppliers │ ├── _form.html.erb │ ├── edit.html.erb │ ├── index.html.erb │ ├── new.html.erb │ └── show.html.erb ├── config.ru ├── config ├── application.rb ├── boot.rb ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── backtrace_silencers.rb │ ├── inflections.rb │ ├── mime_types.rb │ ├── secret_token.rb │ └── session_store.rb ├── locales │ ├── en.yml │ └── tl.yml └── routes.rb ├── db ├── migrate │ ├── 20110902025349_create_debts.rb │ ├── 20110902025801_add_remarks_to_debt.rb │ ├── 20110902030453_create_products.rb │ ├── 20110903171011_create_purchases.rb │ ├── 20110903171022_create_invoices.rb │ ├── 20110904032124_create_suppliers.rb │ ├── 20110904032133_add_supplier_to_purchase.rb │ ├── 20110904034903_create_products_purchases.rb │ ├── 20110904035142_create_line_items.rb │ ├── 20110904064039_create_messages.rb │ └── 20110904091702_create_customers.rb ├── schema.rb └── seeds.rb ├── doc └── README_FOR_APP ├── lib └── tasks │ └── .gitkeep ├── public ├── 404.html ├── 422.html ├── 500.html ├── favicon.ico ├── images │ └── rails.png ├── index.html ├── javascripts │ ├── application.js │ ├── jquery.js │ ├── jquery.min.js │ └── jquery_ujs.js ├── robots.txt └── stylesheets │ ├── .gitkeep │ └── scaffold.css ├── script └── rails ├── spec ├── controllers │ └── customers_controller_spec.rb ├── fixtures │ └── customers.yml ├── helpers │ ├── customers_helper_spec.rb │ └── invoices_helper_spec.rb ├── models │ └── customer_spec.rb ├── requests │ └── customers_spec.rb ├── routing │ └── customers_routing_spec.rb ├── spec_helper.rb └── views │ └── customers │ ├── edit.html.erb_spec.rb │ ├── index.html.erb_spec.rb │ ├── new.html.erb_spec.rb │ └── show.html.erb_spec.rb ├── test ├── fixtures │ ├── debts.yml │ ├── invoices.yml │ ├── line_items.yml │ ├── messages.yml │ ├── products.yml │ ├── purchases.yml │ └── suppliers.yml ├── functional │ ├── debts_controller_test.rb │ ├── invoices_controller_test.rb │ ├── line_items_controller_test.rb │ ├── messages_controller_test.rb │ ├── products_controller_test.rb │ ├── purchases_controller_test.rb │ └── suppliers_controller_test.rb ├── performance │ └── browsing_test.rb ├── test_helper.rb └── unit │ ├── debt_test.rb │ ├── helpers │ ├── debts_helper_test.rb │ ├── invoices_helper_test.rb │ ├── line_items_helper_test.rb │ ├── messages_helper_test.rb │ ├── products_helper_test.rb │ ├── purchases_helper_test.rb │ └── suppliers_helper_test.rb │ ├── invoice_test.rb │ ├── line_item_test.rb │ ├── message_test.rb │ ├── product_test.rb │ ├── purchase_test.rb │ └── supplier_test.rb └── vendor └── plugins └── .gitkeep /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle 2 | db/*.sqlite3 3 | log/*.log 4 | tmp/ 5 | webrat.log 6 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --colour 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'http://rubygems.org' 2 | 3 | gem 'rails', '3.0.10' 4 | gem 'sqlite3' 5 | gem 'jquery-rails' 6 | 7 | group :development, :test do 8 | gem 'rspec-rails', '2.5.0' 9 | gem 'webrat' 10 | end 11 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: http://rubygems.org/ 3 | specs: 4 | abstract (1.0.0) 5 | actionmailer (3.0.10) 6 | actionpack (= 3.0.10) 7 | mail (~> 2.2.19) 8 | actionpack (3.0.10) 9 | activemodel (= 3.0.10) 10 | activesupport (= 3.0.10) 11 | builder (~> 2.1.2) 12 | erubis (~> 2.6.6) 13 | i18n (~> 0.5.0) 14 | rack (~> 1.2.1) 15 | rack-mount (~> 0.6.14) 16 | rack-test (~> 0.5.7) 17 | tzinfo (~> 0.3.23) 18 | activemodel (3.0.10) 19 | activesupport (= 3.0.10) 20 | builder (~> 2.1.2) 21 | i18n (~> 0.5.0) 22 | activerecord (3.0.10) 23 | activemodel (= 3.0.10) 24 | activesupport (= 3.0.10) 25 | arel (~> 2.0.10) 26 | tzinfo (~> 0.3.23) 27 | activeresource (3.0.10) 28 | activemodel (= 3.0.10) 29 | activesupport (= 3.0.10) 30 | activesupport (3.0.10) 31 | arel (2.0.10) 32 | builder (2.1.2) 33 | diff-lcs (1.1.3) 34 | erubis (2.6.6) 35 | abstract (>= 1.0.0) 36 | i18n (0.5.0) 37 | jquery-rails (1.0.13) 38 | railties (~> 3.0) 39 | thor (~> 0.14) 40 | mail (2.2.19) 41 | activesupport (>= 2.3.6) 42 | i18n (>= 0.4.0) 43 | mime-types (~> 1.16) 44 | treetop (~> 1.4.8) 45 | mime-types (1.16) 46 | nokogiri (1.5.0) 47 | polyglot (0.3.2) 48 | rack (1.2.3) 49 | rack-mount (0.6.14) 50 | rack (>= 1.0.0) 51 | rack-test (0.5.7) 52 | rack (>= 1.0) 53 | rails (3.0.10) 54 | actionmailer (= 3.0.10) 55 | actionpack (= 3.0.10) 56 | activerecord (= 3.0.10) 57 | activeresource (= 3.0.10) 58 | activesupport (= 3.0.10) 59 | bundler (~> 1.0) 60 | railties (= 3.0.10) 61 | railties (3.0.10) 62 | actionpack (= 3.0.10) 63 | activesupport (= 3.0.10) 64 | rake (>= 0.8.7) 65 | rdoc (~> 3.4) 66 | thor (~> 0.14.4) 67 | rake (0.9.2) 68 | rdoc (3.9.4) 69 | rspec (2.5.0) 70 | rspec-core (~> 2.5.0) 71 | rspec-expectations (~> 2.5.0) 72 | rspec-mocks (~> 2.5.0) 73 | rspec-core (2.5.2) 74 | rspec-expectations (2.5.0) 75 | diff-lcs (~> 1.1.2) 76 | rspec-mocks (2.5.0) 77 | rspec-rails (2.5.0) 78 | actionpack (~> 3.0) 79 | activesupport (~> 3.0) 80 | railties (~> 3.0) 81 | rspec (~> 2.5.0) 82 | sqlite3 (1.3.4) 83 | thor (0.14.6) 84 | treetop (1.4.10) 85 | polyglot 86 | polyglot (>= 0.3.1) 87 | tzinfo (0.3.29) 88 | webrat (0.7.3) 89 | nokogiri (>= 1.2.0) 90 | rack (>= 1.0) 91 | rack-test (>= 0.5.3) 92 | 93 | PLATFORMS 94 | ruby 95 | 96 | DEPENDENCIES 97 | jquery-rails 98 | rails (= 3.0.10) 99 | rspec-rails (= 2.5.0) 100 | sqlite3 101 | webrat 102 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Bryan Bibat 2 | 3 | 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: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | 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. 8 | 9 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | == Welcome to Rails 2 | 3 | Rails is a web-application framework that includes everything needed to create 4 | database-backed web applications according to the Model-View-Control pattern. 5 | 6 | This pattern splits the view (also called the presentation) into "dumb" 7 | templates that are primarily responsible for inserting pre-built data in between 8 | HTML tags. The model contains the "smart" domain objects (such as Account, 9 | Product, Person, Post) that holds all the business logic and knows how to 10 | persist themselves to a database. The controller handles the incoming requests 11 | (such as Save New Account, Update Product, Show Post) by manipulating the model 12 | and directing data to the view. 13 | 14 | In Rails, the model is handled by what's called an object-relational mapping 15 | layer entitled Active Record. This layer allows you to present the data from 16 | database rows as objects and embellish these data objects with business logic 17 | methods. You can read more about Active Record in 18 | link:files/vendor/rails/activerecord/README.html. 19 | 20 | The controller and view are handled by the Action Pack, which handles both 21 | layers by its two parts: Action View and Action Controller. These two layers 22 | are bundled in a single package due to their heavy interdependence. This is 23 | unlike the relationship between the Active Record and Action Pack that is much 24 | more separate. Each of these packages can be used independently outside of 25 | Rails. You can read more about Action Pack in 26 | link:files/vendor/rails/actionpack/README.html. 27 | 28 | 29 | == Getting Started 30 | 31 | 1. At the command prompt, create a new Rails application: 32 | rails new myapp (where myapp is the application name) 33 | 34 | 2. Change directory to myapp and start the web server: 35 | cd myapp; rails server (run with --help for options) 36 | 37 | 3. Go to http://localhost:3000/ and you'll see: 38 | "Welcome aboard: You're riding Ruby on Rails!" 39 | 40 | 4. Follow the guidelines to start developing your application. You can find 41 | the following resources handy: 42 | 43 | * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html 44 | * Ruby on Rails Tutorial Book: http://www.railstutorial.org/ 45 | 46 | 47 | == Debugging Rails 48 | 49 | Sometimes your application goes wrong. Fortunately there are a lot of tools that 50 | will help you debug it and get it back on the rails. 51 | 52 | First area to check is the application log files. Have "tail -f" commands 53 | running on the server.log and development.log. Rails will automatically display 54 | debugging and runtime information to these files. Debugging info will also be 55 | shown in the browser on requests from 127.0.0.1. 56 | 57 | You can also log your own messages directly into the log file from your code 58 | using the Ruby logger class from inside your controllers. Example: 59 | 60 | class WeblogController < ActionController::Base 61 | def destroy 62 | @weblog = Weblog.find(params[:id]) 63 | @weblog.destroy 64 | logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!") 65 | end 66 | end 67 | 68 | The result will be a message in your log file along the lines of: 69 | 70 | Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1! 71 | 72 | More information on how to use the logger is at http://www.ruby-doc.org/core/ 73 | 74 | Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are 75 | several books available online as well: 76 | 77 | * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe) 78 | * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide) 79 | 80 | These two books will bring you up to speed on the Ruby language and also on 81 | programming in general. 82 | 83 | 84 | == Debugger 85 | 86 | Debugger support is available through the debugger command when you start your 87 | Mongrel or WEBrick server with --debugger. This means that you can break out of 88 | execution at any point in the code, investigate and change the model, and then, 89 | resume execution! You need to install ruby-debug to run the server in debugging 90 | mode. With gems, use sudo gem install ruby-debug. Example: 91 | 92 | class WeblogController < ActionController::Base 93 | def index 94 | @posts = Post.find(:all) 95 | debugger 96 | end 97 | end 98 | 99 | So the controller will accept the action, run the first line, then present you 100 | with a IRB prompt in the server window. Here you can do things like: 101 | 102 | >> @posts.inspect 103 | => "[#nil, "body"=>nil, "id"=>"1"}>, 105 | #"Rails", "body"=>"Only ten..", "id"=>"2"}>]" 107 | >> @posts.first.title = "hello from a debugger" 108 | => "hello from a debugger" 109 | 110 | ...and even better, you can examine how your runtime objects actually work: 111 | 112 | >> f = @posts.first 113 | => #nil, "body"=>nil, "id"=>"1"}> 114 | >> f. 115 | Display all 152 possibilities? (y or n) 116 | 117 | Finally, when you're ready to resume execution, you can enter "cont". 118 | 119 | 120 | == Console 121 | 122 | The console is a Ruby shell, which allows you to interact with your 123 | application's domain model. Here you'll have all parts of the application 124 | configured, just like it is when the application is running. You can inspect 125 | domain models, change values, and save to the database. Starting the script 126 | without arguments will launch it in the development environment. 127 | 128 | To start the console, run rails console from the application 129 | directory. 130 | 131 | Options: 132 | 133 | * Passing the -s, --sandbox argument will rollback any modifications 134 | made to the database. 135 | * Passing an environment name as an argument will load the corresponding 136 | environment. Example: rails console production. 137 | 138 | To reload your controllers and models after launching the console run 139 | reload! 140 | 141 | More information about irb can be found at: 142 | link:http://www.rubycentral.com/pickaxe/irb.html 143 | 144 | 145 | == dbconsole 146 | 147 | You can go to the command line of your database directly through rails 148 | dbconsole. You would be connected to the database with the credentials 149 | defined in database.yml. Starting the script without arguments will connect you 150 | to the development database. Passing an argument will connect you to a different 151 | database, like rails dbconsole production. Currently works for MySQL, 152 | PostgreSQL and SQLite 3. 153 | 154 | == Description of Contents 155 | 156 | The default directory structure of a generated Ruby on Rails application: 157 | 158 | |-- app 159 | | |-- controllers 160 | | |-- helpers 161 | | |-- mailers 162 | | |-- models 163 | | `-- views 164 | | `-- layouts 165 | |-- config 166 | | |-- environments 167 | | |-- initializers 168 | | `-- locales 169 | |-- db 170 | |-- doc 171 | |-- lib 172 | | `-- tasks 173 | |-- log 174 | |-- public 175 | | |-- images 176 | | |-- javascripts 177 | | `-- stylesheets 178 | |-- script 179 | |-- test 180 | | |-- fixtures 181 | | |-- functional 182 | | |-- integration 183 | | |-- performance 184 | | `-- unit 185 | |-- tmp 186 | | |-- cache 187 | | |-- pids 188 | | |-- sessions 189 | | `-- sockets 190 | `-- vendor 191 | `-- plugins 192 | 193 | app 194 | Holds all the code that's specific to this particular application. 195 | 196 | app/controllers 197 | Holds controllers that should be named like weblogs_controller.rb for 198 | automated URL mapping. All controllers should descend from 199 | ApplicationController which itself descends from ActionController::Base. 200 | 201 | app/models 202 | Holds models that should be named like post.rb. Models descend from 203 | ActiveRecord::Base by default. 204 | 205 | app/views 206 | Holds the template files for the view that should be named like 207 | weblogs/index.html.erb for the WeblogsController#index action. All views use 208 | eRuby syntax by default. 209 | 210 | app/views/layouts 211 | Holds the template files for layouts to be used with views. This models the 212 | common header/footer method of wrapping views. In your views, define a layout 213 | using the layout :default and create a file named default.html.erb. 214 | Inside default.html.erb, call <% yield %> to render the view using this 215 | layout. 216 | 217 | app/helpers 218 | Holds view helpers that should be named like weblogs_helper.rb. These are 219 | generated for you automatically when using generators for controllers. 220 | Helpers can be used to wrap functionality for your views into methods. 221 | 222 | config 223 | Configuration files for the Rails environment, the routing map, the database, 224 | and other dependencies. 225 | 226 | db 227 | Contains the database schema in schema.rb. db/migrate contains all the 228 | sequence of Migrations for your schema. 229 | 230 | doc 231 | This directory is where your application documentation will be stored when 232 | generated using rake doc:app 233 | 234 | lib 235 | Application specific libraries. Basically, any kind of custom code that 236 | doesn't belong under controllers, models, or helpers. This directory is in 237 | the load path. 238 | 239 | public 240 | The directory available for the web server. Contains subdirectories for 241 | images, stylesheets, and javascripts. Also contains the dispatchers and the 242 | default HTML files. This should be set as the DOCUMENT_ROOT of your web 243 | server. 244 | 245 | script 246 | Helper scripts for automation and generation. 247 | 248 | test 249 | Unit and functional tests along with fixtures. When using the rails generate 250 | command, template test files will be generated for you and placed in this 251 | directory. 252 | 253 | vendor 254 | External libraries that the application depends on. Also includes the plugins 255 | subdirectory. If the app has frozen rails, those gems also go here, under 256 | vendor/rails/. This directory is in the load path. 257 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Companion code to [Ruby on Rails 3.0: A free student manual](https://github.com/bryanbibat/rails-3_0-tutorial). 2 | 3 | More information in that project. 4 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | require 'rake' 6 | 7 | AlingnenaApp::Application.load_tasks 8 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery 3 | before_filter :set_locale 4 | 5 | private 6 | def set_locale 7 | I18n.locale = params[:locale] || session[:locale] 8 | session[:locale] = params[:locale] if params.has_key? :locale 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /app/controllers/customers_controller.rb: -------------------------------------------------------------------------------- 1 | class CustomersController < ApplicationController 2 | # GET /customers 3 | # GET /customers.xml 4 | def index 5 | @customers = Customer.find_all_by_active(true) 6 | 7 | respond_to do |format| 8 | format.html # index.html.erb 9 | format.xml { render :xml => @customers } 10 | end 11 | end 12 | 13 | # GET /customers/1 14 | # GET /customers/1.xml 15 | def show 16 | @customer = Customer.find(params[:id]) 17 | 18 | if @customer.active? 19 | respond_to do |format| 20 | format.html # show.html.erb 21 | format.xml { render :xml => @customer } 22 | end 23 | else 24 | respond_to do |format| 25 | format.html { redirect_to customers_url, :notice => "Record does not exist" } 26 | end 27 | end 28 | end 29 | 30 | # GET /customers/new 31 | # GET /customers/new.xml 32 | def new 33 | @customer = Customer.new 34 | 35 | respond_to do |format| 36 | format.html # new.html.erb 37 | format.xml { render :xml => @customer } 38 | end 39 | end 40 | 41 | # GET /customers/1/edit 42 | def edit 43 | @customer = Customer.find(params[:id]) 44 | end 45 | 46 | # POST /customers 47 | # POST /customers.xml 48 | def create 49 | @customer = Customer.new(params[:customer]) 50 | 51 | respond_to do |format| 52 | if @customer.save 53 | format.html { redirect_to(@customer, :notice => 'Customer was successfully created.') } 54 | format.xml { render :xml => @customer, :status => :created, :location => @customer } 55 | else 56 | format.html { render :action => "new" } 57 | format.xml { render :xml => @customer.errors, :status => :unprocessable_entity } 58 | end 59 | end 60 | end 61 | 62 | # PUT /customers/1 63 | # PUT /customers/1.xml 64 | def update 65 | @customer = Customer.find(params[:id]) 66 | 67 | respond_to do |format| 68 | if @customer.update_attributes(params[:customer]) 69 | format.html { redirect_to(@customer, :notice => 'Customer was successfully updated.') } 70 | format.xml { head :ok } 71 | else 72 | format.html { render :action => "edit" } 73 | format.xml { render :xml => @customer.errors, :status => :unprocessable_entity } 74 | end 75 | end 76 | end 77 | 78 | # DELETE /customers/1 79 | # DELETE /customers/1.xml 80 | def destroy 81 | @customer = Customer.find(params[:id]) 82 | @customer.destroy 83 | 84 | respond_to do |format| 85 | format.html { redirect_to(customers_url) } 86 | format.xml { head :ok } 87 | end 88 | end 89 | end 90 | -------------------------------------------------------------------------------- /app/controllers/debts_controller.rb: -------------------------------------------------------------------------------- 1 | class DebtsController < ApplicationController 2 | # GET /debts 3 | # GET /debts.xml 4 | def index 5 | @debts = Debt.all 6 | 7 | respond_to do |format| 8 | format.html # index.html.erb 9 | format.xml { render :xml => @debts } 10 | end 11 | end 12 | 13 | # GET /debts/1 14 | # GET /debts/1.xml 15 | def show 16 | @debt = Debt.find(params[:id]) 17 | 18 | respond_to do |format| 19 | format.html # show.html.erb 20 | format.xml { render :xml => @debt } 21 | end 22 | end 23 | 24 | # GET /debts/new 25 | # GET /debts/new.xml 26 | def new 27 | @debt = Debt.new 28 | 29 | respond_to do |format| 30 | format.html # new.html.erb 31 | format.xml { render :xml => @debt } 32 | end 33 | end 34 | 35 | # GET /debts/1/edit 36 | def edit 37 | @debt = Debt.find(params[:id]) 38 | end 39 | 40 | # POST /debts 41 | # POST /debts.xml 42 | def create 43 | @debt = Debt.new(params[:debt]) 44 | 45 | respond_to do |format| 46 | if @debt.save 47 | format.html { redirect_to(@debt, :notice => 'Debt was successfully created.') } 48 | format.xml { render :xml => @debt, :status => :created, :location => @debt } 49 | else 50 | format.html { render :action => "new" } 51 | format.xml { render :xml => @debt.errors, :status => :unprocessable_entity } 52 | end 53 | end 54 | end 55 | 56 | # PUT /debts/1 57 | # PUT /debts/1.xml 58 | def update 59 | @debt = Debt.find(params[:id]) 60 | 61 | respond_to do |format| 62 | if @debt.update_attributes(params[:debt]) 63 | format.html { redirect_to(@debt, :notice => 'Debt was successfully updated.') } 64 | format.xml { head :ok } 65 | else 66 | format.html { render :action => "edit" } 67 | format.xml { render :xml => @debt.errors, :status => :unprocessable_entity } 68 | end 69 | end 70 | end 71 | 72 | # DELETE /debts/1 73 | # DELETE /debts/1.xml 74 | def destroy 75 | @debt = Debt.find(params[:id]) 76 | @debt.destroy 77 | 78 | respond_to do |format| 79 | format.html { redirect_to(debts_url) } 80 | format.xml { head :ok } 81 | end 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /app/controllers/invoices_controller.rb: -------------------------------------------------------------------------------- 1 | class InvoicesController < ApplicationController 2 | def show 3 | # we'll integrate the Invoice details in the Show Purchase screen 4 | redirect_to purchase_path(params[:purchase_id]) 5 | end 6 | 7 | def new 8 | @purchase = Purchase.find(params[:purchase_id]) 9 | @invoice = @purchase.build_invoice 10 | end 11 | 12 | def edit 13 | @purchase = Purchase.find(params[:purchase_id]) 14 | @invoice = @purchase.invoice 15 | end 16 | 17 | def create 18 | @purchase = Purchase.find(params[:purchase_id]) 19 | @invoice = @purchase.build_invoice(params[:invoice]) 20 | 21 | if @invoice.save 22 | redirect_to @purchase, :notice => 'Invoice was successfully created.' 23 | else 24 | render :action => "new" 25 | end 26 | end 27 | 28 | def update 29 | @purchase = Purchase.find(params[:purchase_id]) 30 | @invoice = @purchase.invoice 31 | 32 | if @invoice.update_attributes(params[:invoice]) 33 | redirect_to @purchase, :notice => 'Invoice was successfully updated.' 34 | else 35 | render :action => "edit" 36 | end 37 | end 38 | 39 | def destroy 40 | @purchase = Purchase.find(params[:purchase_id]) 41 | @invoice = @purchase.invoice 42 | @invoice.destroy 43 | redirect_to @purchase 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /app/controllers/line_items_controller.rb: -------------------------------------------------------------------------------- 1 | class LineItemsController < ApplicationController 2 | def index 3 | # integrate with show purchase 4 | redirect_to Purchase.find(params[:purchase_id]) 5 | end 6 | 7 | def show 8 | # integrate with show purchase 9 | redirect_to Purchase.find(params[:purchase_id]) 10 | end 11 | 12 | def new 13 | @purchase = Purchase.find(params[:purchase_id]) 14 | @line_item = @purchase.line_items.build 15 | end 16 | 17 | def edit 18 | @purchase = Purchase.find(params[:purchase_id]) 19 | @line_item = @purchase.line_items.find(params[:id]) 20 | end 21 | 22 | def create 23 | @purchase = Purchase.find(params[:purchase_id]) 24 | @line_item = @purchase.line_items.build(params[:line_item]) 25 | 26 | if @line_item.save 27 | redirect_to @purchase, :notice => 'Line Item was successfully created.' 28 | else 29 | render :action => "new" 30 | end 31 | end 32 | 33 | def update 34 | @purchase = Purchase.find(params[:purchase_id]) 35 | @line_item = @purchase.line_items.find(params[:id]) 36 | 37 | if @line_item.update_attributes(params[:line_item]) 38 | redirect_to @purchase, :notice => 'Line Item was successfully updated.' 39 | else 40 | render :action => "edit" 41 | end 42 | end 43 | 44 | def destroy 45 | @purchase = Purchase.find(params[:purchase_id]) 46 | @line_item = @purchase.line_items.find(params[:id]) 47 | @line_item.destroy 48 | redirect_to @purchase, :notice => 'Line Item was successfully deleted.' 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /app/controllers/messages_controller.rb: -------------------------------------------------------------------------------- 1 | class MessagesController < ApplicationController 2 | # GET /messages 3 | # GET /messages.xml 4 | def index 5 | @message = Message.new 6 | @messages = Message.order("created_at DESC") 7 | 8 | respond_to do |format| 9 | format.html # index.html.erb 10 | format.xml { render :xml => @messages } 11 | end 12 | end 13 | 14 | def message_table 15 | respond_to do |format| 16 | format.js 17 | format.html { render :partial => Message.order("created_at DESC") } 18 | end 19 | end 20 | 21 | # POST /messages 22 | # POST /messages.xml 23 | def create 24 | @message = Message.new(params[:message]) 25 | 26 | respond_to do |format| 27 | if @message.save 28 | format.html { redirect_to(messages_path, :notice => 'Message was successfully created.') } 29 | format.xml { render :xml => @message, :status => :created, :location => @message } 30 | format.js 31 | else 32 | @messages = Message.order("created_at DESC") 33 | format.html { render :action => "index" } 34 | format.xml { render :xml => @message.errors, :status => :unprocessable_entity } 35 | format.js { render :text => "$('#notice').show().html('There was an error in creating the message.')" } 36 | end 37 | end 38 | end 39 | 40 | end 41 | -------------------------------------------------------------------------------- /app/controllers/products_controller.rb: -------------------------------------------------------------------------------- 1 | class ProductsController < ApplicationController 2 | before_filter :check_if_aling_nena, :except => [:index, :show, :search] 3 | 4 | def index 5 | @products = Product.all 6 | end 7 | 8 | def search 9 | @products = Product.find_all_by_name(params[:name]) 10 | end 11 | 12 | def show 13 | @product = Product.find(params[:id]) 14 | end 15 | 16 | def new 17 | @product = Product.new 18 | end 19 | 20 | def create 21 | @product = Product.new(params[:product]) 22 | 23 | if @product.save 24 | redirect_to @product, :notice => "Product has been successfully created." 25 | else 26 | render :action => "new" 27 | end 28 | end 29 | 30 | def edit 31 | @product = Product.find(params[:id]) 32 | end 33 | 34 | def update 35 | @product = Product.find(params[:id]) 36 | 37 | if @product.update_attributes(params[:product]) 38 | redirect_to @product, :notice => 'Product was successfully updated.' 39 | else 40 | render :action => "edit" 41 | end 42 | end 43 | 44 | def destroy 45 | @product = Product.find(params[:id]) 46 | @product.destroy 47 | redirect_to products_path, :notice => "Product was successfully deleted." 48 | end 49 | 50 | private 51 | 52 | def check_if_aling_nena 53 | authenticate_or_request_with_http_basic("Products Realm") do |username, password| 54 | username == "admin" and password == "sTr0NG_p4$swOrD" 55 | end 56 | end 57 | 58 | end 59 | -------------------------------------------------------------------------------- /app/controllers/purchases_controller.rb: -------------------------------------------------------------------------------- 1 | class PurchasesController < ApplicationController 2 | # GET /purchases 3 | # GET /purchases.xml 4 | def index 5 | @purchases = Purchase.all 6 | 7 | respond_to do |format| 8 | format.html # index.html.erb 9 | format.xml { render :xml => @purchases } 10 | end 11 | end 12 | 13 | # GET /purchases/1 14 | # GET /purchases/1.xml 15 | def show 16 | @purchase = Purchase.includes(:line_items => :product).find(params[:id]) 17 | 18 | respond_to do |format| 19 | format.html # show.html.erb 20 | format.xml { render :xml => @purchase } 21 | end 22 | end 23 | 24 | # GET /purchases/new 25 | # GET /purchases/new.xml 26 | def new 27 | @purchase = Purchase.new 28 | 29 | respond_to do |format| 30 | format.html # new.html.erb 31 | format.xml { render :xml => @purchase } 32 | end 33 | end 34 | 35 | # GET /purchases/1/edit 36 | def edit 37 | @purchase = Purchase.find(params[:id]) 38 | end 39 | 40 | # POST /purchases 41 | # POST /purchases.xml 42 | def create 43 | @purchase = Purchase.new(params[:purchase]) 44 | 45 | respond_to do |format| 46 | if @purchase.save 47 | format.html { redirect_to(@purchase, :notice => 'Purchase was successfully created.') } 48 | format.xml { render :xml => @purchase, :status => :created, :location => @purchase } 49 | else 50 | format.html { render :action => "new" } 51 | format.xml { render :xml => @purchase.errors, :status => :unprocessable_entity } 52 | end 53 | end 54 | end 55 | 56 | # PUT /purchases/1 57 | # PUT /purchases/1.xml 58 | def update 59 | @purchase = Purchase.find(params[:id]) 60 | 61 | respond_to do |format| 62 | if @purchase.update_attributes(params[:purchase]) 63 | format.html { redirect_to(@purchase, :notice => 'Purchase was successfully updated.') } 64 | format.xml { head :ok } 65 | else 66 | format.html { render :action => "edit" } 67 | format.xml { render :xml => @purchase.errors, :status => :unprocessable_entity } 68 | end 69 | end 70 | end 71 | 72 | # DELETE /purchases/1 73 | # DELETE /purchases/1.xml 74 | def destroy 75 | @purchase = Purchase.find(params[:id]) 76 | @purchase.destroy 77 | 78 | respond_to do |format| 79 | format.html { redirect_to(purchases_url) } 80 | format.xml { head :ok } 81 | end 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /app/controllers/suppliers_controller.rb: -------------------------------------------------------------------------------- 1 | class SuppliersController < ApplicationController 2 | # GET /suppliers 3 | # GET /suppliers.xml 4 | def index 5 | @suppliers = Supplier.all 6 | 7 | respond_to do |format| 8 | format.html # index.html.erb 9 | format.xml { render :xml => @suppliers } 10 | end 11 | end 12 | 13 | # GET /suppliers/1 14 | # GET /suppliers/1.xml 15 | def show 16 | @supplier = Supplier.find(params[:id]) 17 | 18 | respond_to do |format| 19 | format.html # show.html.erb 20 | format.xml { render :xml => @supplier } 21 | end 22 | end 23 | 24 | # GET /suppliers/new 25 | # GET /suppliers/new.xml 26 | def new 27 | @supplier = Supplier.new 28 | 29 | respond_to do |format| 30 | format.html # new.html.erb 31 | format.xml { render :xml => @supplier } 32 | end 33 | end 34 | 35 | # GET /suppliers/1/edit 36 | def edit 37 | @supplier = Supplier.find(params[:id]) 38 | end 39 | 40 | # POST /suppliers 41 | # POST /suppliers.xml 42 | def create 43 | @supplier = Supplier.new(params[:supplier]) 44 | 45 | respond_to do |format| 46 | if @supplier.save 47 | format.html { redirect_to(@supplier, :notice => 'Supplier was successfully created.') } 48 | format.xml { render :xml => @supplier, :status => :created, :location => @supplier } 49 | else 50 | format.html { render :action => "new" } 51 | format.xml { render :xml => @supplier.errors, :status => :unprocessable_entity } 52 | end 53 | end 54 | end 55 | 56 | # PUT /suppliers/1 57 | # PUT /suppliers/1.xml 58 | def update 59 | @supplier = Supplier.find(params[:id]) 60 | 61 | respond_to do |format| 62 | if @supplier.update_attributes(params[:supplier]) 63 | format.html { redirect_to(@supplier, :notice => 'Supplier was successfully updated.') } 64 | format.xml { head :ok } 65 | else 66 | format.html { render :action => "edit" } 67 | format.xml { render :xml => @supplier.errors, :status => :unprocessable_entity } 68 | end 69 | end 70 | end 71 | 72 | # DELETE /suppliers/1 73 | # DELETE /suppliers/1.xml 74 | def destroy 75 | @supplier = Supplier.find(params[:id]) 76 | @supplier.destroy 77 | 78 | respond_to do |format| 79 | format.html { redirect_to(suppliers_url) } 80 | format.xml { head :ok } 81 | end 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/customers_helper.rb: -------------------------------------------------------------------------------- 1 | module CustomersHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/debts_helper.rb: -------------------------------------------------------------------------------- 1 | module DebtsHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/invoices_helper.rb: -------------------------------------------------------------------------------- 1 | module InvoicesHelper 2 | def display_purchase(invoice) 3 | unless invoice.purchase.nil? 4 | link_to invoice.purchase.description, invoice.purchase 5 | else 6 | "(no Purchase set)" 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /app/helpers/line_items_helper.rb: -------------------------------------------------------------------------------- 1 | module LineItemsHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/messages_helper.rb: -------------------------------------------------------------------------------- 1 | module MessagesHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/products_helper.rb: -------------------------------------------------------------------------------- 1 | module ProductsHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/purchases_helper.rb: -------------------------------------------------------------------------------- 1 | module PurchasesHelper 2 | def display_invoice(purchase) 3 | unless purchase.invoice.nil? 4 | render 'invoice', :purchase => @purchase 5 | else 6 | render 'no_invoice', :purchase => @purchase 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /app/helpers/suppliers_helper.rb: -------------------------------------------------------------------------------- 1 | module SuppliersHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/models/customer.rb: -------------------------------------------------------------------------------- 1 | class Customer < ActiveRecord::Base 2 | before_create :activate 3 | 4 | def destroy 5 | self.active = false 6 | end 7 | 8 | private 9 | def activate 10 | self.active = true 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /app/models/debt.rb: -------------------------------------------------------------------------------- 1 | class Debt < ActiveRecord::Base 2 | end 3 | -------------------------------------------------------------------------------- /app/models/invoice.rb: -------------------------------------------------------------------------------- 1 | class Invoice < ActiveRecord::Base 2 | belongs_to :purchase 3 | end 4 | -------------------------------------------------------------------------------- /app/models/line_item.rb: -------------------------------------------------------------------------------- 1 | class LineItem < ActiveRecord::Base 2 | belongs_to :purchase 3 | belongs_to :product 4 | end 5 | -------------------------------------------------------------------------------- /app/models/message.rb: -------------------------------------------------------------------------------- 1 | class Message < ActiveRecord::Base 2 | validates_presence_of :author, :message 3 | end 4 | -------------------------------------------------------------------------------- /app/models/product.rb: -------------------------------------------------------------------------------- 1 | class Product < ActiveRecord::Base 2 | validates_presence_of :name, :description 3 | has_many :line_items 4 | has_many :purchases, :through => :line_items, :uniq => true 5 | 6 | before_validation :assign_default_description 7 | 8 | private 9 | 10 | def assign_default_description 11 | if description.blank? 12 | self.description = name 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /app/models/purchase.rb: -------------------------------------------------------------------------------- 1 | class Purchase < ActiveRecord::Base 2 | has_one :invoice 3 | belongs_to :supplier 4 | has_many :line_items 5 | has_many :products, :through => :line_items, :uniq => true 6 | 7 | def display_supplier 8 | return supplier.name unless supplier.nil? 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /app/models/supplier.rb: -------------------------------------------------------------------------------- 1 | class Supplier < ActiveRecord::Base 2 | has_many :purchases 3 | end 4 | -------------------------------------------------------------------------------- /app/views/customers/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for(@customer) do |f| %> 2 | <% if @customer.errors.any? %> 3 |
4 |

<%= pluralize(@customer.errors.count, "error") %> prohibited this customer from being saved:

5 | 6 |
    7 | <% @customer.errors.full_messages.each do |msg| %> 8 |
  • <%= msg %>
  • 9 | <% end %> 10 |
11 |
12 | <% end %> 13 | 14 |
15 | <%= f.label :name %>
16 | <%= f.text_field :name %> 17 |
18 |
19 | <%= f.label :active %>
20 | <%= f.check_box :active %> 21 |
22 |
23 | <%= f.submit %> 24 |
25 | <% end %> 26 | -------------------------------------------------------------------------------- /app/views/customers/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Editing customer

2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Show', @customer %> | 6 | <%= link_to 'Back', customers_path %> 7 | -------------------------------------------------------------------------------- /app/views/customers/index.html.erb: -------------------------------------------------------------------------------- 1 |

Listing customers

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | <% @customers.each do |customer| %> 12 | 13 | 14 | 15 | 16 | 17 | 18 | <% end %> 19 |
Name
<%= customer.name %><%= link_to 'Show', customer %><%= link_to 'Edit', edit_customer_path(customer) %><%= link_to 'Destroy', customer, :confirm => 'Are you sure?', :method => :delete %>
20 | 21 |
22 | 23 | <%= link_to 'New Customer', new_customer_path %> 24 | -------------------------------------------------------------------------------- /app/views/customers/new.html.erb: -------------------------------------------------------------------------------- 1 |

New customer

2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Back', customers_path %> 6 | -------------------------------------------------------------------------------- /app/views/customers/show.html.erb: -------------------------------------------------------------------------------- 1 |

<%= notice %>

2 | 3 |

4 | Name: 5 | <%= @customer.name %> 6 |

7 | 8 |

9 | Active: 10 | <%= @customer.active %> 11 |

12 | 13 | 14 | <%= link_to 'Edit', edit_customer_path(@customer) %> | 15 | <%= link_to 'Back', customers_path %> 16 | -------------------------------------------------------------------------------- /app/views/debts/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for(@debt) do |f| %> 2 | <% if @debt.errors.any? %> 3 |
4 |

<%= pluralize(@debt.errors.count, "error") %> prohibited this debt from being saved:

5 | 6 |
    7 | <% @debt.errors.full_messages.each do |msg| %> 8 |
  • <%= msg %>
  • 9 | <% end %> 10 |
11 |
12 | <% end %> 13 | 14 |
15 | <%= f.label :name %>
16 | <%= f.text_field :name %> 17 |
18 |
19 | <%= f.label :item %>
20 | <%= f.text_area :item %> 21 |
22 |
23 | <%= f.label :amount %>
24 | <%= f.text_field :amount %> 25 |
26 |
27 | <%= f.label :remarks %>
28 | <%= f.text_area :remarks %> 29 |
30 |
31 | <%= f.submit %> 32 |
33 | <% end %> 34 | -------------------------------------------------------------------------------- /app/views/debts/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Editing debt

2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Show', @debt %> | 6 | <%= link_to 'Back', debts_path %> 7 | -------------------------------------------------------------------------------- /app/views/debts/index.html.erb: -------------------------------------------------------------------------------- 1 |

Listing debts

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | <% @debts.each do |debt| %> 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | <% end %> 25 |
NameItemAmountRemarks
<%= debt.name %><%= debt.item %><%= debt.amount %><%= debt.remarks %><%= link_to 'Show', debt %><%= link_to 'Edit', edit_debt_path(debt) %><%= link_to 'Destroy', debt, :confirm => 'Are you sure?', :method => :delete %>
26 | 27 |
28 | 29 | <%= link_to 'New Debt', new_debt_path %> 30 | -------------------------------------------------------------------------------- /app/views/debts/new.html.erb: -------------------------------------------------------------------------------- 1 |

New debt

2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Back', debts_path %> 6 | -------------------------------------------------------------------------------- /app/views/debts/show.html.erb: -------------------------------------------------------------------------------- 1 |

<%= notice %>

2 | 3 |

4 | Name: 5 | <%= @debt.name %> 6 |

7 | 8 |

9 | Item: 10 | <%= @debt.item %> 11 |

12 | 13 |

14 | Amount: 15 | <%= @debt.amount %> 16 |

17 | 18 |

19 | Remarks: 20 | <%= @debt.remarks %> 21 |

22 | 23 | <%= link_to 'Edit', edit_debt_path(@debt) %> | 24 | <%= link_to 'Back', debts_path %> 25 | -------------------------------------------------------------------------------- /app/views/invoices/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for(invoice, :url => purchase_invoice_path(purchase)) do |f| %> 2 | <% if invoice.errors.any? %> 3 |
4 |

<%= pluralize(invoice.errors.count, "error") %> prohibited this invoice from being saved:

5 | 6 |
    7 | <% invoice.errors.full_messages.each do |msg| %> 8 |
  • <%= msg %>
  • 9 | <% end %> 10 |
11 |
12 | <% end %> 13 | 14 |
15 |
16 | <%= purchase.description %> 17 |
18 |
19 | <%= f.label :reference_number %>
20 | <%= f.text_field :reference_number %> 21 |
22 |
23 | <%= f.submit %> 24 |
25 | <% end %> 26 | 27 | <%= link_to 'Back', purchase %> 28 | -------------------------------------------------------------------------------- /app/views/invoices/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Editing invoice

2 | 3 | <%= render 'form', :purchase => @purchase, :invoice => @invoice %> 4 | -------------------------------------------------------------------------------- /app/views/invoices/index.html.erb: -------------------------------------------------------------------------------- 1 |

Listing invoices

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <% @invoices.each do |invoice| %> 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | <% end %> 21 |
PurchaseReference number
<%= display_purchase(invoice) %><%= invoice.reference_number %><%= link_to 'Show', invoice %><%= link_to 'Edit', edit_invoice_path(invoice) %><%= link_to 'Destroy', invoice, :confirm => 'Are you sure?', :method => :delete %>
22 | 23 |
24 | 25 | <%= link_to 'New Invoice', new_invoice_path %> 26 | -------------------------------------------------------------------------------- /app/views/invoices/new.html.erb: -------------------------------------------------------------------------------- 1 |

New invoice

2 | 3 | <%= render 'form', :purchase => @purchase, :invoice => @invoice %> 4 | -------------------------------------------------------------------------------- /app/views/invoices/show.html.erb: -------------------------------------------------------------------------------- 1 |

<%= notice %>

2 | 3 |

4 | Purchase: 5 | <%= display_purchase(@invoice) %> 6 |

7 | 8 |

9 | Reference number: 10 | <%= @invoice.reference_number %> 11 |

12 | 13 | 14 | <%= link_to 'Edit', edit_invoice_path(@invoice) %> | 15 | <%= link_to 'Back', invoices_path %> 16 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AlingnenaApp 5 | <%= stylesheet_link_tag :all %> 6 | <%= javascript_include_tag :defaults %> 7 | <%= csrf_meta_tag %> 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/views/line_items/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for([purchase, line_item]) do |f| %> 2 | <% if line_item.errors.any? %> 3 |
4 |

<%= pluralize(line_item.errors.count, "error") %> prohibited this line_item from being saved:

5 | 6 |
    7 | <% line_item.errors.full_messages.each do |msg| %> 8 |
  • <%= msg %>
  • 9 | <% end %> 10 |
11 |
12 | <% end %> 13 | 14 |
15 |
16 | <%= purchase.description %> 17 |
18 |
19 | <%= f.label :product_id, "Product" %>
20 | <%= f.collection_select :product_id, Product.all, :id, :name, :prompt => true %> 21 |
22 |
23 | <%= f.label :quantity %>
24 | <%= f.text_field :quantity %> 25 |
26 |
27 | <%= f.label :cost %>
28 | <%= f.text_field :cost %> 29 |
30 |
31 | <%= f.submit %> 32 |
33 | <% end %> 34 | 35 | <%= link_to 'Back', purchase %> 36 | -------------------------------------------------------------------------------- /app/views/line_items/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Editing Line Item

2 | 3 | <%= render 'form', :purchase => @purchase, :line_item => @line_item %> 4 | -------------------------------------------------------------------------------- /app/views/line_items/index.html.erb: -------------------------------------------------------------------------------- 1 |

Listing line_items

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | <% @line_items.each do |line_item| %> 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | <% end %> 25 |
PurchaseProductQuantityCost
<%= line_item.purchase %><%= line_item.product %><%= line_item.quantity %><%= line_item.cost %><%= link_to 'Show', line_item %><%= link_to 'Edit', edit_line_item_path(line_item) %><%= link_to 'Destroy', line_item, :confirm => 'Are you sure?', :method => :delete %>
26 | 27 |
28 | 29 | <%= link_to 'New Line item', new_line_item_path %> 30 | -------------------------------------------------------------------------------- /app/views/line_items/new.html.erb: -------------------------------------------------------------------------------- 1 |

New Line Item

2 | 3 | <%= render 'form', :purchase => @purchase, :line_item => @line_item %> 4 | -------------------------------------------------------------------------------- /app/views/line_items/show.html.erb: -------------------------------------------------------------------------------- 1 |

<%= notice %>

2 | 3 |

4 | Purchase: 5 | <%= @line_item.purchase %> 6 |

7 | 8 |

9 | Product: 10 | <%= @line_item.product %> 11 |

12 | 13 |

14 | Quantity: 15 | <%= @line_item.quantity %> 16 |

17 | 18 |

19 | Cost: 20 | <%= @line_item.cost %> 21 |

22 | 23 | 24 | <%= link_to 'Edit', edit_line_item_path(@line_item) %> | 25 | <%= link_to 'Back', line_items_path %> 26 | -------------------------------------------------------------------------------- /app/views/messages/_message.html.erb: -------------------------------------------------------------------------------- 1 |
  • 2 | <%= message.author %> said 3 | (<%= time_ago_in_words(message.created_at) %> ago): 4 | <%= message.message %> 5 |
  • 6 | -------------------------------------------------------------------------------- /app/views/messages/create.js.erb: -------------------------------------------------------------------------------- 1 | $("#message_list").html("<%= escape_javascript( 2 | render :partial => Message.all(:order => "created_at DESC") ) %>"); 3 | $("#notice").show().html("Message was successfully created.").delay(20000).fadeOut("slow"); 4 | $("#new_message")[0].reset(); 5 | -------------------------------------------------------------------------------- /app/views/messages/create.js.rjs: -------------------------------------------------------------------------------- 1 | page.show 'notice' 2 | page.replace_html :message_list, 3 | :partial => Message.all(:order => "created_at DESC") 4 | page.replace_html :notice, 'Message was successfully created.' 5 | page[:new_message].reset 6 | page.delay(20) do 7 | page.visual_effect :fade, 'notice' 8 | end 9 | -------------------------------------------------------------------------------- /app/views/messages/index.html.erb: -------------------------------------------------------------------------------- 1 |

    <%= notice %>

    2 | 3 |

    Aling Nena's Shoutbox

    4 | 5 | <%= form_for(@message, :remote => true) do |f| %> 6 | <% if @message.errors.any? %> 7 |
    8 |

    <%= pluralize(@message.errors.count, "error") %> prohibited this message from being saved:

    9 | 10 |
      11 | <% @message.errors.full_messages.each do |msg| %> 12 |
    • <%= msg %>
    • 13 | <% end %> 14 |
    15 |
    16 | <% end %> 17 | 18 |
    19 | <%= f.label :author, "Name" %>
    20 | <%= f.text_field :author %> 21 |
    22 |
    23 | <%= f.label :message %>
    24 | <%= f.text_field :message %> 25 |
    26 |
    27 | <%= f.submit %> 28 |
    29 | <% end %> 30 | 31 |

    Messages

    32 | 33 |
      34 | <%= render :partial => @messages %> 35 |
    36 | -------------------------------------------------------------------------------- /app/views/messages/message_table.js.erb: -------------------------------------------------------------------------------- 1 | $("#message_list").html("<%= escape_javascript( 2 | render :partial => Message.all(:order => "created_at desc") ) %>"); 3 | -------------------------------------------------------------------------------- /app/views/products/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for product do |f| %> 2 | <% if product.errors.any? %> 3 |
    4 |

    <%= t "activerecord.errors.template.header", 5 | :count => product.errors.count, 6 | :model => product.class.model_name.human.downcase %>:

    7 |
      8 | <% product.errors.full_messages.each do |msg| %> 9 |
    • <%= msg %>
    • 10 | <% end %> 11 |
    12 |
    13 | <% end %> 14 | 15 |
    16 | <%= f.label :name %>
    17 | <%= f.text_field :name %> 18 |
    19 |
    20 | <%= f.label :description %>
    21 | <%= f.text_area :description, :size => "35x3" %> 22 |
    23 |
    24 | <%= f.label :cost %>
    25 | <%= f.text_field :cost %> 26 |
    27 |
    28 | <%= f.label :stock %>
    29 | <%= f.text_field :stock %> 30 |
    31 |
    32 | <%= f.submit button_label %> 33 |
    34 | <% end %> 35 | -------------------------------------------------------------------------------- /app/views/products/_hr.html.erb: -------------------------------------------------------------------------------- 1 |
    2 | 3 | -------------------------------------------------------------------------------- /app/views/products/_item.html.erb: -------------------------------------------------------------------------------- 1 | 2 | <%= item.name %> 3 | <%= item.description %> 4 | <%= number_to_currency item.cost, :unit => 'PhP' %> 5 | <%= item.stock %> 6 | <%= link_to 'Show', item %> 7 | <%= link_to 'Edit', edit_product_path(item) %> 8 | 9 | -------------------------------------------------------------------------------- /app/views/products/edit.html.erb: -------------------------------------------------------------------------------- 1 |

    Edit Product

    2 | 3 | <%= render :partial => "form", 4 | :locals => { :product => @product, :button_label => "Update" } %> 5 | 6 | <%= link_to 'Show', @product %> | 7 | <%= link_to 'Back', products_path %> 8 | -------------------------------------------------------------------------------- /app/views/products/index.html.erb: -------------------------------------------------------------------------------- 1 |

    <%= flash[:notice] %>

    2 | 3 | <%= form_tag search_products_path, {:method => :get} do %> 4 | <%= label_tag "name", "Search by product name:" %> 5 | <%= text_field_tag "name" %> 6 | <%= submit_tag "Search" %> 7 | <% end %> 8 | 9 |

    Listing Products

    10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | <%= render :partial => "item", :collection => @products, :spacer_template => "hr" %> 19 |
    NameDescriptionCostStock
    20 | 21 |

    <%= link_to "Create a new Product", new_product_path %>

    22 | -------------------------------------------------------------------------------- /app/views/products/new.html.erb: -------------------------------------------------------------------------------- 1 |

    <%=t 'views.product.header.new' %>

    2 | 3 | <%= render :partial => "form", 4 | :locals => { :product => @product, :button_label => t('views.button.create') } %> 5 | 6 | <%= link_to t('views.link.back'), products_path %> 7 | -------------------------------------------------------------------------------- /app/views/products/search.html.erb: -------------------------------------------------------------------------------- 1 |

    Listing Products

    2 | 3 |

    Displaying Products with name "<%= params[:name] %>"

    4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | <% @products.each do |product| %> 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | <% end %> 22 |
    NameDescriptionCostStock
    <%= product.name %><%= product.description %><%= number_to_currency product.cost, :unit => 'PhP' %><%= product.stock %><%= link_to 'Show', product %>
    23 | 24 |

    <%= link_to "Back to original list", products_path %>

    25 | -------------------------------------------------------------------------------- /app/views/products/show.html.erb: -------------------------------------------------------------------------------- 1 |

    <%= flash[:notice] %>

    2 | 3 |

    <%=t "views.product.header.show" %>

    4 |

    5 | <%= label(:product, :name) %>: 6 | <%= @product.name %> 7 |

    8 |

    9 | <%= label(:product, :description) %>: 10 | <%= @product.description %> 11 |

    12 |

    13 | <%= label(:product, :cost) %>: 14 | <%= number_to_currency @product.cost %> 15 |

    16 |

    17 | <%= label(:product, :stock) %>: 18 | <%= number_with_delimiter @product.stock %> 19 |

    20 |

    21 | <%= label(:product, :created_at) %>: 22 | <%=l @product.created_at %> 23 |

    24 | 25 |

    Related Purchases

    26 |
      27 | <% @product.purchases.each do |purchase| %> 28 |
    • <%= link_to purchase.description, purchase %>
    • 29 | <% end %> 30 |
    31 | 32 | <%= link_to 'Edit this record', edit_product_path(@product) %>
    33 | <%= link_to 'Delete this record', @product, 34 | { :confirm => 'Are you sure?', :method => :delete } %>
    35 | <%= link_to 'Back to List of Products', products_path %> 36 | -------------------------------------------------------------------------------- /app/views/purchases/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for(@purchase) do |f| %> 2 | <% if @purchase.errors.any? %> 3 |
    4 |

    <%= pluralize(@purchase.errors.count, "error") %> prohibited this purchase from being saved:

    5 | 6 |
      7 | <% @purchase.errors.full_messages.each do |msg| %> 8 |
    • <%= msg %>
    • 9 | <% end %> 10 |
    11 |
    12 | <% end %> 13 | 14 |
    15 | <%= f.label :description %>
    16 | <%= f.text_area :description %> 17 |
    18 |
    19 | <%= f.label :delivered_at %>
    20 | <%= f.date_select :delivered_at %> 21 |
    22 |
    23 | <%= f.label :supplier_id, "Supplier" %>
    24 | <%= f.collection_select :supplier_id, Supplier.all, :id, :name, :prompt => true %> 25 |
    26 |
    27 | <%= f.submit %> 28 |
    29 | <% end %> 30 | -------------------------------------------------------------------------------- /app/views/purchases/_invoice.html.erb: -------------------------------------------------------------------------------- 1 |

    2 | Invoice Reference Number: 3 | <%= link_to @purchase.invoice.reference_number, 4 | edit_purchase_invoice_path(@purchase) %> 5 |

    6 |

    7 | <%= link_to "Delete Invoice", purchase_invoice_path(@purchase), 8 | :confirm => "Are you sure?", :method => :delete %> 9 |

    10 | -------------------------------------------------------------------------------- /app/views/purchases/_no_invoice.html.erb: -------------------------------------------------------------------------------- 1 |

    2 | <%= link_to "Create Invoice", new_purchase_invoice_path(@purchase) %> 3 |

    4 | -------------------------------------------------------------------------------- /app/views/purchases/edit.html.erb: -------------------------------------------------------------------------------- 1 |

    Editing purchase

    2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Show', @purchase %> | 6 | <%= link_to 'Back', purchases_path %> 7 | -------------------------------------------------------------------------------- /app/views/purchases/index.html.erb: -------------------------------------------------------------------------------- 1 |

    Listing purchases

    2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <% @purchases.each do |purchase| %> 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | <% end %> 21 |
    DescriptionDelivered at
    <%= purchase.description %><%= purchase.delivered_at %><%= link_to 'Show', purchase %><%= link_to 'Edit', edit_purchase_path(purchase) %><%= link_to 'Destroy', purchase, :confirm => 'Are you sure?', :method => :delete %>
    22 | 23 |
    24 | 25 | <%= link_to 'New Purchase', new_purchase_path %> 26 | -------------------------------------------------------------------------------- /app/views/purchases/new.html.erb: -------------------------------------------------------------------------------- 1 |

    New purchase

    2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Back', purchases_path %> 6 | -------------------------------------------------------------------------------- /app/views/purchases/show.html.erb: -------------------------------------------------------------------------------- 1 |

    <%= notice %>

    2 | 3 |

    4 | Description: 5 | <%= @purchase.description %> 6 |

    7 | 8 |

    9 | Delivered at: 10 | <%= @purchase.delivered_at %> 11 |

    12 | 13 |

    14 | Supplier: 15 | <%= @purchase.display_supplier %> 16 |

    17 | 18 | <%= display_invoice @purchase %> 19 | 20 |

    Line Items

    21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | <% @purchase.line_items.each do |item| %> 29 | 30 | 31 | 32 | 33 | 34 | 38 | 39 | <% end %> 40 |
    ProductQuantityCost
    <%= item.product.name %><%= item.quantity %><%= number_to_currency item.cost, :unit => "PhP" %><%= link_to "Edit", edit_purchase_line_item_path(@purchase, item) %> 35 | <%= link_to "Destroy", purchase_line_item_path(@purchase, item), 36 | :confirm => "Are you sure?", :method => :delete %> 37 |
    41 | 42 |

    <%= link_to "New Line Item", new_purchase_line_item_path(@purchase) %>

    43 | 44 |

    Related Products

    45 |
      46 | <% @purchase.products.each do |product| %> 47 |
    • <%= link_to product.name, product %>
    • 48 | <% end %> 49 |
    50 | 51 | <%= link_to 'Edit', edit_purchase_path(@purchase) %> | 52 | <%= link_to 'Back', purchases_path %> 53 | -------------------------------------------------------------------------------- /app/views/suppliers/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for(@supplier) do |f| %> 2 | <% if @supplier.errors.any? %> 3 |
    4 |

    <%= pluralize(@supplier.errors.count, "error") %> prohibited this supplier from being saved:

    5 | 6 |
      7 | <% @supplier.errors.full_messages.each do |msg| %> 8 |
    • <%= msg %>
    • 9 | <% end %> 10 |
    11 |
    12 | <% end %> 13 | 14 |
    15 | <%= f.label :name %>
    16 | <%= f.text_field :name %> 17 |
    18 |
    19 | <%= f.label :contact_number %>
    20 | <%= f.text_field :contact_number %> 21 |
    22 |
    23 | <%= f.submit %> 24 |
    25 | <% end %> 26 | -------------------------------------------------------------------------------- /app/views/suppliers/edit.html.erb: -------------------------------------------------------------------------------- 1 |

    Editing supplier

    2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Show', @supplier %> | 6 | <%= link_to 'Back', suppliers_path %> 7 | -------------------------------------------------------------------------------- /app/views/suppliers/index.html.erb: -------------------------------------------------------------------------------- 1 |

    Listing suppliers

    2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <% @suppliers.each do |supplier| %> 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | <% end %> 21 |
    NameContact number
    <%= supplier.name %><%= supplier.contact_number %><%= link_to 'Show', supplier %><%= link_to 'Edit', edit_supplier_path(supplier) %><%= link_to 'Destroy', supplier, :confirm => 'Are you sure?', :method => :delete %>
    22 | 23 |
    24 | 25 | <%= link_to 'New Supplier', new_supplier_path %> 26 | -------------------------------------------------------------------------------- /app/views/suppliers/new.html.erb: -------------------------------------------------------------------------------- 1 |

    New supplier

    2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Back', suppliers_path %> 6 | -------------------------------------------------------------------------------- /app/views/suppliers/show.html.erb: -------------------------------------------------------------------------------- 1 |

    <%= notice %>

    2 | 3 |

    Supplier Details

    4 | 5 |

    6 | Name: 7 | <%= @supplier.name %> 8 |

    9 | 10 |

    11 | Contact number: 12 | <%= @supplier.contact_number %> 13 |

    14 | 15 |

    Related Purchases

    16 |
      17 | <% @supplier.purchases.each do |purchase| %> 18 |
    • <%= link_to purchase.description, purchase %>
    • 19 | <% end %> 20 |
    21 | 22 | <%= link_to 'Edit', edit_supplier_path(@supplier) %> | 23 | <%= link_to 'Back', suppliers_path %> 24 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run AlingnenaApp::Application 5 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require 'rails/all' 4 | 5 | # If you have a Gemfile, require the gems listed there, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(:default, Rails.env) if defined?(Bundler) 8 | 9 | module AlingnenaApp 10 | class Application < Rails::Application 11 | # Settings in config/environments/* take precedence over those specified here. 12 | # Application configuration should go into files in config/initializers 13 | # -- all .rb files in that directory are automatically loaded. 14 | 15 | # Custom directories with classes and modules you want to be autoloadable. 16 | # config.autoload_paths += %W(#{config.root}/extras) 17 | 18 | # Only load the plugins named here, in the order given (default is alphabetical). 19 | # :all can be used as a placeholder for all plugins not explicitly named. 20 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 21 | 22 | # Activate observers that should always be running. 23 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 24 | 25 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 26 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 27 | # config.time_zone = 'Central Time (US & Canada)' 28 | 29 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 30 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 31 | # config.i18n.default_locale = :de 32 | 33 | # JavaScript files you want as :defaults (application.js is always included). 34 | # config.action_view.javascript_expansions[:defaults] = %w(jquery rails) 35 | 36 | # Configure the default encoding used in templates for Ruby 1.9. 37 | config.encoding = "utf-8" 38 | 39 | # Configure sensitive parameters which will be filtered from the log file. 40 | config.filter_parameters += [:password] 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | 3 | # Set up gems listed in the Gemfile. 4 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 5 | 6 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) 7 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | development: 4 | adapter: sqlite3 5 | database: db/development.sqlite3 6 | pool: 5 7 | timeout: 5000 8 | 9 | # Warning: The database defined as "test" will be erased and 10 | # re-generated from your development database when you run "rake". 11 | # Do not set this db to the same as development or production. 12 | test: 13 | adapter: sqlite3 14 | database: db/test.sqlite3 15 | pool: 5 16 | timeout: 5000 17 | 18 | production: 19 | adapter: sqlite3 20 | database: db/production.sqlite3 21 | pool: 5 22 | timeout: 5000 23 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the rails application 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the rails application 5 | AlingnenaApp::Application.initialize! 6 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | AlingnenaApp::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the webserver when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Log error messages when you accidentally call methods on nil. 10 | config.whiny_nils = true 11 | 12 | # Show full error reports and disable caching 13 | config.consider_all_requests_local = true 14 | config.action_view.debug_rjs = true 15 | config.action_controller.perform_caching = false 16 | 17 | # Don't care if the mailer can't send 18 | config.action_mailer.raise_delivery_errors = false 19 | 20 | # Print deprecation notices to the Rails logger 21 | config.active_support.deprecation = :log 22 | 23 | # Only use best-standards-support built into browsers 24 | config.action_dispatch.best_standards_support = :builtin 25 | end 26 | 27 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | AlingnenaApp::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # The production environment is meant for finished, "live" apps. 5 | # Code is not reloaded between requests 6 | config.cache_classes = true 7 | 8 | # Full error reports are disabled and caching is turned on 9 | config.consider_all_requests_local = false 10 | config.action_controller.perform_caching = true 11 | 12 | # Specifies the header that your server uses for sending files 13 | config.action_dispatch.x_sendfile_header = "X-Sendfile" 14 | 15 | # For nginx: 16 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' 17 | 18 | # If you have no front-end server that supports something like X-Sendfile, 19 | # just comment this out and Rails will serve the files 20 | 21 | # See everything in the log (default is :info) 22 | # config.log_level = :debug 23 | 24 | # Use a different logger for distributed setups 25 | # config.logger = SyslogLogger.new 26 | 27 | # Use a different cache store in production 28 | # config.cache_store = :mem_cache_store 29 | 30 | # Disable Rails's static asset server 31 | # In production, Apache or nginx will already do this 32 | config.serve_static_assets = false 33 | 34 | # Enable serving of images, stylesheets, and javascripts from an asset server 35 | # config.action_controller.asset_host = "http://assets.example.com" 36 | 37 | # Disable delivery errors, bad email addresses will be ignored 38 | # config.action_mailer.raise_delivery_errors = false 39 | 40 | # Enable threaded mode 41 | # config.threadsafe! 42 | 43 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 44 | # the I18n.default_locale when a translation can not be found) 45 | config.i18n.fallbacks = true 46 | 47 | # Send deprecation notices to registered listeners 48 | config.active_support.deprecation = :notify 49 | end 50 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | AlingnenaApp::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Log error messages when you accidentally call methods on nil. 11 | config.whiny_nils = true 12 | 13 | # Show full error reports and disable caching 14 | config.consider_all_requests_local = true 15 | config.action_controller.perform_caching = false 16 | 17 | # Raise exceptions instead of rendering exception templates 18 | config.action_dispatch.show_exceptions = false 19 | 20 | # Disable request forgery protection in test environment 21 | config.action_controller.allow_forgery_protection = false 22 | 23 | # Tell Action Mailer not to deliver emails to the real world. 24 | # The :test delivery method accumulates sent emails in the 25 | # ActionMailer::Base.deliveries array. 26 | config.action_mailer.delivery_method = :test 27 | 28 | # Use SQL instead of Active Record's schema dumper when creating the test database. 29 | # This is necessary if your schema can't be completely dumped by the schema dumper, 30 | # like if you have constraints or database-specific column types 31 | # config.active_record.schema_format = :sql 32 | 33 | # Print deprecation notices to the stderr 34 | config.active_support.deprecation = :stderr 35 | end 36 | -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format 4 | # (all these examples are active by default): 5 | # ActiveSupport::Inflector.inflections do |inflect| 6 | # inflect.plural /^(ox)$/i, '\1en' 7 | # inflect.singular /^(ox)en/i, '\1' 8 | # inflect.irregular 'person', 'people' 9 | # inflect.uncountable %w( fish sheep ) 10 | # end 11 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | # Mime::Type.register_alias "text/html", :iphone 6 | -------------------------------------------------------------------------------- /config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | # Make sure the secret is at least 30 characters and all random, 6 | # no regular words or you'll be exposed to dictionary attacks. 7 | AlingnenaApp::Application.config.secret_token = '4c58bfd2e82613212d47fa2f6a73aeaae2fbc3ced90750c3f43be5a7461fc21b95c7267dd8736e944e39670dd9bbc4f9a67a79a995560998d60d5d42026f4a22' 8 | -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | AlingnenaApp::Application.config.session_store :cookie_store, :key => '_alingnena-app_session' 4 | 5 | # Use the database for sessions instead of the cookie-based default, 6 | # which shouldn't be used to store highly confidential information 7 | # (create the session table with "rails generate session_migration") 8 | # AlingnenaApp::Application.config.session_store :active_record_store 9 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Sample localization file for English. Add more files in this directory for other locales. 2 | # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. 3 | 4 | en: 5 | hello: "Hello world" 6 | views: 7 | button: 8 | create: "Create" 9 | link: 10 | back: "Back" 11 | product: 12 | header: 13 | new: "New Product" 14 | activerecord: 15 | errors: 16 | template: 17 | header: 18 | one: "1 error prohibited this %{model} from being saved" 19 | other: "%{count} errors prohibited this %{model} from being saved" 20 | -------------------------------------------------------------------------------- /config/locales/tl.yml: -------------------------------------------------------------------------------- 1 | tl: 2 | number: 3 | format: 4 | # Sets the separator between the units, for more precision (e.g. 1.0 / 2.0 == 0.5) 5 | separator: "." 6 | # Delimits thousands (e.g. 1,000,000 is a million) (always in groups of three) 7 | delimiter: "," 8 | # Number of decimals, behind the separator (1 with a precision of 2 gives: 1.00) 9 | precision: 3 10 | currency: 11 | format: 12 | # Where is the currency sign? %u is the currency unit, %n the number (default: $5.00) 13 | format: "%u%n" 14 | unit: "PhP" 15 | # These three are to override number.format above and are optional 16 | separator: "." 17 | delimiter: "," 18 | precision: 2 19 | date: 20 | formats: 21 | default: "%Y-%m-%d" 22 | short: "%b %d" 23 | long: "ika-%d ng %B, %Y" 24 | day_names: [Linggo, Lunes, Martes, Miyerkules, Huwebes, Biyernes, Sabado] 25 | abbr_day_names: [Lin, Lun, Mar, Mye, Huw, Bye, Sab] 26 | 27 | # Don't forget the nil at the beginning; there's no such thing as a 0th month 28 | month_names: [~, Enero, Pebrero, Marso, Abril, Mayo, Hunyo, Hulyo, Agosto, Setyembre, Oktubre, Nobyembre, Disyembre] 29 | abbr_month_names: [~, Ene, Peb, Mar, Abr, May, Hun, Hul, Ago, Set, Okt, Nob, Dis] 30 | time: 31 | formats: 32 | default: "ika-%d ng %B, %Y %I:%M:%S %p" 33 | short: "%d %b %H:%M" 34 | long: "ika-%d ng %B, %Y %I:%M %p" 35 | am: "AM" 36 | pm: "PM" 37 | 38 | views: 39 | button: 40 | create: "Likhain" 41 | link: 42 | back: "Bumalik" 43 | product: 44 | header: 45 | new: "Bagong Produkto" 46 | activerecord: 47 | models: 48 | product: "Produkto" 49 | attributes: 50 | product: 51 | name: "Pangalan" 52 | description: "Paglalarawan" 53 | cost: "Presyo" 54 | stock: "Dami" 55 | errors: 56 | format: "%{message}" 57 | template: 58 | header: 59 | one: "May isang mali na humahadlang sa pag-save ng %{model}" 60 | other: "May %{count} mali na humahadlang sa pag-save ng %{model}" 61 | messages: 62 | blank: "Dapat ipuno ang %{attribute}" 63 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | AlingnenaApp::Application.routes.draw do 2 | resources :customers 3 | 4 | resources :messages do 5 | collection do 6 | get 'message_table' 7 | end 8 | end 9 | 10 | resources :suppliers 11 | 12 | resources :purchases do 13 | resource :invoice 14 | resources :line_items 15 | end 16 | 17 | resources :debts 18 | resources :products do 19 | collection do 20 | get 'search' 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /db/migrate/20110902025349_create_debts.rb: -------------------------------------------------------------------------------- 1 | class CreateDebts < ActiveRecord::Migration 2 | def self.up 3 | create_table :debts do |t| 4 | t.string :name 5 | t.text :item 6 | t.decimal :amount 7 | 8 | t.timestamps 9 | end 10 | end 11 | 12 | def self.down 13 | drop_table :debts 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /db/migrate/20110902025801_add_remarks_to_debt.rb: -------------------------------------------------------------------------------- 1 | class AddRemarksToDebt < ActiveRecord::Migration 2 | def self.up 3 | add_column :debts, :remarks, :text 4 | end 5 | 6 | def self.down 7 | remove_column :debts, :remarks 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20110902030453_create_products.rb: -------------------------------------------------------------------------------- 1 | class CreateProducts < ActiveRecord::Migration 2 | def self.up 3 | create_table :products do |t| 4 | t.string :name 5 | t.text :description 6 | t.decimal :cost 7 | t.integer :stock 8 | 9 | t.timestamps 10 | end 11 | 12 | Product.create :name => "test product 1", :description => "test description 1", 13 | :cost => 1.11, :stock => 10 14 | Product.create :name => "test product 2", :description => "test description 2", 15 | :cost => 2.22, :stock => 20 16 | 17 | end 18 | 19 | def self.down 20 | drop_table :products 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /db/migrate/20110903171011_create_purchases.rb: -------------------------------------------------------------------------------- 1 | class CreatePurchases < ActiveRecord::Migration 2 | def self.up 3 | create_table :purchases do |t| 4 | t.text :description 5 | t.date :delivered_at 6 | 7 | t.timestamps 8 | end 9 | end 10 | 11 | def self.down 12 | drop_table :purchases 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /db/migrate/20110903171022_create_invoices.rb: -------------------------------------------------------------------------------- 1 | class CreateInvoices < ActiveRecord::Migration 2 | def self.up 3 | create_table :invoices do |t| 4 | t.references :purchase 5 | t.string :reference_number 6 | 7 | t.timestamps 8 | end 9 | end 10 | 11 | def self.down 12 | drop_table :invoices 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /db/migrate/20110904032124_create_suppliers.rb: -------------------------------------------------------------------------------- 1 | class CreateSuppliers < ActiveRecord::Migration 2 | def self.up 3 | create_table :suppliers do |t| 4 | t.string :name 5 | t.string :contact_number 6 | 7 | t.timestamps 8 | end 9 | end 10 | 11 | def self.down 12 | drop_table :suppliers 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /db/migrate/20110904032133_add_supplier_to_purchase.rb: -------------------------------------------------------------------------------- 1 | class AddSupplierToPurchase < ActiveRecord::Migration 2 | def self.up 3 | add_column :purchases, :supplier_id, :integer 4 | end 5 | 6 | def self.down 7 | remove_column :purchases, :supplier_id 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20110904034903_create_products_purchases.rb: -------------------------------------------------------------------------------- 1 | class CreateProductsPurchases < ActiveRecord::Migration 2 | def self.up 3 | create_table :products_purchases, :id => false do |t| 4 | t.integer :product_id 5 | t.integer :purchase_id 6 | end 7 | end 8 | 9 | def self.down 10 | drop_table :products_purchases 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /db/migrate/20110904035142_create_line_items.rb: -------------------------------------------------------------------------------- 1 | class CreateLineItems < ActiveRecord::Migration 2 | def self.up 3 | create_table :line_items do |t| 4 | t.references :purchase 5 | t.references :product 6 | t.integer :quantity 7 | t.decimal :cost 8 | 9 | t.timestamps 10 | end 11 | end 12 | 13 | def self.down 14 | drop_table :line_items 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /db/migrate/20110904064039_create_messages.rb: -------------------------------------------------------------------------------- 1 | class CreateMessages < ActiveRecord::Migration 2 | def self.up 3 | create_table :messages do |t| 4 | t.string :author 5 | t.string :message 6 | 7 | t.timestamps 8 | end 9 | end 10 | 11 | def self.down 12 | drop_table :messages 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /db/migrate/20110904091702_create_customers.rb: -------------------------------------------------------------------------------- 1 | class CreateCustomers < ActiveRecord::Migration 2 | def self.up 3 | create_table :customers do |t| 4 | t.string :name 5 | t.boolean :active 6 | 7 | t.timestamps 8 | end 9 | end 10 | 11 | def self.down 12 | drop_table :customers 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | # This file is auto-generated from the current state of the database. Instead 3 | # of editing this file, please use the migrations feature of Active Record to 4 | # incrementally modify your database, and then regenerate this schema definition. 5 | # 6 | # Note that this schema.rb definition is the authoritative source for your 7 | # database schema. If you need to create the application database on another 8 | # system, you should be using db:schema:load, not running all the migrations 9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 10 | # you'll amass, the slower it'll run and the greater likelihood for issues). 11 | # 12 | # It's strongly recommended to check this file into your version control system. 13 | 14 | ActiveRecord::Schema.define(:version => 20110904091702) do 15 | 16 | create_table "customers", :force => true do |t| 17 | t.string "name" 18 | t.boolean "active" 19 | t.datetime "created_at" 20 | t.datetime "updated_at" 21 | end 22 | 23 | create_table "debts", :force => true do |t| 24 | t.string "name" 25 | t.text "item" 26 | t.decimal "amount" 27 | t.datetime "created_at" 28 | t.datetime "updated_at" 29 | t.text "remarks" 30 | end 31 | 32 | create_table "invoices", :force => true do |t| 33 | t.integer "purchase_id" 34 | t.string "reference_number" 35 | t.datetime "created_at" 36 | t.datetime "updated_at" 37 | end 38 | 39 | create_table "line_items", :force => true do |t| 40 | t.integer "purchase_id" 41 | t.integer "product_id" 42 | t.integer "quantity" 43 | t.decimal "cost" 44 | t.datetime "created_at" 45 | t.datetime "updated_at" 46 | end 47 | 48 | create_table "messages", :force => true do |t| 49 | t.string "author" 50 | t.string "message" 51 | t.datetime "created_at" 52 | t.datetime "updated_at" 53 | end 54 | 55 | create_table "products", :force => true do |t| 56 | t.string "name" 57 | t.text "description" 58 | t.decimal "cost" 59 | t.integer "stock" 60 | t.datetime "created_at" 61 | t.datetime "updated_at" 62 | end 63 | 64 | create_table "products_purchases", :id => false, :force => true do |t| 65 | t.integer "product_id" 66 | t.integer "purchase_id" 67 | end 68 | 69 | create_table "purchases", :force => true do |t| 70 | t.text "description" 71 | t.date "delivered_at" 72 | t.datetime "created_at" 73 | t.datetime "updated_at" 74 | t.integer "supplier_id" 75 | end 76 | 77 | create_table "suppliers", :force => true do |t| 78 | t.string "name" 79 | t.string "contact_number" 80 | t.datetime "created_at" 81 | t.datetime "updated_at" 82 | end 83 | 84 | end 85 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) 7 | # Mayor.create(:name => 'Daley', :city => cities.first) 8 | -------------------------------------------------------------------------------- /doc/README_FOR_APP: -------------------------------------------------------------------------------- 1 | Use this README file to introduce your application and point to useful places in the API for learning more. 2 | Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries. 3 | -------------------------------------------------------------------------------- /lib/tasks/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bryanbibat/rails-3_0-tutorial-code/9e88d00b44777f914a4f3d00f1a1188897353f6f/lib/tasks/.gitkeep -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 17 | 18 | 19 | 20 | 21 |
    22 |

    The page you were looking for doesn't exist.

    23 |

    You may have mistyped the address or the page may have moved.

    24 |
    25 | 26 | 27 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 17 | 18 | 19 | 20 | 21 |
    22 |

    The change you wanted was rejected.

    23 |

    Maybe you tried to change something you didn't have access to.

    24 |
    25 | 26 | 27 | -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 17 | 18 | 19 | 20 | 21 |
    22 |

    We're sorry, but something went wrong.

    23 |

    We've been notified about this issue and we'll take a look at it shortly.

    24 |
    25 | 26 | 27 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bryanbibat/rails-3_0-tutorial-code/9e88d00b44777f914a4f3d00f1a1188897353f6f/public/favicon.ico -------------------------------------------------------------------------------- /public/images/rails.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bryanbibat/rails-3_0-tutorial-code/9e88d00b44777f914a4f3d00f1a1188897353f6f/public/images/rails.png -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Ruby on Rails: Welcome aboard 5 | 172 | 185 | 186 | 187 |
    188 | 201 | 202 |
    203 | 207 | 208 | 212 | 213 |
    214 |

    Getting started

    215 |

    Here’s how to get rolling:

    216 | 217 |
      218 |
    1. 219 |

      Use rails generate to create your models and controllers

      220 |

      To see all available options, run it without parameters.

      221 |
    2. 222 | 223 |
    3. 224 |

      Set up a default route and remove or rename this file

      225 |

      Routes are set up in config/routes.rb.

      226 |
    4. 227 | 228 |
    5. 229 |

      Create your database

      230 |

      Run rake db:migrate to create your database. If you're not using SQLite (the default), edit config/database.yml with your username and password.

      231 |
    6. 232 |
    233 |
    234 |
    235 | 236 | 237 |
    238 | 239 | 240 | -------------------------------------------------------------------------------- /public/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // Place your application-specific JavaScript functions and classes here 2 | // This file is automatically included by javascript_include_tag :defaults 3 | $(document).ready(function() { 4 | setInterval( function() { 5 | $.getScript("/messages/message_table.js"); 6 | }, 60000 ); 7 | }); 8 | -------------------------------------------------------------------------------- /public/javascripts/jquery_ujs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Unobtrusive scripting adapter for jQuery 3 | * 4 | * Requires jQuery 1.6.0 or later. 5 | * https://github.com/rails/jquery-ujs 6 | 7 | * Uploading file using rails.js 8 | * ============================= 9 | * 10 | * By default, browsers do not allow files to be uploaded via AJAX. As a result, if there are any non-blank file fields 11 | * in the remote form, this adapter aborts the AJAX submission and allows the form to submit through standard means. 12 | * 13 | * The `ajax:aborted:file` event allows you to bind your own handler to process the form submission however you wish. 14 | * 15 | * Ex: 16 | * $('form').live('ajax:aborted:file', function(event, elements){ 17 | * // Implement own remote file-transfer handler here for non-blank file inputs passed in `elements`. 18 | * // Returning false in this handler tells rails.js to disallow standard form submission 19 | * return false; 20 | * }); 21 | * 22 | * The `ajax:aborted:file` event is fired when a file-type input is detected with a non-blank value. 23 | * 24 | * Third-party tools can use this hook to detect when an AJAX file upload is attempted, and then use 25 | * techniques like the iframe method to upload the file instead. 26 | * 27 | * Required fields in rails.js 28 | * =========================== 29 | * 30 | * If any blank required inputs (required="required") are detected in the remote form, the whole form submission 31 | * is canceled. Note that this is unlike file inputs, which still allow standard (non-AJAX) form submission. 32 | * 33 | * The `ajax:aborted:required` event allows you to bind your own handler to inform the user of blank required inputs. 34 | * 35 | * !! Note that Opera does not fire the form's submit event if there are blank required inputs, so this event may never 36 | * get fired in Opera. This event is what causes other browsers to exhibit the same submit-aborting behavior. 37 | * 38 | * Ex: 39 | * $('form').live('ajax:aborted:required', function(event, elements){ 40 | * // Returning false in this handler tells rails.js to submit the form anyway. 41 | * // The blank required inputs are passed to this function in `elements`. 42 | * return ! confirm("Would you like to submit the form with missing info?"); 43 | * }); 44 | */ 45 | 46 | (function($, undefined) { 47 | // Shorthand to make it a little easier to call public rails functions from within rails.js 48 | var rails; 49 | 50 | $.rails = rails = { 51 | // Link elements bound by jquery-ujs 52 | linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote]', 53 | 54 | // Select elements bound by jquery-ujs 55 | selectChangeSelector: 'select[data-remote]', 56 | 57 | // Form elements bound by jquery-ujs 58 | formSubmitSelector: 'form', 59 | 60 | // Form input elements bound by jquery-ujs 61 | formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])', 62 | 63 | // Form input elements disabled during form submission 64 | disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]', 65 | 66 | // Form input elements re-enabled after form submission 67 | enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled', 68 | 69 | // Form required input elements 70 | requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])', 71 | 72 | // Form file input elements 73 | fileInputSelector: 'input:file', 74 | 75 | // Make sure that every Ajax request sends the CSRF token 76 | CSRFProtection: function(xhr) { 77 | var token = $('meta[name="csrf-token"]').attr('content'); 78 | if (token) xhr.setRequestHeader('X-CSRF-Token', token); 79 | }, 80 | 81 | // Triggers an event on an element and returns false if the event result is false 82 | fire: function(obj, name, data) { 83 | var event = $.Event(name); 84 | obj.trigger(event, data); 85 | return event.result !== false; 86 | }, 87 | 88 | // Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm 89 | confirm: function(message) { 90 | return confirm(message); 91 | }, 92 | 93 | // Default ajax function, may be overridden with custom function in $.rails.ajax 94 | ajax: function(options) { 95 | return $.ajax(options); 96 | }, 97 | 98 | // Submits "remote" forms and links with ajax 99 | handleRemote: function(element) { 100 | var method, url, data, 101 | crossDomain = element.data('cross-domain') || null, 102 | dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType); 103 | 104 | if (rails.fire(element, 'ajax:before')) { 105 | 106 | if (element.is('form')) { 107 | method = element.attr('method'); 108 | url = element.attr('action'); 109 | data = element.serializeArray(); 110 | // memoized value from clicked submit button 111 | var button = element.data('ujs:submit-button'); 112 | if (button) { 113 | data.push(button); 114 | element.data('ujs:submit-button', null); 115 | } 116 | } else if (element.is('select')) { 117 | method = element.data('method'); 118 | url = element.data('url'); 119 | data = element.serialize(); 120 | if (element.data('params')) data = data + "&" + element.data('params'); 121 | } else { 122 | method = element.data('method'); 123 | url = element.attr('href'); 124 | data = element.data('params') || null; 125 | } 126 | 127 | options = { 128 | type: method || 'GET', data: data, dataType: dataType, crossDomain: crossDomain, 129 | // stopping the "ajax:beforeSend" event will cancel the ajax request 130 | beforeSend: function(xhr, settings) { 131 | if (settings.dataType === undefined) { 132 | xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script); 133 | } 134 | return rails.fire(element, 'ajax:beforeSend', [xhr, settings]); 135 | }, 136 | success: function(data, status, xhr) { 137 | element.trigger('ajax:success', [data, status, xhr]); 138 | }, 139 | complete: function(xhr, status) { 140 | element.trigger('ajax:complete', [xhr, status]); 141 | }, 142 | error: function(xhr, status, error) { 143 | element.trigger('ajax:error', [xhr, status, error]); 144 | } 145 | }; 146 | // Do not pass url to `ajax` options if blank 147 | if (url) { $.extend(options, { url: url }); } 148 | 149 | rails.ajax(options); 150 | } 151 | }, 152 | 153 | // Handles "data-method" on links such as: 154 | // Delete 155 | handleMethod: function(link) { 156 | var href = link.attr('href'), 157 | method = link.data('method'), 158 | csrf_token = $('meta[name=csrf-token]').attr('content'), 159 | csrf_param = $('meta[name=csrf-param]').attr('content'), 160 | form = $('
    '), 161 | metadata_input = ''; 162 | 163 | if (csrf_param !== undefined && csrf_token !== undefined) { 164 | metadata_input += ''; 165 | } 166 | 167 | form.hide().append(metadata_input).appendTo('body'); 168 | form.submit(); 169 | }, 170 | 171 | /* Disables form elements: 172 | - Caches element value in 'ujs:enable-with' data store 173 | - Replaces element text with value of 'data-disable-with' attribute 174 | - Adds disabled=disabled attribute 175 | */ 176 | disableFormElements: function(form) { 177 | form.find(rails.disableSelector).each(function() { 178 | var element = $(this), method = element.is('button') ? 'html' : 'val'; 179 | element.data('ujs:enable-with', element[method]()); 180 | element[method](element.data('disable-with')); 181 | element.attr('disabled', 'disabled'); 182 | }); 183 | }, 184 | 185 | /* Re-enables disabled form elements: 186 | - Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`) 187 | - Removes disabled attribute 188 | */ 189 | enableFormElements: function(form) { 190 | form.find(rails.enableSelector).each(function() { 191 | var element = $(this), method = element.is('button') ? 'html' : 'val'; 192 | if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with')); 193 | element.removeAttr('disabled'); 194 | }); 195 | }, 196 | 197 | /* For 'data-confirm' attribute: 198 | - Fires `confirm` event 199 | - Shows the confirmation dialog 200 | - Fires the `confirm:complete` event 201 | 202 | Returns `true` if no function stops the chain and user chose yes; `false` otherwise. 203 | Attaching a handler to the element's `confirm` event that returns a `falsy` value cancels the confirmation dialog. 204 | Attaching a handler to the element's `confirm:complete` event that returns a `falsy` value makes this function 205 | return false. The `confirm:complete` event is fired whether or not the user answered true or false to the dialog. 206 | */ 207 | allowAction: function(element) { 208 | var message = element.data('confirm'), 209 | answer = false, callback; 210 | if (!message) { return true; } 211 | 212 | if (rails.fire(element, 'confirm')) { 213 | answer = rails.confirm(message); 214 | callback = rails.fire(element, 'confirm:complete', [answer]); 215 | } 216 | return answer && callback; 217 | }, 218 | 219 | // Helper function which checks for blank inputs in a form that match the specified CSS selector 220 | blankInputs: function(form, specifiedSelector, nonBlank) { 221 | var inputs = $(), input, 222 | selector = specifiedSelector || 'input,textarea'; 223 | form.find(selector).each(function() { 224 | input = $(this); 225 | // Collect non-blank inputs if nonBlank option is true, otherwise, collect blank inputs 226 | if (nonBlank ? input.val() : !input.val()) { 227 | inputs = inputs.add(input); 228 | } 229 | }); 230 | return inputs.length ? inputs : false; 231 | }, 232 | 233 | // Helper function which checks for non-blank inputs in a form that match the specified CSS selector 234 | nonBlankInputs: function(form, specifiedSelector) { 235 | return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank 236 | }, 237 | 238 | // Helper function, needed to provide consistent behavior in IE 239 | stopEverything: function(e) { 240 | $(e.target).trigger('ujs:everythingStopped'); 241 | e.stopImmediatePropagation(); 242 | return false; 243 | }, 244 | 245 | // find all the submit events directly bound to the form and 246 | // manually invoke them. If anyone returns false then stop the loop 247 | callFormSubmitBindings: function(form) { 248 | var events = form.data('events'), continuePropagation = true; 249 | if (events !== undefined && events['submit'] !== undefined) { 250 | $.each(events['submit'], function(i, obj){ 251 | if (typeof obj.handler === 'function') return continuePropagation = obj.handler(obj.data); 252 | }); 253 | } 254 | return continuePropagation; 255 | } 256 | }; 257 | 258 | $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }}); 259 | 260 | $(rails.linkClickSelector).live('click.rails', function(e) { 261 | var link = $(this); 262 | if (!rails.allowAction(link)) return rails.stopEverything(e); 263 | 264 | if (link.data('remote') !== undefined) { 265 | rails.handleRemote(link); 266 | return false; 267 | } else if (link.data('method')) { 268 | rails.handleMethod(link); 269 | return false; 270 | } 271 | }); 272 | 273 | $(rails.selectChangeSelector).live('change.rails', function(e) { 274 | var link = $(this); 275 | if (!rails.allowAction(link)) return rails.stopEverything(e); 276 | 277 | rails.handleRemote(link); 278 | return false; 279 | }); 280 | 281 | $(rails.formSubmitSelector).live('submit.rails', function(e) { 282 | var form = $(this), 283 | remote = form.data('remote') !== undefined, 284 | blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector), 285 | nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector); 286 | 287 | if (!rails.allowAction(form)) return rails.stopEverything(e); 288 | 289 | // skip other logic when required values are missing or file upload is present 290 | if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) { 291 | return rails.stopEverything(e); 292 | } 293 | 294 | if (remote) { 295 | if (nonBlankFileInputs) { 296 | return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]); 297 | } 298 | 299 | // If browser does not support submit bubbling, then this live-binding will be called before direct 300 | // bindings. Therefore, we should directly call any direct bindings before remotely submitting form. 301 | if (!$.support.submitBubbles && rails.callFormSubmitBindings(form) === false) return rails.stopEverything(e); 302 | 303 | rails.handleRemote(form); 304 | return false; 305 | } else { 306 | // slight timeout so that the submit button gets properly serialized 307 | setTimeout(function(){ rails.disableFormElements(form); }, 13); 308 | } 309 | }); 310 | 311 | $(rails.formInputClickSelector).live('click.rails', function(event) { 312 | var button = $(this); 313 | 314 | if (!rails.allowAction(button)) return rails.stopEverything(event); 315 | 316 | // register the pressed submit button 317 | var name = button.attr('name'), 318 | data = name ? {name:name, value:button.val()} : null; 319 | 320 | button.closest('form').data('ujs:submit-button', data); 321 | }); 322 | 323 | $(rails.formSubmitSelector).live('ajax:beforeSend.rails', function(event) { 324 | if (this == event.target) rails.disableFormElements($(this)); 325 | }); 326 | 327 | $(rails.formSubmitSelector).live('ajax:complete.rails', function(event) { 328 | if (this == event.target) rails.enableFormElements($(this)); 329 | }); 330 | 331 | })( jQuery ); 332 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-Agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /public/stylesheets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bryanbibat/rails-3_0-tutorial-code/9e88d00b44777f914a4f3d00f1a1188897353f6f/public/stylesheets/.gitkeep -------------------------------------------------------------------------------- /public/stylesheets/scaffold.css: -------------------------------------------------------------------------------- 1 | body { background-color: #fff; color: #333; } 2 | 3 | body, p, ol, ul, td { 4 | font-family: verdana, arial, helvetica, sans-serif; 5 | font-size: 13px; 6 | line-height: 18px; 7 | } 8 | 9 | pre { 10 | background-color: #eee; 11 | padding: 10px; 12 | font-size: 11px; 13 | } 14 | 15 | a { color: #000; } 16 | a:visited { color: #666; } 17 | a:hover { color: #fff; background-color:#000; } 18 | 19 | div.field, div.actions { 20 | margin-bottom: 10px; 21 | } 22 | 23 | #notice { 24 | color: green; 25 | } 26 | 27 | .field_with_errors { 28 | padding: 2px; 29 | background-color: red; 30 | display: table; 31 | } 32 | 33 | #error_explanation { 34 | width: 450px; 35 | border: 2px solid red; 36 | padding: 7px; 37 | padding-bottom: 0; 38 | margin-bottom: 20px; 39 | background-color: #f0f0f0; 40 | } 41 | 42 | #error_explanation h2 { 43 | text-align: left; 44 | font-weight: bold; 45 | padding: 5px 5px 5px 15px; 46 | font-size: 12px; 47 | margin: -7px; 48 | margin-bottom: 0px; 49 | background-color: #c00; 50 | color: #fff; 51 | } 52 | 53 | #error_explanation ul li { 54 | font-size: 12px; 55 | list-style: square; 56 | } 57 | -------------------------------------------------------------------------------- /script/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. 3 | 4 | APP_PATH = File.expand_path('../../config/application', __FILE__) 5 | require File.expand_path('../../config/boot', __FILE__) 6 | require 'rails/commands' 7 | -------------------------------------------------------------------------------- /spec/controllers/customers_controller_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | # This spec was generated by rspec-rails when you ran the scaffold generator. 4 | # It demonstrates how one might use RSpec to specify the controller code that 5 | # was generated by the Rails when you ran the scaffold generator. 6 | 7 | describe CustomersController do 8 | 9 | def mock_customer(stubs={}) 10 | @mock_customer ||= mock_model(Customer, stubs).as_null_object 11 | end 12 | 13 | describe "GET index" do 14 | it "assigns all customers as @customers" do 15 | Customer.stub(:find_all_by_active).with(true) { [mock_customer] } 16 | get :index 17 | assigns(:customers).should eq([mock_customer]) 18 | end 19 | 20 | it "should only retrieve active customers" do 21 | Customer.should_receive(:find_all_by_active).with(true) { [mock_customer] } 22 | get :index 23 | end 24 | end 25 | 26 | describe "GET show" do 27 | describe "when the record is active" do 28 | it "assigns the requested customer as @customer" do 29 | Customer.stub(:find).with("37") { mock_customer(:active? => true) } 30 | get :show, :id => "37" 31 | assigns(:customer).should be(mock_customer) 32 | end 33 | end 34 | 35 | describe "when the record is inactive" do 36 | it "redirects to the list" do 37 | Customer.stub(:find).with("37") { mock_customer(:active? => false) } 38 | get :show, :id => "37" 39 | response.should redirect_to(customers_url) 40 | end 41 | it "displays a message" do 42 | Customer.stub(:find).with("37") { mock_customer(:active? => false) } 43 | get :show, :id => "37" 44 | flash[:notice].should eq "Record does not exist" 45 | end 46 | end 47 | end 48 | 49 | describe "GET new" do 50 | it "assigns a new customer as @customer" do 51 | Customer.stub(:new) { mock_customer } 52 | get :new 53 | assigns(:customer).should be(mock_customer) 54 | end 55 | end 56 | 57 | describe "GET edit" do 58 | it "assigns the requested customer as @customer" do 59 | Customer.stub(:find).with("37") { mock_customer } 60 | get :edit, :id => "37" 61 | assigns(:customer).should be(mock_customer) 62 | end 63 | end 64 | 65 | describe "POST create" do 66 | describe "with valid params" do 67 | it "assigns a newly created customer as @customer" do 68 | Customer.stub(:new).with({'these' => 'params'}) { mock_customer(:save => true) } 69 | post :create, :customer => {'these' => 'params'} 70 | assigns(:customer).should be(mock_customer) 71 | end 72 | 73 | it "redirects to the created customer" do 74 | Customer.stub(:new) { mock_customer(:save => true) } 75 | post :create, :customer => {} 76 | response.should redirect_to(customer_url(mock_customer)) 77 | end 78 | end 79 | 80 | describe "with invalid params" do 81 | it "assigns a newly created but unsaved customer as @customer" do 82 | Customer.stub(:new).with({'these' => 'params'}) { mock_customer(:save => false) } 83 | post :create, :customer => {'these' => 'params'} 84 | assigns(:customer).should be(mock_customer) 85 | end 86 | 87 | it "re-renders the 'new' template" do 88 | Customer.stub(:new) { mock_customer(:save => false) } 89 | post :create, :customer => {} 90 | response.should render_template("new") 91 | end 92 | end 93 | end 94 | 95 | describe "PUT update" do 96 | describe "with valid params" do 97 | it "updates the requested customer" do 98 | Customer.stub(:find).with("37") { mock_customer } 99 | mock_customer.should_receive(:update_attributes).with({'these' => 'params'}) 100 | put :update, :id => "37", :customer => {'these' => 'params'} 101 | end 102 | 103 | it "assigns the requested customer as @customer" do 104 | Customer.stub(:find) { mock_customer(:update_attributes => true) } 105 | put :update, :id => "1" 106 | assigns(:customer).should be(mock_customer) 107 | end 108 | 109 | it "redirects to the customer" do 110 | Customer.stub(:find) { mock_customer(:update_attributes => true) } 111 | put :update, :id => "1" 112 | response.should redirect_to(customer_url(mock_customer)) 113 | end 114 | end 115 | 116 | describe "with invalid params" do 117 | it "assigns the customer as @customer" do 118 | Customer.stub(:find) { mock_customer(:update_attributes => false) } 119 | put :update, :id => "1" 120 | assigns(:customer).should be(mock_customer) 121 | end 122 | 123 | it "re-renders the 'edit' template" do 124 | Customer.stub(:find) { mock_customer(:update_attributes => false) } 125 | put :update, :id => "1" 126 | response.should render_template("edit") 127 | end 128 | end 129 | end 130 | 131 | describe "DELETE destroy" do 132 | it "destroys the requested customer" do 133 | Customer.stub(:find).with("37") { mock_customer } 134 | mock_customer.should_receive(:destroy) 135 | delete :destroy, :id => "37" 136 | end 137 | 138 | it "redirects to the customers list" do 139 | Customer.stub(:find) { mock_customer } 140 | delete :destroy, :id => "1" 141 | response.should redirect_to(customers_url) 142 | end 143 | end 144 | 145 | end 146 | -------------------------------------------------------------------------------- /spec/fixtures/customers.yml: -------------------------------------------------------------------------------- 1 | active: 2 | name: Active Customer 3 | active: true 4 | 5 | inactive: 6 | name: Inactive Customer 7 | active: false 8 | -------------------------------------------------------------------------------- /spec/helpers/customers_helper_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | # Specs in this file have access to a helper object that includes 4 | # the CustomersHelper. For example: 5 | # 6 | # describe CustomersHelper do 7 | # describe "string concat" do 8 | # it "concats two strings with spaces" do 9 | # helper.concat_strings("this","that").should == "this that" 10 | # end 11 | # end 12 | # end 13 | describe CustomersHelper do 14 | end 15 | -------------------------------------------------------------------------------- /spec/helpers/invoices_helper_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe InvoicesHelper do 4 | describe "display_purchase" do 5 | it "should display description of the purchase of the invoice" do 6 | mock_purchase = stub_model(Purchase, :description => "a description") 7 | mock_invoice = stub_model(Invoice, :purchase => mock_purchase) 8 | helper.display_purchase(mock_invoice).should include "a description" 9 | end 10 | 11 | it "should display a default message if there is no purchase" do 12 | mock_invoice = stub_model(Invoice, :purchase => nil) 13 | helper.display_purchase(mock_invoice).should == "(no Purchase set)" 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /spec/models/customer_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Customer do 4 | it "should create a new instance given valid attributes" do 5 | Customer.create!(:name => 'John', :active => false) # will throw error on failure 6 | end 7 | 8 | it "should set the record as active on create" do 9 | customer = Customer.create(:name => "name", :active => false) 10 | customer.reload 11 | customer.active.should eq true 12 | end 13 | 14 | describe "when destroyed" do 15 | fixtures :customers 16 | before(:each) do 17 | @customer = customers(:active) 18 | @customer.destroy 19 | end 20 | 21 | it "should not delete the record from the database" do 22 | @customer.should_not be_destroyed 23 | end 24 | 25 | it "should set the customer as inactive" do 26 | @customer.should_not be_active 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /spec/requests/customers_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe "Customers" do 4 | describe "GET /customers" do 5 | it "works! (now write some real specs)" do 6 | visit customers_path 7 | response.status.should be(200) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /spec/routing/customers_routing_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe CustomersController do 4 | describe "routing" do 5 | 6 | it "recognizes and generates #index" do 7 | { :get => "/customers" }.should route_to(:controller => "customers", :action => "index") 8 | end 9 | 10 | it "recognizes and generates #new" do 11 | { :get => "/customers/new" }.should route_to(:controller => "customers", :action => "new") 12 | end 13 | 14 | it "recognizes and generates #show" do 15 | { :get => "/customers/1" }.should route_to(:controller => "customers", :action => "show", :id => "1") 16 | end 17 | 18 | it "recognizes and generates #edit" do 19 | { :get => "/customers/1/edit" }.should route_to(:controller => "customers", :action => "edit", :id => "1") 20 | end 21 | 22 | it "recognizes and generates #create" do 23 | { :post => "/customers" }.should route_to(:controller => "customers", :action => "create") 24 | end 25 | 26 | it "recognizes and generates #update" do 27 | { :put => "/customers/1" }.should route_to(:controller => "customers", :action => "update", :id => "1") 28 | end 29 | 30 | it "recognizes and generates #destroy" do 31 | { :delete => "/customers/1" }.should route_to(:controller => "customers", :action => "destroy", :id => "1") 32 | end 33 | 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file is copied to spec/ when you run 'rails generate rspec:install' 2 | ENV["RAILS_ENV"] ||= 'test' 3 | require File.expand_path("../../config/environment", __FILE__) 4 | require 'rspec/rails' 5 | 6 | # Requires supporting ruby files with custom matchers and macros, etc, 7 | # in spec/support/ and its subdirectories. 8 | Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} 9 | 10 | RSpec.configure do |config| 11 | # == Mock Framework 12 | # 13 | # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: 14 | # 15 | # config.mock_with :mocha 16 | # config.mock_with :flexmock 17 | # config.mock_with :rr 18 | config.mock_with :rspec 19 | 20 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 21 | config.fixture_path = "#{::Rails.root}/spec/fixtures" 22 | 23 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 24 | # examples within a transaction, remove the following line or assign false 25 | # instead of true. 26 | config.use_transactional_fixtures = true 27 | end 28 | -------------------------------------------------------------------------------- /spec/views/customers/edit.html.erb_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe "customers/edit.html.erb" do 4 | before(:each) do 5 | @customer = assign(:customer, stub_model(Customer, 6 | :name => "MyString", 7 | :active => false 8 | )) 9 | end 10 | 11 | it "renders the edit customer form" do 12 | render 13 | 14 | rendered.should have_selector("form", :action => customer_path(@customer), :method => "post") do |form| 15 | form.should have_selector("input#customer_name", :name => "customer[name]") 16 | form.should have_selector("input#customer_active", :name => "customer[active]") 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/views/customers/index.html.erb_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe "customers/index.html.erb" do 4 | before(:each) do 5 | assign(:customers, [ 6 | stub_model(Customer, 7 | :name => "Name", 8 | :active => false 9 | ), 10 | stub_model(Customer, 11 | :name => "Name", 12 | :active => false 13 | ) 14 | ]) 15 | end 16 | 17 | it "renders a list of customers" do 18 | render 19 | rendered.should have_selector("tr>td", :content => "Name".to_s, :count => 2) 20 | end 21 | 22 | it "does not display the Active field" do 23 | render 24 | rendered.should_not have_selector("tr>th", :content => "Active") 25 | rendered.should_not have_selector("tr>td", :content => false.to_s, :count => 2) 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /spec/views/customers/new.html.erb_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe "customers/new.html.erb" do 4 | before(:each) do 5 | assign(:customer, stub_model(Customer, 6 | :name => "MyString", 7 | :active => false 8 | ).as_new_record) 9 | end 10 | 11 | it "renders new customer form" do 12 | render 13 | 14 | rendered.should have_selector("form", :action => customers_path, :method => "post") do |form| 15 | form.should have_selector("input#customer_name", :name => "customer[name]") 16 | form.should have_selector("input#customer_active", :name => "customer[active]") 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/views/customers/show.html.erb_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe "customers/show.html.erb" do 4 | before(:each) do 5 | @customer = assign(:customer, stub_model(Customer, 6 | :name => "Name", 7 | :active => false 8 | )) 9 | end 10 | 11 | it "renders attributes in

    " do 12 | render 13 | rendered.should contain("Name".to_s) 14 | rendered.should contain(false.to_s) 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /test/fixtures/debts.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html 2 | 3 | one: 4 | name: MyString 5 | item: MyText 6 | amount: 9.99 7 | 8 | two: 9 | name: MyString 10 | item: MyText 11 | amount: 9.99 12 | -------------------------------------------------------------------------------- /test/fixtures/invoices.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html 2 | 3 | one: 4 | purchase: 5 | reference_number: MyString 6 | 7 | two: 8 | purchase: 9 | reference_number: MyString 10 | -------------------------------------------------------------------------------- /test/fixtures/line_items.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html 2 | 3 | one: 4 | purchase: 5 | product: 6 | quantity: 1 7 | cost: 9.99 8 | 9 | two: 10 | purchase: 11 | product: 12 | quantity: 1 13 | cost: 9.99 14 | -------------------------------------------------------------------------------- /test/fixtures/messages.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html 2 | 3 | one: 4 | author: MyString 5 | message: MyString 6 | 7 | two: 8 | author: MyString 9 | message: MyString 10 | -------------------------------------------------------------------------------- /test/fixtures/products.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html 2 | 3 | one: 4 | name: MyString 5 | description: MyText 6 | cost: 9.99 7 | stock: 1 8 | 9 | two: 10 | name: MyString 11 | description: MyText 12 | cost: 9.99 13 | stock: 1 14 | -------------------------------------------------------------------------------- /test/fixtures/purchases.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html 2 | 3 | one: 4 | description: MyText 5 | delivered_at: 2011-09-04 6 | 7 | two: 8 | description: MyText 9 | delivered_at: 2011-09-04 10 | -------------------------------------------------------------------------------- /test/fixtures/suppliers.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html 2 | 3 | one: 4 | name: MyString 5 | contact_number: MyString 6 | 7 | two: 8 | name: MyString 9 | contact_number: MyString 10 | -------------------------------------------------------------------------------- /test/functional/debts_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class DebtsControllerTest < ActionController::TestCase 4 | setup do 5 | @debt = debts(:one) 6 | end 7 | 8 | test "should get index" do 9 | get :index 10 | assert_response :success 11 | assert_not_nil assigns(:debts) 12 | end 13 | 14 | test "should get new" do 15 | get :new 16 | assert_response :success 17 | end 18 | 19 | test "should create debt" do 20 | assert_difference('Debt.count') do 21 | post :create, :debt => @debt.attributes 22 | end 23 | 24 | assert_redirected_to debt_path(assigns(:debt)) 25 | end 26 | 27 | test "should show debt" do 28 | get :show, :id => @debt.to_param 29 | assert_response :success 30 | end 31 | 32 | test "should get edit" do 33 | get :edit, :id => @debt.to_param 34 | assert_response :success 35 | end 36 | 37 | test "should update debt" do 38 | put :update, :id => @debt.to_param, :debt => @debt.attributes 39 | assert_redirected_to debt_path(assigns(:debt)) 40 | end 41 | 42 | test "should destroy debt" do 43 | assert_difference('Debt.count', -1) do 44 | delete :destroy, :id => @debt.to_param 45 | end 46 | 47 | assert_redirected_to debts_path 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /test/functional/invoices_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class InvoicesControllerTest < ActionController::TestCase 4 | setup do 5 | @invoice = invoices(:one) 6 | end 7 | 8 | test "should get index" do 9 | get :index 10 | assert_response :success 11 | assert_not_nil assigns(:invoices) 12 | end 13 | 14 | test "should get new" do 15 | get :new 16 | assert_response :success 17 | end 18 | 19 | test "should create invoice" do 20 | assert_difference('Invoice.count') do 21 | post :create, :invoice => @invoice.attributes 22 | end 23 | 24 | assert_redirected_to invoice_path(assigns(:invoice)) 25 | end 26 | 27 | test "should show invoice" do 28 | get :show, :id => @invoice.to_param 29 | assert_response :success 30 | end 31 | 32 | test "should get edit" do 33 | get :edit, :id => @invoice.to_param 34 | assert_response :success 35 | end 36 | 37 | test "should update invoice" do 38 | put :update, :id => @invoice.to_param, :invoice => @invoice.attributes 39 | assert_redirected_to invoice_path(assigns(:invoice)) 40 | end 41 | 42 | test "should destroy invoice" do 43 | assert_difference('Invoice.count', -1) do 44 | delete :destroy, :id => @invoice.to_param 45 | end 46 | 47 | assert_redirected_to invoices_path 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /test/functional/line_items_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class LineItemsControllerTest < ActionController::TestCase 4 | setup do 5 | @line_item = line_items(:one) 6 | end 7 | 8 | test "should get index" do 9 | get :index 10 | assert_response :success 11 | assert_not_nil assigns(:line_items) 12 | end 13 | 14 | test "should get new" do 15 | get :new 16 | assert_response :success 17 | end 18 | 19 | test "should create line_item" do 20 | assert_difference('LineItem.count') do 21 | post :create, :line_item => @line_item.attributes 22 | end 23 | 24 | assert_redirected_to line_item_path(assigns(:line_item)) 25 | end 26 | 27 | test "should show line_item" do 28 | get :show, :id => @line_item.to_param 29 | assert_response :success 30 | end 31 | 32 | test "should get edit" do 33 | get :edit, :id => @line_item.to_param 34 | assert_response :success 35 | end 36 | 37 | test "should update line_item" do 38 | put :update, :id => @line_item.to_param, :line_item => @line_item.attributes 39 | assert_redirected_to line_item_path(assigns(:line_item)) 40 | end 41 | 42 | test "should destroy line_item" do 43 | assert_difference('LineItem.count', -1) do 44 | delete :destroy, :id => @line_item.to_param 45 | end 46 | 47 | assert_redirected_to line_items_path 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /test/functional/messages_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class MessagesControllerTest < ActionController::TestCase 4 | setup do 5 | @message = messages(:one) 6 | end 7 | 8 | test "should get index" do 9 | get :index 10 | assert_response :success 11 | assert_not_nil assigns(:messages) 12 | end 13 | 14 | test "should get new" do 15 | get :new 16 | assert_response :success 17 | end 18 | 19 | test "should create message" do 20 | assert_difference('Message.count') do 21 | post :create, :message => @message.attributes 22 | end 23 | 24 | assert_redirected_to message_path(assigns(:message)) 25 | end 26 | 27 | test "should show message" do 28 | get :show, :id => @message.to_param 29 | assert_response :success 30 | end 31 | 32 | test "should get edit" do 33 | get :edit, :id => @message.to_param 34 | assert_response :success 35 | end 36 | 37 | test "should update message" do 38 | put :update, :id => @message.to_param, :message => @message.attributes 39 | assert_redirected_to message_path(assigns(:message)) 40 | end 41 | 42 | test "should destroy message" do 43 | assert_difference('Message.count', -1) do 44 | delete :destroy, :id => @message.to_param 45 | end 46 | 47 | assert_redirected_to messages_path 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /test/functional/products_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ProductsControllerTest < ActionController::TestCase 4 | test "should get show" do 5 | get :show 6 | assert_response :success 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /test/functional/purchases_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class PurchasesControllerTest < ActionController::TestCase 4 | setup do 5 | @purchase = purchases(:one) 6 | end 7 | 8 | test "should get index" do 9 | get :index 10 | assert_response :success 11 | assert_not_nil assigns(:purchases) 12 | end 13 | 14 | test "should get new" do 15 | get :new 16 | assert_response :success 17 | end 18 | 19 | test "should create purchase" do 20 | assert_difference('Purchase.count') do 21 | post :create, :purchase => @purchase.attributes 22 | end 23 | 24 | assert_redirected_to purchase_path(assigns(:purchase)) 25 | end 26 | 27 | test "should show purchase" do 28 | get :show, :id => @purchase.to_param 29 | assert_response :success 30 | end 31 | 32 | test "should get edit" do 33 | get :edit, :id => @purchase.to_param 34 | assert_response :success 35 | end 36 | 37 | test "should update purchase" do 38 | put :update, :id => @purchase.to_param, :purchase => @purchase.attributes 39 | assert_redirected_to purchase_path(assigns(:purchase)) 40 | end 41 | 42 | test "should destroy purchase" do 43 | assert_difference('Purchase.count', -1) do 44 | delete :destroy, :id => @purchase.to_param 45 | end 46 | 47 | assert_redirected_to purchases_path 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /test/functional/suppliers_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class SuppliersControllerTest < ActionController::TestCase 4 | setup do 5 | @supplier = suppliers(:one) 6 | end 7 | 8 | test "should get index" do 9 | get :index 10 | assert_response :success 11 | assert_not_nil assigns(:suppliers) 12 | end 13 | 14 | test "should get new" do 15 | get :new 16 | assert_response :success 17 | end 18 | 19 | test "should create supplier" do 20 | assert_difference('Supplier.count') do 21 | post :create, :supplier => @supplier.attributes 22 | end 23 | 24 | assert_redirected_to supplier_path(assigns(:supplier)) 25 | end 26 | 27 | test "should show supplier" do 28 | get :show, :id => @supplier.to_param 29 | assert_response :success 30 | end 31 | 32 | test "should get edit" do 33 | get :edit, :id => @supplier.to_param 34 | assert_response :success 35 | end 36 | 37 | test "should update supplier" do 38 | put :update, :id => @supplier.to_param, :supplier => @supplier.attributes 39 | assert_redirected_to supplier_path(assigns(:supplier)) 40 | end 41 | 42 | test "should destroy supplier" do 43 | assert_difference('Supplier.count', -1) do 44 | delete :destroy, :id => @supplier.to_param 45 | end 46 | 47 | assert_redirected_to suppliers_path 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /test/performance/browsing_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | require 'rails/performance_test_help' 3 | 4 | # Profiling results for each test method are written to tmp/performance. 5 | class BrowsingTest < ActionDispatch::PerformanceTest 6 | def test_homepage 7 | get '/' 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV["RAILS_ENV"] = "test" 2 | require File.expand_path('../../config/environment', __FILE__) 3 | require 'rails/test_help' 4 | 5 | class ActiveSupport::TestCase 6 | # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. 7 | # 8 | # Note: You'll currently still have to declare fixtures explicitly in integration tests 9 | # -- they do not yet inherit this setting 10 | fixtures :all 11 | 12 | # Add more helper methods to be used by all tests here... 13 | end 14 | -------------------------------------------------------------------------------- /test/unit/debt_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class DebtTest < ActiveSupport::TestCase 4 | # Replace this with your real tests. 5 | test "the truth" do 6 | assert true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /test/unit/helpers/debts_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class DebtsHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /test/unit/helpers/invoices_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class InvoicesHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /test/unit/helpers/line_items_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class LineItemsHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /test/unit/helpers/messages_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class MessagesHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /test/unit/helpers/products_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ProductsHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /test/unit/helpers/purchases_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class PurchasesHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /test/unit/helpers/suppliers_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class SuppliersHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /test/unit/invoice_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class InvoiceTest < ActiveSupport::TestCase 4 | # Replace this with your real tests. 5 | test "the truth" do 6 | assert true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /test/unit/line_item_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class LineItemTest < ActiveSupport::TestCase 4 | # Replace this with your real tests. 5 | test "the truth" do 6 | assert true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /test/unit/message_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class MessageTest < ActiveSupport::TestCase 4 | # Replace this with your real tests. 5 | test "the truth" do 6 | assert true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /test/unit/product_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ProductTest < ActiveSupport::TestCase 4 | # Replace this with your real tests. 5 | test "the truth" do 6 | assert true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /test/unit/purchase_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class PurchaseTest < ActiveSupport::TestCase 4 | # Replace this with your real tests. 5 | test "the truth" do 6 | assert true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /test/unit/supplier_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class SupplierTest < ActiveSupport::TestCase 4 | # Replace this with your real tests. 5 | test "the truth" do 6 | assert true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /vendor/plugins/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bryanbibat/rails-3_0-tutorial-code/9e88d00b44777f914a4f3d00f1a1188897353f6f/vendor/plugins/.gitkeep --------------------------------------------------------------------------------