diff --git a/Gemfile b/Gemfile index 7abd1ea..a84778a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'http://rubygems.org' -gem 'rails', '3.1.0.rc1' +gem 'rails', '3.1.0.rc4' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' @@ -8,22 +8,24 @@ gem 'rails', '3.1.0.rc1' gem 'mysql2' # Asset template engines -gem 'json' -gem 'sass' -gem 'haml' gem 'coffee-script' gem 'uglifier' gem 'jquery-rails' -gem 'devise', '1.1.4' + +gem 'haml-rails' +gem 'sass-rails', "~> 3.1.0.rc" + +gem 'devise' gem 'cancan' gem 'will_paginate', :git => 'git://github.com/JackDanger/will_paginate.git' - gem 'paperclip' -# gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git' +# Admin +# gem 'meta_search', '>= 1.1.0.pre' +# gem 'activeadmin', :git => 'https://github.com/gregbell/active_admin.git' # Use unicorn as the web server # gem 'unicorn' @@ -32,5 +34,9 @@ gem 'paperclip' # gem 'capistrano' # To use debugger -# gem 'ruby-debug' +# gem 'ruby-debug19', :require => 'ruby-debug' +group :test do + # Pretty printed test output + gem 'turn', :require => false +end diff --git a/Gemfile.lock b/Gemfile.lock index f4b0683..f649e55 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,72 +4,111 @@ GIT specs: will_paginate (2.3.15) +GIT + remote: https://github.com/gregbell/active_admin.git + revision: 811f286fda3b6dfa91aa172b2471ee56346d539d + specs: + activeadmin (0.2.2) + devise (>= 1.1.2) + fastercsv + formtastic (>= 1.1.0) + inherited_resources + kaminari (>= 0.12.4) + meta_search (>= 0.9.2) + rails (>= 3.0.0) + sass (>= 3.1.0) + GEM remote: http://rubygems.org/ specs: - actionmailer (3.1.0.rc1) - actionpack (= 3.1.0.rc1) + actionmailer (3.1.0.rc4) + actionpack (= 3.1.0.rc4) mail (~> 2.3.0) - actionpack (3.1.0.rc1) - activemodel (= 3.1.0.rc1) - activesupport (= 3.1.0.rc1) + actionpack (3.1.0.rc4) + activemodel (= 3.1.0.rc4) + activesupport (= 3.1.0.rc4) builder (~> 3.0.0) erubis (~> 2.7.0) - i18n (~> 0.6.0beta1) - rack (~> 1.3.0.beta2) + i18n (~> 0.6) + rack (~> 1.3.0) rack-cache (~> 1.0.1) rack-mount (~> 0.8.1) rack-test (~> 0.6.0) - sprockets (~> 2.0.0.beta.5) + sprockets (~> 2.0.0.beta.10) tzinfo (~> 0.3.27) - activemodel (3.1.0.rc1) - activesupport (= 3.1.0.rc1) + activemodel (3.1.0.rc4) + activesupport (= 3.1.0.rc4) bcrypt-ruby (~> 2.1.4) builder (~> 3.0.0) - i18n (~> 0.6.0beta1) - activerecord (3.1.0.rc1) - activemodel (= 3.1.0.rc1) - activesupport (= 3.1.0.rc1) + i18n (~> 0.6) + activerecord (3.1.0.rc4) + activemodel (= 3.1.0.rc4) + activesupport (= 3.1.0.rc4) arel (~> 2.1.1) tzinfo (~> 0.3.27) - activeresource (3.1.0.rc1) - activemodel (= 3.1.0.rc1) - activesupport (= 3.1.0.rc1) - activesupport (3.1.0.rc1) + activeresource (3.1.0.rc4) + activemodel (= 3.1.0.rc4) + activesupport (= 3.1.0.rc4) + activesupport (3.1.0.rc4) multi_json (~> 1.0) - arel (2.1.1) + ansi (1.3.0) + arel (2.1.3) bcrypt-ruby (2.1.4) builder (3.0.0) cancan (1.6.5) + cocaine (0.1.0) coffee-script (2.2.0) coffee-script-source execjs coffee-script-source (1.1.1) - devise (1.1.4) + devise (1.4.2) bcrypt-ruby (~> 2.1.2) - warden (~> 1.0.2) + orm_adapter (~> 0.0.3) + warden (~> 1.0.3) erubis (2.7.0) - execjs (1.1.0) + execjs (1.2.0) multi_json (~> 1.0) - haml (3.1.1) - hike (1.0.0) + fastercsv (1.5.4) + formtastic (1.2.4) + actionpack (>= 2.3.7) + activesupport (>= 2.3.7) + i18n (~> 0.4) + haml (3.1.2) + haml-rails (0.3.4) + actionpack (~> 3.0) + activesupport (~> 3.0) + haml (~> 3.0) + railties (~> 3.0) + has_scope (0.5.0) + hike (1.2.0) i18n (0.6.0) - jquery-rails (1.0.9) + inherited_resources (1.2.2) + has_scope (~> 0.5.0) + responders (~> 0.6.0) + jquery-rails (1.0.12) railties (~> 3.0) thor (~> 0.14) - json (1.5.1) + kaminari (0.12.4) + rails (>= 3.0.0) mail (2.3.0) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) + meta_search (1.1.0.pre2) + actionpack (~> 3.1.0.alpha) + activerecord (~> 3.1.0.alpha) + activesupport (~> 3.1.0.alpha) mime-types (1.16) multi_json (1.0.3) - mysql2 (0.3.2) - paperclip (2.3.11) + mysql2 (0.3.6) + orm_adapter (0.0.5) + paperclip (2.3.15) activerecord (>= 2.3.0) activesupport (>= 2.3.2) + cocaine (>= 0.0.2) + mime-types polyglot (0.3.1) - rack (1.3.0) + rack (1.3.1) rack-cache (1.0.2) rack (>= 0.4) rack-mount (0.8.1) @@ -78,23 +117,31 @@ GEM rack rack-test (0.6.0) rack (>= 1.0) - rails (3.1.0.rc1) - actionmailer (= 3.1.0.rc1) - actionpack (= 3.1.0.rc1) - activerecord (= 3.1.0.rc1) - activeresource (= 3.1.0.rc1) - activesupport (= 3.1.0.rc1) + rails (3.1.0.rc4) + actionmailer (= 3.1.0.rc4) + actionpack (= 3.1.0.rc4) + activerecord (= 3.1.0.rc4) + activeresource (= 3.1.0.rc4) + activesupport (= 3.1.0.rc4) bundler (~> 1.0) - railties (= 3.1.0.rc1) - railties (3.1.0.rc1) - actionpack (= 3.1.0.rc1) - activesupport (= 3.1.0.rc1) + railties (= 3.1.0.rc4) + railties (3.1.0.rc4) + actionpack (= 3.1.0.rc4) + activesupport (= 3.1.0.rc4) rack-ssl (~> 1.3.2) rake (>= 0.8.7) + rdoc (~> 3.4) thor (~> 0.14.6) - rake (0.9.1) - sass (3.1.2) - sprockets (2.0.0.beta.9) + rake (0.9.2) + rdoc (3.8) + responders (0.6.4) + sass (3.1.4) + sass-rails (3.1.0.rc.4) + actionpack (~> 3.1.0.rc1) + railties (~> 3.1.0.rc1) + sass (>= 3.1.4) + sprockets (>= 2.0.0.beta.9) + sprockets (2.0.0.beta.10) hike (~> 1.0) rack (~> 1.0) tilt (!= 1.3.0, ~> 1.1) @@ -102,8 +149,10 @@ GEM tilt (1.3.2) treetop (1.4.9) polyglot (>= 0.3.1) - tzinfo (0.3.27) - uglifier (0.5.4) + turn (0.8.2) + ansi (>= 1.2.2) + tzinfo (0.3.29) + uglifier (1.0.0) execjs (>= 0.3.0) multi_json (>= 1.0.2) warden (1.0.4) @@ -113,15 +162,17 @@ PLATFORMS ruby DEPENDENCIES + activeadmin! cancan coffee-script - devise (= 1.1.4) - haml + devise + haml-rails jquery-rails - json + meta_search (>= 1.1.0.pre) mysql2 paperclip - rails (= 3.1.0.rc1) - sass + rails (= 3.1.0.rc4) + sass-rails (~> 3.1.0.rc) + turn uglifier will_paginate! diff --git a/README b/README index 5656947..7c36f23 100644 --- a/README +++ b/README @@ -1 +1,261 @@ -Base App ! \ No newline at end of file +== Welcome to Rails + +Rails is a web-application framework that includes everything needed to create +database-backed web applications according to the Model-View-Control pattern. + +This pattern splits the view (also called the presentation) into "dumb" +templates that are primarily responsible for inserting pre-built data in between +HTML tags. The model contains the "smart" domain objects (such as Account, +Product, Person, Post) that holds all the business logic and knows how to +persist themselves to a database. The controller handles the incoming requests +(such as Save New Account, Update Product, Show Post) by manipulating the model +and directing data to the view. + +In Rails, the model is handled by what's called an object-relational mapping +layer entitled Active Record. This layer allows you to present the data from +database rows as objects and embellish these data objects with business logic +methods. You can read more about Active Record in +link:files/vendor/rails/activerecord/README.html. + +The controller and view are handled by the Action Pack, which handles both +layers by its two parts: Action View and Action Controller. These two layers +are bundled in a single package due to their heavy interdependence. This is +unlike the relationship between the Active Record and Action Pack that is much +more separate. Each of these packages can be used independently outside of +Rails. You can read more about Action Pack in +link:files/vendor/rails/actionpack/README.html. + + +== Getting Started + +1. At the command prompt, create a new Rails application: + 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/ + + +== Debugging Rails + +Sometimes your application goes wrong. Fortunately there are a lot of tools that +will help you debug it and get it back on the rails. + +First area to check is the application log files. Have "tail -f" commands +running on the server.log and development.log. Rails will automatically display +debugging and runtime information to these files. Debugging info will also be +shown in the browser on requests from 127.0.0.1. + +You can also log your own messages directly into the log file from your code +using the Ruby logger class from inside your controllers. Example: + + class WeblogController < ActionController::Base + def destroy + @weblog = Weblog.find(params[:id]) + @weblog.destroy + logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!") + end + end + +The result will be a message in your log file along the lines of: + + Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1! + +More information on how to use the logger is at http://www.ruby-doc.org/core/ + +Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are +several books available online as well: + +* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe) +* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide) + +These two books will bring you up to speed on the Ruby language and also on +programming in general. + + +== Debugger + +Debugger support is available through the debugger command when you start your +Mongrel or WEBrick server with --debugger. This means that you can break out of +execution at any point in the code, investigate and change the model, and then, +resume execution! You need to install ruby-debug to run the server in debugging +mode. With gems, use sudo gem install ruby-debug. Example: + + class WeblogController < ActionController::Base + def index + @posts = Post.all + debugger + end + end + +So the controller will accept the action, run the first line, then present you +with a IRB prompt in the server window. Here you can do things like: + + >> @posts.inspect + => "[#nil, "body"=>nil, "id"=>"1"}>, + #"Rails", "body"=>"Only ten..", "id"=>"2"}>]" + >> @posts.first.title = "hello from a debugger" + => "hello from a debugger" + +...and even better, you can examine how your runtime objects actually work: + + >> f = @posts.first + => #nil, "body"=>nil, "id"=>"1"}> + >> f. + Display all 152 possibilities? (y or n) + +Finally, when you're ready to resume execution, you can enter "cont". + + +== Console + +The console is a Ruby shell, which allows you to interact with your +application's domain model. Here you'll have all parts of the application +configured, just like it is when the application is running. You can inspect +domain models, change values, and save to the database. Starting the script +without arguments will launch it in the development environment. + +To start the console, run rails console from the application +directory. + +Options: + +* Passing the -s, --sandbox argument will rollback any modifications + made to the database. +* Passing an environment name as an argument will load the corresponding + environment. Example: rails console production. + +To reload your controllers and models after launching the console run +reload! + +More information about irb can be found at: +link:http://www.rubycentral.org/pickaxe/irb.html + + +== dbconsole + +You can go to the command line of your database directly through rails +dbconsole. You would be connected to the database with the credentials +defined in database.yml. Starting the script without arguments will connect you +to the development database. Passing an argument will connect you to a different +database, like rails dbconsole production. Currently works for MySQL, +PostgreSQL and SQLite 3. + +== Description of Contents + +The default directory structure of a generated Ruby on Rails application: + + |-- app + | |-- assets + | |-- images + | |-- javascripts + | `-- stylesheets + | |-- controllers + | |-- helpers + | |-- mailers + | |-- models + | `-- views + | `-- layouts + |-- config + | |-- environments + | |-- initializers + | `-- locales + |-- db + |-- doc + |-- lib + | `-- tasks + |-- log + |-- public + |-- script + |-- test + | |-- fixtures + | |-- functional + | |-- integration + | |-- performance + | `-- unit + |-- tmp + | |-- cache + | |-- pids + | |-- sessions + | `-- sockets + `-- vendor + |-- assets + `-- stylesheets + `-- plugins + +app + Holds all the code that's specific to this particular application. + +app/assets + Contains subdirectories for images, stylesheets, and JavaScript files. + +app/controllers + Holds controllers that should be named like weblogs_controller.rb for + automated URL mapping. All controllers should descend from + ApplicationController which itself descends from ActionController::Base. + +app/models + Holds models that should be named like post.rb. Models descend from + ActiveRecord::Base by default. + +app/views + Holds the template files for the view that should be named like + weblogs/index.html.erb for the WeblogsController#index action. All views use + eRuby syntax by default. + +app/views/layouts + Holds the template files for layouts to be used with views. This models the + common header/footer method of wrapping views. In your views, define a layout + using the layout :default and create a file named default.html.erb. + Inside default.html.erb, call <% yield %> to render the view using this + layout. + +app/helpers + Holds view helpers that should be named like weblogs_helper.rb. These are + generated for you automatically when using generators for controllers. + Helpers can be used to wrap functionality for your views into methods. + +config + Configuration files for the Rails environment, the routing map, the database, + and other dependencies. + +db + Contains the database schema in schema.rb. db/migrate contains all the + sequence of Migrations for your schema. + +doc + This directory is where your application documentation will be stored when + generated using rake doc:app + +lib + Application specific libraries. Basically, any kind of custom code that + doesn't belong under controllers, models, or helpers. This directory is in + the load path. + +public + The directory available for the web server. Also contains the dispatchers and the + default HTML files. This should be set as the DOCUMENT_ROOT of your web + server. + +script + Helper scripts for automation and generation. + +test + Unit and functional tests along with fixtures. When using the rails generate + command, template test files will be generated for you and placed in this + directory. + +vendor + External libraries that the application depends on. Also includes the plugins + subdirectory. If the app has frozen rails, those gems also go here, under + vendor/rails/. This directory is in the load path. diff --git a/Rakefile b/Rakefile index 54ea5a6..bbd6d08 100644 --- a/Rakefile +++ b/Rakefile @@ -4,4 +4,4 @@ require File.expand_path('../config/application', __FILE__) -BaseApp::Application.load_tasks +Harmony::Application.load_tasks diff --git a/app/assets/images/rails.png b/app/assets/images/rails.png deleted file mode 100644 index d5edc04..0000000 Binary files a/app/assets/images/rails.png and /dev/null differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 37c7bfc..4576ec3 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -6,4 +6,4 @@ // //= require jquery //= require jquery_ujs -//= require_tree . +//= require_tree ./commons diff --git a/app/assets/javascripts/home.js.coffee b/app/assets/javascripts/commons/home.js.coffee similarity index 100% rename from app/assets/javascripts/home.js.coffee rename to app/assets/javascripts/commons/home.js.coffee diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index fc25b57..5b1a5ca 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -3,5 +3,5 @@ * 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 . + *= require_tree ./base */ \ No newline at end of file diff --git a/app/assets/stylesheets/base/home.css.sass b/app/assets/stylesheets/base/home.css.sass new file mode 100644 index 0000000..0557eba --- /dev/null +++ b/app/assets/stylesheets/base/home.css.sass @@ -0,0 +1,2 @@ + +body.home diff --git a/app/assets/stylesheets/base/layout.css.sass b/app/assets/stylesheets/base/layout.css.sass new file mode 100644 index 0000000..493c12b --- /dev/null +++ b/app/assets/stylesheets/base/layout.css.sass @@ -0,0 +1,48 @@ +* + margin: 0 + padding: 0 + +html, body + background-color: white + font: + family: Arial + size: 0.85em + margin: 0 + padding: 0 + color: #666 + +a + color: #000 + text-decoration: none + img + border: none + +.clear + clear: both + height: 0 + overflow: hidden + +div, input, span, p, ul, li, h1, h2, h3, h4, a, img, ol, label + outline: none + +// Stylesheet STRUCTURE + + + + + +// Display Flash Message + +.flash_message + margin: auto + width: 400px + padding: 20px + margin-bottom: 20px + +#flash_alert + background: #F78E87 + color: #CC0000 + +#flash_notice + background: #5D89AC + color: #004186 \ No newline at end of file diff --git a/app/assets/stylesheets/home.sass b/app/assets/stylesheets/home.sass deleted file mode 100644 index f017a85..0000000 --- a/app/assets/stylesheets/home.sass +++ /dev/null @@ -1,13 +0,0 @@ -.flash_message - margin: auto - width: 400px - padding: 20px - margin-bottom: 20px - -#flash_alert - background: #F78E87 - color: #CC0000 - -#flash_notice - background: #5D89AC - color: #004186 \ No newline at end of file diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb deleted file mode 100644 index 93e075c..0000000 --- a/app/views/home/index.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -

Check if that works

- -Page up -> App up \ No newline at end of file diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml new file mode 100644 index 0000000..1dffc66 --- /dev/null +++ b/app/views/home/index.html.haml @@ -0,0 +1,2 @@ +%h1 Home#index +%p Find me in app/views/home/index.html.haml \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb deleted file mode 100644 index 4e658a7..0000000 --- a/app/views/layouts/application.html.erb +++ /dev/null @@ -1,15 +0,0 @@ - - - - BaseApp - <%= stylesheet_link_tag "application" %> - <%= javascript_include_tag "application" %> - <%= csrf_meta_tags %> - - - -<%= display_flash %> -<%= yield %> - - - diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml new file mode 100644 index 0000000..dd54ae7 --- /dev/null +++ b/app/views/layouts/application.html.haml @@ -0,0 +1,20 @@ + +%html + %head + %title + + = stylesheet_link_tag "application" + = javascript_include_tag "application" + = csrf_meta_tags + + %body + + %header + %nav + + #content + + = display_flash + = yield + + %footer diff --git a/config.ru b/config.ru index 0a5a4d1..b7f456f 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) -run BaseApp::Application +run Harmony::Application diff --git a/config/application.rb b/config/application.rb index cf23df0..232a515 100644 --- a/config/application.rb +++ b/config/application.rb @@ -6,8 +6,12 @@ # you've limited to :test, :development, or :production. Bundler.require(:default, Rails.env) if defined?(Bundler) -module BaseApp +module Harmony class Application < Rails::Application + + # Loading SASS when "rails g controller" is using + config.sass.preferred_syntax = :sass + # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. @@ -30,13 +34,6 @@ class Application < Rails::Application # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de - # Please note that JavaScript expansions are *ignored altogether* if the asset - # pipeline is enabled (see config.assets.enabled below). Put your defaults in - # app/assets/javascripts/application.js in that case. - # - # JavaScript files you want as :defaults (application.js is always included). - # config.action_view.javascript_expansions[:defaults] = %w(prototype prototype_ujs) - # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" diff --git a/config/database.yml b/config/database.yml index b1eca23..1191bfb 100644 --- a/config/database.yml +++ b/config/database.yml @@ -12,10 +12,10 @@ development: adapter: mysql2 encoding: utf8 reconnect: false - database: base_app + database: Baseapp pool: 5 - username: base_user - password: base_pass + username: baseapp + password: baseapp socket: /tmp/mysql.sock # Warning: The database defined as "test" will be erased and @@ -25,7 +25,7 @@ test: adapter: mysql2 encoding: utf8 reconnect: false - database: BaseApp_test + database: Harmony_test pool: 5 username: root password: @@ -35,7 +35,7 @@ production: adapter: mysql2 encoding: utf8 reconnect: false - database: BaseApp_production + database: Harmony_production pool: 5 username: root password: diff --git a/config/environment.rb b/config/environment.rb index 801b60c..e774977 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -2,4 +2,4 @@ require File.expand_path('../application', __FILE__) # Initialize the rails application -BaseApp::Application.initialize! +Harmony::Application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index cad2f9b..eac33f7 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,4 +1,4 @@ -BaseApp::Application.configure do +Harmony::Application.configure do # Settings specified here will take precedence over those in config/application.rb # In the development environment your application's code is reloaded on @@ -21,6 +21,7 @@ # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin - - config.action_mailer.default_url_options = { :host => 'www.example.com' } + + # Do not compress assets + config.assets.compress = false end diff --git a/config/environments/production.rb b/config/environments/production.rb index ea8451e..f454294 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,4 +1,4 @@ -BaseApp::Application.configure do +Harmony::Application.configure do # Settings specified here will take precedence over those in config/application.rb # Code is not reloaded between requests @@ -11,15 +11,15 @@ # Disable Rails's static asset server (Apache or nginx will already do this) config.serve_static_assets = false - # Compress both stylesheets and JavaScripts + # Compress JavaScripts and CSS + config.assets.compress = true + + # Specify the default JavaScript compressor config.assets.js_compressor = :uglifier - config.assets.css_compressor = :scss # Specifies the header that your server uses for sending files # (comment out if your front-end server doesn't support this) config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx - - config.action_mailer.default_url_options = { :host => 'www.example.com' } # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true diff --git a/config/environments/test.rb b/config/environments/test.rb index 2e88a88..2ee93d8 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,4 +1,4 @@ -BaseApp::Application.configure do +Harmony::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The test environment is used exclusively to run your application's @@ -17,8 +17,6 @@ # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false - - config.action_mailer.default_url_options = { :host => 'www.example.com' } # Raise exceptions instead of rendering exception templates config.action_dispatch.show_exceptions = false diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 29be805..3d91b61 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -3,7 +3,7 @@ Devise.setup do |config| # ==> Mailer Configuration # Configure the e-mail address which will be shown in DeviseMailer. - config.mailer_sender = "please-change-me@config-initializers-devise.com" + config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com" # Configure the class responsible to send e-mails. # config.mailer = "Devise::Mailer" @@ -15,48 +15,69 @@ require 'devise/orm/active_record' # ==> Configuration for any authentication mechanism - # Configure which keys are used when authenticating an user. By default is + # Configure which keys are used when authenticating a user. The default is # just :email. You can configure it to use [:username, :subdomain], so for - # authenticating an user, both parameters are required. Remember that those + # authenticating a user, both parameters are required. Remember that those # parameters are used only when authenticating and not when retrieving from # session. If you need permissions, you should implement that in a before filter. + # You can also supply a hash where the value is a boolean determining whether + # or not authentication should be aborted when the value is not present. # config.authentication_keys = [ :email ] + # Configure parameters from the request object used for authentication. Each entry + # given should be a request method and it will automatically be passed to the + # find_for_authentication method and considered in your model lookup. For instance, + # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. + # The same considerations mentioned for authentication_keys also apply to request_keys. + # config.request_keys = [] + + # Configure which authentication keys should be case-insensitive. + # These keys will be downcased upon creating or modifying a user and when used + # to authenticate or find a user. Default is :email. + config.case_insensitive_keys = [ :email ] + + # Configure which authentication keys should have whitespace stripped. + # These keys will have whitespace before and after removed upon creating or + # modifying a user and when used to authenticate or find a user. Default is :email. + config.strip_whitespace_keys = [ :email ] + # Tell if authentication through request.params is enabled. True by default. # config.params_authenticatable = true - # Tell if authentication through HTTP Basic Auth is enabled. True by default. - # config.http_authenticatable = true + # Tell if authentication through HTTP Basic Auth is enabled. False by default. + # config.http_authenticatable = false - # Set this to true to use Basic Auth for AJAX requests. True by default. + # If http headers should be returned for AJAX requests. True by default. # config.http_authenticatable_on_xhr = true - # The realm used in Http Basic Authentication + # The realm used in Http Basic Authentication. "Application" by default. # config.http_authentication_realm = "Application" + # It will change confirmation, password recovery and other workflows + # to behave the same regardless if the e-mail provided was right or wrong. + # Does not affect registerable. + # config.paranoid = true + # ==> Configuration for :database_authenticatable # For bcrypt, this is the cost for hashing the password and defaults to 10. If # using other encryptors, it sets how many times you want the password re-encrypted. config.stretches = 10 - # Define which will be the encryption algorithm. Devise also supports encryptors - # from others authentication tools as :clearance_sha1, :authlogic_sha512 (then - # you should set stretches above to 20 for default behavior) and :restful_authentication_sha1 - # (then you should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper) - config.encryptor = :bcrypt - # Setup a pepper to generate the encrypted password. - config.pepper = "b8f956c34a7315586915497c2bbe0e41c7a63f26d18fada90ccf38007cef56f2fcaa48bac05e37ffa6aa851781afaf26bd2087252ccd460860d5bfec7ef7fecf" + # config.pepper = "291220e5fa272f28365e9038a01bdc903d78ed0e0d5a628ea75f61b12ba95fb63d250499f28ed1d971ccff3ad13e5712dd968030c9e5b05707663550437dac51" # ==> Configuration for :confirmable # The time you want to give your user to confirm his account. During this time - # he will be able to access your application without confirming. Default is nil. - # When confirm_within is zero, the user won't be able to sign in without confirming. - # You can use this to let your user access some features of your application - # without confirming the account, but blocking it after a certain period - # (ie 2 days). + # he will be able to access your application without confirming. Default is 0.days + # When confirm_within is zero, the user won't be able to sign in without confirming. + # You can use this to let your user access some features of your application + # without confirming the account, but blocking it after a certain period + # (ie 2 days). # config.confirm_within = 2.days + # Defines which key will be used when confirming an account + # config.confirmation_keys = [ :email ] + # ==> Configuration for :rememberable # The time the user will be remembered without asking for credentials again. # config.remember_for = 2.weeks @@ -67,17 +88,25 @@ # If true, extends the user's remember period when remembered via cookie. # config.extend_remember_period = false + # If true, uses the password salt as remember token. This should be turned + # to false if you are not using database authenticatable. + config.use_salt_as_remember_token = true + + # Options to be passed to the created cookie. For instance, you can set + # :secure => true in order to force SSL only cookies. + # config.cookie_options = {} + # ==> Configuration for :validatable - # Range for password length - # config.password_length = 6..20 + # Range for password length. Default is 6..128. + # config.password_length = 6..128 # Regex to use to validate the email address - # config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i + # config.email_regexp = /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i # ==> Configuration for :timeoutable # The time you want to timeout the user session without activity. After this - # time the user will be asked for credentials again. - # config.timeout_in = 10.minutes + # time the user will be asked for credentials again. Default is 30 minutes. + # config.timeout_in = 30.minutes # ==> Configuration for :lockable # Defines which strategy will be used to lock an account. @@ -85,6 +114,9 @@ # :none = No lock strategy. You should handle locking by yourself. # config.lock_strategy = :failed_attempts + # Defines which key will be used when locking and unlocking an account + # config.unlock_keys = [ :email ] + # Defines which strategy will be used to unlock an account. # :email = Sends an unlock link to the user email # :time = Re-enables login after a certain amount of time (see :unlock_in below) @@ -99,44 +131,74 @@ # Time interval to unlock the account if :time is enabled as unlock_strategy. # config.unlock_in = 1.hour + # ==> Configuration for :recoverable + # + # Defines which key will be used when recovering the password for an account + # config.reset_password_keys = [ :email ] + + # Time interval you can reset your password with a reset password key. + # Don't put a too small interval or your users won't have the time to + # change their passwords. + config.reset_password_within = 2.hours + + # ==> Configuration for :encryptable + # Allow you to use another encryption algorithm besides bcrypt (default). You can use + # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, + # :authlogic_sha512 (then you should set stretches above to 20 for default behavior) + # and :restful_authentication_sha1 (then you should set stretches to 10, and copy + # REST_AUTH_SITE_KEY to pepper) + # config.encryptor = :sha512 + # ==> Configuration for :token_authenticatable # Defines name of the authentication token params key # config.token_authentication_key = :auth_token + # If true, authentication through token does not store user in session and needs + # to be supplied on each request. Useful if you are using the token as API token. + # config.stateless_token = false + # ==> Scopes configuration # Turn scoped views on. Before rendering "sessions/new", it will first check for # "users/sessions/new". It's turned off by default because it's slower if you # are using only default views. - # config.scoped_views = true + # config.scoped_views = false # Configure the default scope given to Warden. By default it's the first - # devise role declared in your routes. + # devise role declared in your routes (usually :user). # config.default_scope = :user - # Configure sign_out behavior. - # By default sign_out is scoped (i.e. /users/sign_out affects only :user scope). - # In case of sign_out_all_scopes set to true any logout action will sign out all active scopes. - # config.sign_out_all_scopes = false + # Configure sign_out behavior. + # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope). + # The default is true, which means any logout action will sign out all active scopes. + # config.sign_out_all_scopes = true # ==> Navigation configuration # Lists the formats that should be treated as navigational. Formats like # :html, should redirect to the sign in page when the user does not have # access, but formats like :xml or :json, should return 401. + # # If you have any extra navigational formats, like :iphone or :mobile, you - # should add them to the navigational formats lists. Default is [:html] - # config.navigational_formats = [:html, :iphone] + # should add them to the navigational formats lists. + # + # The :"*/*" and "*/*" formats below is required to match Internet + # Explorer requests. + # config.navigational_formats = [:"*/*", "*/*", :html] + + # The default HTTP method used to sign out a resource. Default is :delete. + config.sign_out_via = :delete + + # ==> OmniAuth + # Add a new OmniAuth provider. Check the wiki for more information on setting + # up on your models and hooks. + # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo' # ==> Warden configuration - # If you want to use other strategies, that are not (yet) supported by Devise, - # you can configure them inside the config.warden block. The example below - # allows you to setup OAuth, using http://github.com/roman/warden_oauth + # If you want to use other strategies, that are not supported by Devise, or + # change the failure app, you can configure them inside the config.warden block. # # config.warden do |manager| - # manager.oauth(:twitter) do |twitter| - # twitter.consumer_secret = - # twitter.consumer_key = - # twitter.options :site => 'http://twitter.com' - # end - # manager.default_strategies(:scope => :user).unshift :twitter_oauth + # manager.failure_app = AnotherApp + # manager.intercept_401 = false + # manager.default_strategies(:scope => :user).unshift :some_external_strategy # end end diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index 51335dc..c2f428c 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. -BaseApp::Application.config.secret_token = '2a7b3bc3a130d8cf5cb309f8ff81239390b6a1fef2b3ad4447798f6237b56fd71590b2050c6092dbeb8c60aa2e8e5ebffb593bd085e1954ad00512a6c7c95176' +Harmony::Application.config.secret_token = 'f10eb716033683f79e7b54538b7cf80f6f6de1c8ad73d58420679cb57b3f8b7a6565144e9999fc11bec991d46441bea44d8fe8b385790de40fc60add389ff5b9' diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index b9ad61d..eb99c3f 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,8 +1,8 @@ # Be sure to restart your server when you modify this file. -BaseApp::Application.config.session_store :cookie_store, :key => '_BaseApp_session' +Harmony::Application.config.session_store :cookie_store, key: '_Harmony_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with "rails generate session_migration") -# BaseApp::Application.config.session_store :active_record_store +# Harmony::Application.config.session_store :active_record_store diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 32ffbee..16c3243 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -1,10 +1,10 @@ # Be sure to restart your server when you modify this file. # -# This file contains the settings for ActionController::ParametersWrapper -# which will be enabled by default in the upcoming version of Ruby on Rails. +# 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. -ActionController::Base.wrap_parameters :format => [:json] +ActionController::Base.wrap_parameters format: [:json] # Disable root element in JSON by default. if defined?(ActiveRecord) diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml index 5e4e433..a5cf3bf 100644 --- a/config/locales/devise.en.yml +++ b/config/locales/devise.en.yml @@ -1,12 +1,19 @@ +# Additional translations at http://github.com/plataformatec/devise/wiki/I18n + en: errors: messages: + expired: "has expired, please request a new one" not_found: "not found" - already_confirmed: "was already confirmed" + already_confirmed: "was already confirmed, please try signing in" not_locked: "was not locked" + not_saved: + one: "1 error prohibited this %{resource} from being saved:" + other: "%{count} errors prohibited this %{resource} from being saved:" devise: failure: + already_authenticated: 'You are already signed in.' unauthenticated: 'You need to sign in or sign up before continuing.' unconfirmed: 'You have to confirm your account before continuing.' locked: 'Your account is locked.' @@ -20,16 +27,23 @@ en: passwords: send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.' updated: 'Your password was changed successfully. You are now signed in.' + send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail" confirmations: send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.' + send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.' confirmed: 'Your account was successfully confirmed. You are now signed in.' registrations: - signed_up: 'You have signed up successfully. If enabled, a confirmation was sent to your e-mail.' + signed_up: 'Welcome! You have signed up successfully.' + inactive_signed_up: 'You have signed up successfully. However, we could not sign you in because your account is %{reason}.' updated: 'You updated your account successfully.' destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.' unlocks: send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.' unlocked: 'Your account was successfully unlocked. You are now signed in.' + send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.' + omniauth_callbacks: + success: 'Successfully authorized from %{kind} account.' + failure: 'Could not authorize you from %{kind} because "%{reason}".' mailer: confirmation_instructions: subject: 'Confirmation instructions' diff --git a/config/routes.rb b/config/routes.rb index 486c701..075a130 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,68 @@ -BaseApp::Application.routes.draw do +Harmony::Application.routes.draw do + + get "home/index" # Routes pour le login, création de compte etc. devise_for :users # Accueil root :to => "home#index" + + + # 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 + + # 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 + + # 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/20110603094244_create_roles.rb b/db/migrate/20110603094244_create_roles.rb deleted file mode 100644 index 78808a5..0000000 --- a/db/migrate/20110603094244_create_roles.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateRoles < ActiveRecord::Migration - def change - create_table :roles do |t| - t.string :name - t.integer :rights - - t.timestamps - end - end -end diff --git a/db/migrate/20110603094214_devise_create_users.rb b/db/migrate/20110724224302_devise_create_users.rb similarity index 100% rename from db/migrate/20110603094214_devise_create_users.rb rename to db/migrate/20110724224302_devise_create_users.rb diff --git a/db/schema.rb b/db/schema.rb index a78b7e2..8a39ea0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,23 +10,15 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110603094244) do - - create_table "roles", :force => true do |t| - t.string "name" - t.integer "rights" - t.datetime "created_at" - t.datetime "updated_at" - end +ActiveRecord::Schema.define(:version => 20110724224302) do create_table "users", :force => true do |t| - t.string "email", :default => "", :null => false - t.string "encrypted_password", :limit => 128, :default => "", :null => false - t.string "password_salt", :default => "", :null => false + t.string "email", :default => "", :null => false + t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "reset_password_token" - t.string "remember_token" + t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", :default => 0 + t.integer "sign_in_count", :default => 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" diff --git a/db/seeds.rb b/db/seeds.rb index b249ebe..4edb1e8 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,16 +1,7 @@ -# Création des rôles par défaut : -{:admin => 256, :user => 32}.each do |name, rights| - Role.create! do |r| - r.name = name.to_s - r.rights = rights.to_s - end -end - - -# Ajoute de l'utilisateur admin : -User.create! do |u| - u.email = 'admin@test.com' - u.password = 'admin123' - u.role = Role.get :admin - u.confirm! -end \ No newline at end of file +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) +# Mayor.create(name: 'Emanuel', city: cities.first) diff --git a/lib/tasks/setup.rake b/lib/tasks/setup.rake deleted file mode 100644 index e69de29..0000000 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. +
+
+
+ + +
+ + diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml deleted file mode 100644 index 820d69a..0000000 --- a/test/fixtures/roles.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html - -one: - name: MyString - rights: 1 - -two: - name: MyString - rights: 1 diff --git a/test/performance/browsing_test.rb b/test/performance/browsing_test.rb index 5d1be04..3fea27b 100644 --- a/test/performance/browsing_test.rb +++ b/test/performance/browsing_test.rb @@ -5,7 +5,7 @@ class BrowsingTest < ActionDispatch::PerformanceTest # Refer to the documentation for all available options # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory] # :output => 'tmp/performance', :formats => [:flat] } - + def test_homepage get '/' end diff --git a/test/unit/role_test.rb b/test/unit/role_test.rb deleted file mode 100644 index 11c53a8..0000000 --- a/test/unit/role_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class RoleTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end