From 1d456d0b53e7e4d1a940c1f7ee28ec656c0f83a0 Mon Sep 17 00:00:00 2001 From: Armando Fox Date: Sat, 10 Dec 2011 17:01:03 -0800 Subject: [PATCH] branch that mirrors state of app at end of basic Rails intro in tutorial chapter --- Gemfile | 45 ++-- Gemfile.lock | 121 +++------ README | 64 +---- Rakefile | 2 +- app/assets/images/rails.png | Bin 0 -> 6646 bytes app/assets/javascripts/application.js | 9 + app/assets/stylesheets/application.css | 7 + app/controllers/movies_controller.rb | 58 ++--- app/mailers/.gitkeep | 0 app/models/movie.rb | 18 -- app/views/layouts/application.html.erb | 14 + app/views/movies/_movie_form.html.haml | 11 + app/views/movies/edit.html.haml | 10 +- app/views/movies/index.html.haml | 15 +- app/views/movies/new.html.haml | 8 +- app/views/movies/show.html.haml | 24 +- config/application.rb | 28 +- config/database.yml | 8 +- config/environments/development.rb | 10 +- config/environments/production.rb | 35 ++- config/environments/test.rb | 9 +- config/initializers/secret_token.rb | 2 +- config/initializers/session_store.rb | 2 +- config/initializers/wrap_parameters.rb | 14 + config/locales/en.yml | 2 +- config/routes.rb | 57 ++++- ...ies.rb => 20111119180638_create_movies.rb} | 6 +- db/seeds.rb | 4 +- public/index.html | 241 ++++++++++++++++++ 29 files changed, 538 insertions(+), 286 deletions(-) create mode 100644 app/assets/images/rails.png create mode 100644 app/assets/javascripts/application.js create mode 100644 app/assets/stylesheets/application.css create mode 100644 app/mailers/.gitkeep create mode 100644 app/views/layouts/application.html.erb create mode 100644 app/views/movies/_movie_form.html.haml create mode 100644 config/initializers/wrap_parameters.rb rename db/migrate/{20110909213200_create_movies.rb => 20111119180638_create_movies.rb} (66%) create mode 100644 public/index.html diff --git a/Gemfile b/Gemfile index 2b6bd29..2d412a1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,27 +1,30 @@ source 'http://rubygems.org' -gem 'rails', '3.1' +gem 'rails', '3.1.0' -# To bundle edge Rails instead: -# gem 'rails', :git => 'git://github.com/rails/rails.git' +# Bundle edge Rails instead: +# gem 'rails', :git => 'git://github.com/rails/rails.git' -gem 'sqlite3', '~> 1.3.3' -gem 'haml' -gem 'ruby-tmdb' -gem 'rake', '0.8.7' - -group :test, :development do - gem 'capybara' - gem 'cucumber-rails' - gem 'cucumber' - gem 'rspec-rails' - gem 'rspec' - gem 'ruby-debug19' - gem 'rcov' +gem 'sqlite3' + + +# Gems used only for assets and not required +# in production environments by default. +group :assets do + gem 'sass-rails', " ~> 3.1.0" + gem 'coffee-rails', "~> 3.1.0" + gem 'uglifier' end -# Bundle the extra gems: -# gem 'bj' -# gem 'nokogiri' -# gem 'sqlite3-ruby', :require => 'sqlite3' -# gem 'aws-s3', :require => 'aws/s3' +gem 'jquery-rails' + +# Use unicorn as the web server +# gem 'unicorn' + +# Deploy with Capistrano +# gem 'capistrano' + +# To use debugger +gem 'ruby-debug19', :require => 'ruby-debug' +gem 'haml' +gem 'railroady' diff --git a/Gemfile.lock b/Gemfile.lock index 6bd388f..c5ee6a1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -30,45 +30,28 @@ GEM activesupport (= 3.1.0) activesupport (3.1.0) multi_json (~> 1.0) -<<<<<<< HEAD - addressable (2.2.6) -======= archive-tar-minitar (0.5.2) ->>>>>>> e60314f... Updated gems to correct versions; updated form partial (at least one of them) to use new form_for syntax, which requires <%= and not <% on form_for to generate output; fixed syntax in migration since Time.parse and Date.parse take month/day args in opposite order in ruby 1.9 arel (2.2.1) bcrypt-ruby (3.0.1) builder (3.0.0) - capybara (1.1.1) - mime-types (>= 1.16) - nokogiri (>= 1.3.3) - rack (>= 1.0.0) - rack-test (>= 0.5.4) - selenium-webdriver (~> 2.0) - xpath (~> 0.1.4) - childprocess (0.2.2) - ffi (~> 1.0.6) + coffee-rails (3.1.1) + coffee-script (>= 2.2.0) + railties (~> 3.1.0) + coffee-script (2.2.0) + coffee-script-source + execjs + coffee-script-source (1.1.3) columnize (0.3.4) - cucumber (1.1.0) - builder (>= 2.1.2) - diff-lcs (>= 1.1.2) - gherkin (~> 2.5.0) - json (>= 1.4.6) - term-ansicolor (>= 1.0.6) - cucumber-rails (1.1.1) - capybara (>= 1.1.1) - cucumber (>= 1.1.0) - nokogiri (>= 1.5.0) - deepopenstruct (0.1.2) - diff-lcs (1.1.3) erubis (2.7.0) - ffi (1.0.9) - gherkin (2.5.4) - json (>= 1.4.6) + execjs (1.2.9) + multi_json (~> 1.0) haml (3.1.3) hike (1.2.1) i18n (0.6.0) + jquery-rails (1.0.18) + railties (~> 3.0) + thor (~> 0.14) json (1.6.1) - json_pure (1.6.1) linecache19 (0.5.12) ruby_core_source (>= 0.1.4) mail (2.3.0) @@ -77,8 +60,7 @@ GEM treetop (~> 1.4.8) mime-types (1.17.2) multi_json (1.0.3) - nokogiri (1.5.0) - polyglot (0.3.2) + polyglot (0.3.3) rack (1.3.5) rack-cache (1.0.3) rack (>= 0.4) @@ -88,6 +70,7 @@ GEM rack rack-test (0.6.1) rack (>= 1.0) + railroady (1.0.2) rails (3.1.0) actionmailer (= 3.1.0) actionpack (= 3.1.0) @@ -103,40 +86,9 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.6) -<<<<<<< HEAD - rake (0.9.2) - rbx-require-relative (0.0.5) - rcov (0.9.9) - rdoc (3.9.4) -======= - rake (0.8.7) + rake (0.9.2.2) rdoc (3.11) json (~> 1.4) ->>>>>>> e60314f... Updated gems to correct versions; updated form partial (at least one of them) to use new form_for syntax, which requires <%= and not <% on form_for to generate output; fixed syntax in migration since Time.parse and Date.parse take month/day args in opposite order in ruby 1.9 - rspec (2.6.0) - rspec-core (~> 2.6.0) - rspec-expectations (~> 2.6.0) - rspec-mocks (~> 2.6.0) - rspec-core (2.6.4) - rspec-expectations (2.6.0) - diff-lcs (~> 1.1.2) - rspec-mocks (2.6.0) - rspec-rails (2.6.1) - actionpack (~> 3.0) - activesupport (~> 3.0) - railties (~> 3.0) - rspec (~> 2.6.0) -<<<<<<< HEAD - ruby-debug (0.10.4) - columnize (>= 0.1) - ruby-debug-base (~> 0.10.4.0) - ruby-debug-base (0.10.4) - linecache (>= 0.3) - ruby-tmdb (0.2.1) - addressable - deepopenstruct (>= 0.1.2) - json -======= ruby-debug-base19 (0.11.25) columnize (>= 0.3.1) linecache19 (>= 0.5.11) @@ -147,46 +99,37 @@ GEM ruby-debug-base19 (>= 0.11.19) ruby_core_source (0.1.5) archive-tar-minitar (>= 0.5.2) ->>>>>>> e60314f... Updated gems to correct versions; updated form partial (at least one of them) to use new form_for syntax, which requires <%= and not <% on form_for to generate output; fixed syntax in migration since Time.parse and Date.parse take month/day args in opposite order in ruby 1.9 - rubyzip (0.9.4) - selenium-webdriver (2.9.1) - childprocess (>= 0.2.1) - ffi (= 1.0.9) - json_pure - rubyzip + sass (3.1.10) + sass-rails (3.1.5) + actionpack (~> 3.1.0) + railties (~> 3.1.0) + sass (~> 3.1.10) + tilt (~> 1.3.2) sprockets (2.0.3) hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.4) - term-ansicolor (1.0.7) thor (0.14.6) tilt (1.3.3) treetop (1.4.10) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.30) - xpath (0.1.4) - nokogiri (~> 1.3) + tzinfo (0.3.31) + uglifier (1.1.0) + execjs (>= 0.3.0) + multi_json (>= 1.0.2) PLATFORMS ruby DEPENDENCIES - capybara - cucumber - cucumber-rails + coffee-rails (~> 3.1.0) haml - rails (= 3.1) -<<<<<<< HEAD - rcov - rspec-rails - ruby-debug - ruby-tmdb -======= - rake (= 0.8.7) - rspec - rspec-rails + jquery-rails + railroady + rails (= 3.1.0) ruby-debug19 ->>>>>>> e60314f... Updated gems to correct versions; updated form partial (at least one of them) to use new form_for syntax, which requires <%= and not <% on form_for to generate output; fixed syntax in migration since Time.parse and Date.parse take month/day args in opposite order in ruby 1.9 - sqlite3 (~> 1.3.3) + sass-rails (~> 3.1.0) + sqlite3 + uglifier diff --git a/README b/README index 408cdb9..7c36f23 100644 --- a/README +++ b/README @@ -1,15 +1,3 @@ -== RottenPotatoes for "Engineering Software for Cloud Computing" - -This repo tracks the version of the RottenPotatoes teaching app used -with the Fox & Patterson textbook "Engineering Software for Cloud -Computing". - -Different branches of the repo correspond to the code developed in -different chapters of the book. - -See the book for information on how to use this repo and what the -branches are for. - == Welcome to Rails Rails is a web-application framework that includes everything needed to create @@ -38,39 +26,6 @@ Rails. You can read more about Action Pack in link:files/vendor/rails/actionpack/README.html. -== Getting Started - -NOTE: The steps below are for creating a new app. The initial version -of RottenPotatoes was created with Rails 3.0.5 and Ruby 1.8.7 using the -commands: - -* rails new rottenpotatoes -J -T -* cd rottenpotatoes -* rails generate resource movie title:string rating:string description:text released_on:datetime -* rake db:migrate -* rails generate cucumber:install -* rails generate rspec:install -* rm public/index.html - -and then filling in the basic code for the Movie model, views and controller. - -1. At the command prompt, create a new Rails application: - rails new myapp (where myapp is the application name) - -2. Change directory to myapp and start the web server: - cd myapp; rails server (run with --help for options) - -3. Go to http://localhost:3000/ and you'll see: - "Welcome aboard: You're riding Ruby on Rails!" - -4. Follow the guidelines to start developing your application. You can find -the following resources handy: - -* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html -* Ruby on Rails Tutorial Book: http://www.railstutorial.org/ - - - == Getting Started 1. At the command prompt, create a new Rails application: @@ -136,7 +91,7 @@ mode. With gems, use sudo gem install ruby-debug. Example: class WeblogController < ActionController::Base def index - @posts = Post.find(:all) + @posts = Post.all debugger end end @@ -184,7 +139,7 @@ To reload your controllers and models after launching the console run reload! More information about irb can be found at: -link:http://www.rubycentral.com/pickaxe/irb.html +link:http://www.rubycentral.org/pickaxe/irb.html == dbconsole @@ -201,6 +156,10 @@ PostgreSQL and SQLite 3. The default directory structure of a generated Ruby on Rails application: |-- app + | |-- assets + | |-- images + | |-- javascripts + | `-- stylesheets | |-- controllers | |-- helpers | |-- mailers @@ -217,9 +176,6 @@ The default directory structure of a generated Ruby on Rails application: | `-- tasks |-- log |-- public - | |-- images - | |-- javascripts - | `-- stylesheets |-- script |-- test | |-- fixtures @@ -233,11 +189,16 @@ The default directory structure of a generated Ruby on Rails application: | |-- sessions | `-- sockets `-- vendor + |-- assets + `-- stylesheets `-- plugins app Holds all the code that's specific to this particular application. +app/assets + Contains subdirectories for images, stylesheets, and JavaScript files. + app/controllers Holds controllers that should be named like weblogs_controller.rb for automated URL mapping. All controllers should descend from @@ -282,8 +243,7 @@ lib the load path. public - The directory available for the web server. Contains subdirectories for - images, stylesheets, and javascripts. Also contains the dispatchers and the + The directory available for the web server. Also contains the dispatchers and the default HTML files. This should be set as the DOCUMENT_ROOT of your web server. diff --git a/Rakefile b/Rakefile index 21125b2..3a62945 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ +#!/usr/bin/env rake # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) -require 'rake' Rottenpotatoes::Application.load_tasks diff --git a/app/assets/images/rails.png b/app/assets/images/rails.png new file mode 100644 index 0000000000000000000000000000000000000000..d5edc04e65f555e3ba4dcdaad39dc352e75b575e GIT binary patch literal 6646 zcmVpVcQya!6@Dsmj@#jv7C*qh zIhOJ6_K0n?*d`*T7TDuW-}m`9Kz3~>+7`DUkbAraU%yi+R{N~~XA2B%zt-4=tLimUer9!2M~N{G5bftFij_O&)a zsHnOppFIzebQ`RA0$!yUM-lg#*o@_O2wf422iLnM6cU(ktYU8#;*G!QGhIy9+ZfzKjLuZo%@a z-i@9A`X%J{^;2q&ZHY3C(B%gqCPW!8{9C0PMcNZccefK){s|V5-xxtHQc@uf>XqhD z7#N^siWqetgq29aX>G^olMf=bbRF6@Y(}zYxw6o!9WBdG1unP}<(V;zKlcR2p86fq zYjaqB^;Ycq>Wy@5T1xOzG3tucG3e%nPvajaN{CrFbnzv^9&K3$NrDm*eQe4`BGQ2bI;dFEwyt>hK%X!L6)82aOZp zsrGcJ#7PoX7)s|~t6is?FfX*7vWdREi58tiY4S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q2-5q&XC>%HOLkOYxZ66(s86?=0s4z5xbiOV)}L-&6b)h6(~CIaR#JNw~46+WBiU7IhB zq!NuR4!TsYnyBg>@G=Ib*cMq^k<}AMpCeYEf&dzfiGI-wOQ7hb+nA zkN7_){y&c3xC0 AQ~&?~ literal 0 HcmV?d00001 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000..37c7bfc --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,9 @@ +// This is a manifest file that'll be compiled into including all the files listed below. +// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically +// be included in the compiled file accessible from http://example.com/assets/application.js +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// the compiled file. +// +//= require jquery +//= require jquery_ujs +//= require_tree . diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 0000000..42fe63d --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,7 @@ +/* + * This is a manifest file that'll automatically include all the stylesheets available in this directory + * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at + * the top of the compiled file, but it's generally better to create a new file per style scope. + *= require_self + *= require_tree . +*/ diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index df2daf8..4ea15bc 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -1,53 +1,33 @@ class MoviesController < ApplicationController - def index - @movies = Movie.find(:all, :order => 'release_date') - end - - def search_tmdb - @movies = Movie.find_in_tmdb(params[:search_terms]) + def show + id = params[:id] # retrieve movie ID from URI route + @movie = Movie.find(id) # look up movie by unique ID + # will render app/views/movies/show. by default end - def new - @movie = Movie.new - end - + # in movies_controller.rb def create - @movie = Movie.new(params[:movie]) - if @movie.save - flash[:notice] = "#{@movie.title} added to Rotten Potatoes!" - redirect_to movie_path(@movie) - else - render :action => "new" - end + Movie.create!(params[:movie]) + redirect_to movies_path end - - def show - @movie = Movie.find(params[:id]) + def index + @movies = Movie.all end - + def new + end + # in movies_controller.rb + def edit - @movie = Movie.find(params[:id]) + @movie = Movie.find params[:id] end - + def update - @movie = Movie.find(params[:id]) - if @movie.update_attributes(params[:movie]) - flash[:notice] = "#{@movie.title} has been updated!" - redirect_to movie_path(@movie) - else - render :action => "edit" - end + @movie = Movie.find params[:id] + @movie.update_attributes!(params[:movie]) + redirect_to movie_path(@movie) end - def destroy - @movie = Movie.find(params[:id]) - if @movie.destroy - flash[:notice] = "#{@movie.title} has been deleted!" - else - flash[:error] = "Failed to delete #{@movie.title}!" - end - redirect_to(movies_url) - end + end diff --git a/app/mailers/.gitkeep b/app/mailers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/movie.rb b/app/models/movie.rb index d41d330..49198a7 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -1,20 +1,2 @@ class Movie < ActiveRecord::Base - - class InvalidKeyError < StandardError ; end - - def self.api_key - 'cc4b67c52acb514bdf4931f7cedfd12b' - end - - def self.find_in_tmdb(string) - Tmdb.api_key = self.api_key - begin - TmdbMovie.find(:title => string) - rescue ArgumentError => tmdb_error - raise Movie::InvalidKeyError, tmdb_error.message - rescue RuntimeError => tmdb_error - raise Movie::InvalidKeyError, tmdb_error.message - end - end - end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..749e4b4 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + Rottenpotatoes + <%= stylesheet_link_tag "application" %> + <%= javascript_include_tag "application" %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/app/views/movies/_movie_form.html.haml b/app/views/movies/_movie_form.html.haml new file mode 100644 index 0000000..a68ccbc --- /dev/null +++ b/app/views/movies/_movie_form.html.haml @@ -0,0 +1,11 @@ +-# in _movie_form.html.haml (the partial) + += label :movie, :title, 'Title' += text_field :movie, 'title' + += label :movie, :rating, 'Rating' += select :movie, :rating, ['G','PG','PG-13','R','NC-17'] + += label :movie, :release_date, 'Released On' += date_select :movie, :release_date + diff --git a/app/views/movies/edit.html.haml b/app/views/movies/edit.html.haml index f028fda..26c8fde 100644 --- a/app/views/movies/edit.html.haml +++ b/app/views/movies/edit.html.haml @@ -1,7 +1,7 @@ -%h2 Editing #{@movie.title} +-# edit.html.haml using partial -= render :partial => "edit_form" +%h1 Edit Existing Movie -%ul#page_nav - %li= link_to "Cancel and back to #{@movie.name}", @movie - %li= link_to "Cancel and go Back to list of movies", movies_path += form_tag movie_path(@movie), :method => :put do + = render :partial => 'movie_form' + = submit_tag 'Update Movie Info' diff --git a/app/views/movies/index.html.haml b/app/views/movies/index.html.haml index 087057e..449cae0 100644 --- a/app/views/movies/index.html.haml +++ b/app/views/movies/index.html.haml @@ -1,6 +1,7 @@ -%h2 All Movies +-# This file is app/views/movies/index.html.haml +%h1 All Movies -%table#movies{:summary => 'List of all the movies.'} +%table#movies %thead %tr %th Movie Title @@ -8,13 +9,9 @@ %th Release Date %th More Info %tbody - - @movies.each_with_index do |movie,count| - %tr{:class => oddness(count)} + - @movies.each do |movie| + %tr %td= movie.title %td= movie.rating %td= movie.release_date - %td= link_to 'More about #{movie.title}', movie - -%ul#page_nav - %li= link_to 'Add New Movie Manually', new_movie_path - + %td= link_to "More about #{movie.title}", movie diff --git a/app/views/movies/new.html.haml b/app/views/movies/new.html.haml index 8959d73..8da1669 100644 --- a/app/views/movies/new.html.haml +++ b/app/views/movies/new.html.haml @@ -1,6 +1,6 @@ -%h2 Add New Movie +%h1 Create New Movie -= render :partial => "edit_form" += form_tag movies_path do -%ul#page_nav - %li= link_to "Cancel and go back to list of movies", movies_path + = render :partial => 'movie_form' + = submit_tag 'Save Changes' diff --git a/app/views/movies/show.html.haml b/app/views/movies/show.html.haml index 9589b37..10ef4dc 100644 --- a/app/views/movies/show.html.haml +++ b/app/views/movies/show.html.haml @@ -1,10 +1,18 @@ -%h2= @movie.title +-# in app/views/movies/show.html.haml -%p - Released on #{@movie.release_date.to_formatted_s}. Rated #{@movie.rating}. - = simple_format(@movie.description) +%h2 Details about #{@movie.title} -%ul#page_nav - %li= link_to 'Edit', edit_movie_path(@movie) - %li= link_to 'Delete', movie_path(@movie), :method => :delete, :confirm => "Really delete #{@movie.title}?" - %li= link_to 'Back to list of movies', movies_path +%ul#details + %li + Rating: + = @movie.rating + %li + Released on: + = @movie.release_date.strftime("%B %d, %Y") + +%h3 Description: + +%p#description= @movie.description + += link_to 'Edit', edit_movie_path(@movie) += link_to 'Back to movie list', movies_path diff --git a/config/application.rb b/config/application.rb index b0c7909..8e9d6e0 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,10 +1,19 @@ require File.expand_path('../boot', __FILE__) -require 'rails/all' - -# If you have a Gemfile, require the gems listed there, including any gems -# you've limited to :test, :development, or :production. -Bundler.require(:default, Rails.env) if defined?(Bundler) +# Pick the frameworks you want: +require "active_record/railtie" +require "action_controller/railtie" +require "action_mailer/railtie" +require "active_resource/railtie" +require "sprockets/railtie" +# require "rails/test_unit/railtie" + +if defined?(Bundler) + # If you precompile assets before deploying to production, use this line + Bundler.require *Rails.groups(:assets => %w(development test)) + # If you want your assets lazily compiled in production, use this line + # Bundler.require(:default, :assets, Rails.env) +end module Rottenpotatoes class Application < Rails::Application @@ -30,13 +39,16 @@ class Application < Rails::Application # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de - # JavaScript files you want as :defaults (application.js is always included). - config.action_view.javascript_expansions[:defaults] = %w() - # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] + + # Enable the asset pipeline + config.assets.enabled = true + + # Version of your assets, change this if you want to expire all your assets + config.assets.version = '1.0' end end diff --git a/config/database.yml b/config/database.yml index ad7d699..51a4dd4 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,5 +1,8 @@ # SQLite version 3.x # gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' development: adapter: sqlite3 database: db/development.sqlite3 @@ -9,7 +12,7 @@ development: # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. -test: &test +test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 @@ -20,6 +23,3 @@ production: database: db/production.sqlite3 pool: 5 timeout: 5000 - -cucumber: - <<: *test \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 129c4b6..b3ea037 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -3,7 +3,7 @@ # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development - # since you don't have to restart the webserver when you make code changes. + # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Log error messages when you accidentally call methods on nil. @@ -11,7 +11,6 @@ # Show full error reports and disable caching config.consider_all_requests_local = true - config.action_view.debug_rjs = true config.action_controller.perform_caching = false # Don't care if the mailer can't send @@ -22,5 +21,10 @@ # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin -end + # Do not compress assets + config.assets.compress = false + + # Expands the lines which load the assets + config.assets.debug = true +end diff --git a/config/environments/production.rb b/config/environments/production.rb index cff0d88..63f9e68 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,7 +1,6 @@ Rottenpotatoes::Application.configure do # Settings specified here will take precedence over those in config/application.rb - # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true @@ -9,14 +8,27 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Specifies the header that your server uses for sending files - config.action_dispatch.x_sendfile_header = "X-Sendfile" + # Disable Rails's static asset server (Apache or nginx will already do this) + config.serve_static_assets = false + + # Compress JavaScripts and CSS + config.assets.compress = true + + # Don't fallback to assets pipeline if a precompiled asset is missed + config.assets.compile = false + + # Generate digests for assets URLs + config.assets.digest = true - # For nginx: - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' + # Defaults to Rails.root.join("public/assets") + # config.assets.manifest = YOUR_PATH - # If you have no front-end server that supports something like X-Sendfile, - # just comment this out and Rails will serve the files + # Specifies the header that your server uses for sending files + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true # See everything in the log (default is :info) # config.log_level = :debug @@ -27,13 +39,12 @@ # Use a different cache store in production # config.cache_store = :mem_cache_store - # Disable Rails's static asset server - # In production, Apache or nginx will already do this - config.serve_static_assets = false - - # Enable serving of images, stylesheets, and javascripts from an asset server + # Enable serving of images, stylesheets, and JavaScripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" + # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) + # config.assets.precompile += %w( search.js ) + # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false diff --git a/config/environments/test.rb b/config/environments/test.rb index 5af6a68..61cc3b1 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -7,7 +7,11 @@ # and recreated between test runs. Don't rely on the data there! config.cache_classes = true - # Log error messages when you accidentally call methods on nil. + # Configure static asset server for tests with Cache-Control for performance + config.serve_static_assets = true + config.static_cache_control = "public, max-age=3600" + + # Log error messages when you accidentally call methods on nil config.whiny_nils = true # Show full error reports and disable caching @@ -32,4 +36,7 @@ # Print deprecation notices to the stderr config.active_support.deprecation = :stderr + + # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets + config.assets.allow_debugging = true end diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index 8f5578d..cbfb633 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -4,4 +4,4 @@ # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. -Rottenpotatoes::Application.config.secret_token = '34b98b325dd4a08e0e2ab75dcfd9ee3c8c0337daa64e2fce0e71b8545c52d7125e27c6edba1ae7b63bedca6cc1d8aea7ff73c337fa110fad98eb77dafa953159' +Rottenpotatoes::Application.config.secret_token = '683d4dea01b4bc5f21a276ea8cedf23a4f26d44d8e8680a2c16fb0c10ee60daae78896b37cce798dc793dc270bc7c1325ab83b175c6b35aea8e2cb2d19a25f8f' diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 474ba66..6a8e3fc 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,6 +1,6 @@ # Be sure to restart your server when you modify this file. -Rottenpotatoes::Application.config.session_store :cookie_store, :key => '_rottenpotatoes_session' +Rottenpotatoes::Application.config.session_store :cookie_store, key: '_rottenpotatoes_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..999df20 --- /dev/null +++ b/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end + +# Disable root element in JSON by default. +ActiveSupport.on_load(:active_record) do + self.include_root_in_json = false +end diff --git a/config/locales/en.yml b/config/locales/en.yml index a747bfa..179c14c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,5 +1,5 @@ # Sample localization file for English. Add more files in this directory for other locales. -# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. +# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. en: hello: "Hello world" diff --git a/config/routes.rb b/config/routes.rb index 51e3ec1..18a27b4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,12 +1,59 @@ Rottenpotatoes::Application.routes.draw do - # create RESTful routes for the Movie resource. + # The priority is based upon order of creation: + # first created -> highest priority. + + # Sample of regular route: + # match 'products/:id' => 'catalog#view' + # Keep in mind you can assign values other than :controller and :action + + # Sample of named route: + # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase + # This route can be invoked with purchase_url(:id => product.id) + + # Sample resource route (maps HTTP verbs to controller actions automatically): + # resources :products resources :movies - # The root of the site ('/') is an alias for 'list all movies'. - root :to => 'movies#index' + # Sample resource route with options: + # resources :products do + # member do + # get 'short' + # post 'toggle' + # end + # + # collection do + # get 'sold' + # end + # end + + # Sample resource route with sub-resources: + # resources :products do + # resources :comments, :sales + # resource :seller + # end - # Otherwise, assume the route names the controller and action - match ':controller/:action' + # Sample resource route with more complex sub-resources + # resources :products do + # resources :comments + # resources :sales do + # get 'recent', :on => :collection + # end + # end + + # Sample resource route within a namespace: + # namespace :admin do + # # Directs /admin/products/* to Admin::ProductsController + # # (app/controllers/admin/products_controller.rb) + # resources :products + # end + + # You can have the root of your site routed with "root" + # just remember to delete public/index.html. + # root :to => 'welcome#index' # See how all your routes lay out with "rake routes" + + # This is a legacy wild controller route that's not recommended for RESTful applications. + # Note: This route will make all actions in every controller accessible via GET requests. + # match ':controller(/:action(/:id(.:format)))' end diff --git a/db/migrate/20110909213200_create_movies.rb b/db/migrate/20111119180638_create_movies.rb similarity index 66% rename from db/migrate/20110909213200_create_movies.rb rename to db/migrate/20111119180638_create_movies.rb index 4cfbfa1..c20bdae 100644 --- a/db/migrate/20110909213200_create_movies.rb +++ b/db/migrate/20111119180638_create_movies.rb @@ -1,15 +1,17 @@ class CreateMovies < ActiveRecord::Migration - def self.up + def up create_table :movies do |t| t.string :title t.string :rating t.text :description t.datetime :release_date + # Add fields that let Rails automatically keep track + # of when movies are added or modified: t.timestamps end end - def self.down + def down drop_table :movies end end diff --git a/db/seeds.rb b/db/seeds.rb index 664d8c7..4edb1e8 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -3,5 +3,5 @@ # # Examples: # -# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) -# Mayor.create(:name => 'Daley', :city => cities.first) +# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) +# Mayor.create(name: 'Emanuel', city: cities.first) diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..9d9811a --- /dev/null +++ b/public/index.html @@ -0,0 +1,241 @@ + + + + Ruby on Rails: Welcome aboard + + + + +
+ + +
+ + + + +
+

Getting started

+

Here’s how to get rolling:

+ +
    +
  1. +

    Use rails generate to create your models and controllers

    +

    To see all available options, run it without parameters.

    +
  2. + +
  3. +

    Set up a default route and remove public/index.html

    +

    Routes are set up in config/routes.rb.

    +
  4. + +
  5. +

    Create your database

    +

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

    +
  6. +
+
+
+ + +
+ +