From cb02d10df2b892925bfa8b2a9b01223e44f2acb4 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 25 Jul 2011 15:10:13 -0700 Subject: sync the getting started guide with master --- railties/guides/source/getting_started.textile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 0b89021392..6c8aa668b2 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -197,9 +197,10 @@ For example, the following HTTP request: DELETE /photos/17 -refers to a photo resource with an ID of 17 and indicates an action to be taken -upon it: deletion. REST is a natural web application architecture which Rails -abstracts, shielding you from RESTful complexities and browser quirks. +would be understood to refer to a photo resource with the ID of 17, and to +indicate a desired action - deleting that resource. REST is a natural style for +the architecture of web applications, and Rails hooks into this shielding you +from many of the RESTful complexities and browser quirks. If you'd like more details on REST as an architectural style, these resources are more approachable than Fielding's thesis: -- cgit v1.2.3 From fa159d317611d1fe5b483f2542666da00bab2e6c Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 26 Jul 2011 19:35:16 +0530 Subject: move the note after the scaffold files listing --- railties/guides/source/getting_started.textile | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 6c8aa668b2..3cca383616 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -536,21 +536,8 @@ command in your terminal: $ rails generate scaffold Post name:string title:string content:text -This will create a new database table called posts (plural of Post). The table -will have three columns, name (type string), title (type string) and content -(type text). It will also hook this new database up to Rails (details below). - -NOTE. While scaffolding will get you up and running quickly, the code it -generates is unlikely to be a perfect fit for your application. You'll most -probably want to customize the generated code. Many experienced Rails developers -avoid scaffolding entirely, preferring to write all or most of their source code -from scratch. Rails, however, makes it really simple to customize templates for -generated models, controllers, views and other source files. You'll find more -information in the "Creating and Customizing Rails Generators & -Templates":generators.html guide. - -The scaffold generator will build 17 files in your application, along with some -folders, and edit one more. Here's a quick overview of what it creates: +The scaffold generator will build several files in your application, along with some +folders, and edit config/routes.rb. Here's a quick overview of what it creates: |_.File |_.Purpose| |db/migrate/20100207214725_create_posts.rb |Migration to create the posts table in your database (your name will include a different timestamp)| @@ -571,6 +558,15 @@ folders, and edit one more. Here's a quick overview of what it creates: |test/unit/helpers/posts_helper_test.rb |Unit testing harness for the posts helper| |config/routes.rb |Edited to include routing information for posts| +NOTE. While scaffolding will get you up and running quickly, the code it +generates is unlikely to be a perfect fit for your application. You'll most +probably want to customize the generated code. Many experienced Rails developers +avoid scaffolding entirely, preferring to write all or most of their source code +from scratch. Rails, however, makes it really simple to customize templates for +generated models, controllers, views and other source files. You'll find more +information in the "Creating and Customizing Rails Generators & +Templates":generators.html guide. + h4. Running a Migration One of the products of the +rails generate scaffold+ command is a _database -- cgit v1.2.3 From 5a22f05522d4b624463da174576f3663ea2872ac Mon Sep 17 00:00:00 2001 From: Alberto Perdomo Date: Thu, 28 Jul 2011 00:51:14 +0100 Subject: Association and Callbacks guide: Added section on shortcut syntax 'validates'. --- .../active_record_validations_callbacks.textile | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index ce0b5416de..e2ec874190 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -612,6 +612,61 @@ class Movie < ActiveRecord::Base end +h3. Shortcut helper + +There is a special method +validates+ that is a shortcut to all default validators and any custom validator classes ending in 'Validator'. Note that Rails default validators can be overridden inside specific classes by creating custom validator classes in their place such as +PresenceValidator+. + +h4. Multiple validations for a single attribue + +In cases where you want multiple validations for a single attribute you can do it with a one-liner. + + +class User < ActiveRecord::Base + validates :password, :presence => true, :confirmation => true, :length => { :minimum => 6 } +end + + +h4. Combining standard validations with custom validators + +You can also combine standard validations with your own custom validators. + + +class EmailValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + record.errors[attribute] << (options[:message] || "is not an email") unless + value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i + end +end + +class Person + include ActiveModel::Validations + attr_accessor :name, :email + + validates :name, :presence => true, :uniqueness => true, :length => { :maximum => 100 } + validates :email, :presence => true, :email => true +end + + +h4. Validating multiple attributes with the same criteria + +If you have a case where you want to apply the same validations to multiple attributes you can do that as well. + + +class BlogPost < ActiveRecord::Base + validates :title, :body, :presence => true +end + + +h4. Using the standard options + +The shortcut syntax is also compatible with the standard options +:allow_nil+, +:allow_blank+, etc. as well as the conditional options +:if+ and +unless+. + + +class User < ActiveRecord::Base + validates :password, :presence => { :if => :password_required? }, :confirmation => true +end + + h3. Working with Validation Errors In addition to the +valid?+ and +invalid?+ methods covered earlier, Rails provides a number of methods for working with the +errors+ collection and inquiring about the validity of objects. -- cgit v1.2.3 From b93a918337e99c3fe3ad059f093b1ee56b9e6a7d Mon Sep 17 00:00:00 2001 From: Bogdan Gusiev Date: Thu, 28 Jul 2011 11:56:08 +0300 Subject: MassAssignmentProtection: consider 'id' insensetive in StrictSanitizer In order to use StrictSanitizer in test mode Consider :id as not sensetive attribute that can be filtered from mass assignement without exception. --- .../generators/rails/app/templates/config/environments/test.rb.tt | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index ee068b0202..80198cc21e 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -34,6 +34,11 @@ # like if you have constraints or database-specific column types # config.active_record.schema_format = :sql + <%- unless options.skip_active_record? -%> + # Raise exception on mass assignment protection for ActiveRecord models + config.active_record.mass_assignment_sanitizer = :strict + <%- end -%> + # Print deprecation notices to the stderr config.active_support.deprecation = :stderr end -- cgit v1.2.3 From 5515a18aa52df3f71ed4d29fbcc0dc2819e39d5e Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Tue, 26 Jul 2011 17:25:32 -0400 Subject: Expanded meta-data in gemspec to include author, email, etc.; Defaults include "TODO" to prevent gems from being built without review. --- .../generators/rails/plugin_new/templates/%name%.gemspec | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec index eb1a1e5054..b469edd772 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec @@ -1,12 +1,16 @@ # Provide a simple gemspec so you can easily use your # project in your rails apps through git. Gem::Specification.new do |s| - s.name = "<%= name %>" - s.summary = "Insert <%= camelized %> summary." - s.description = "Insert <%= camelized %> description." + s.name = "<%= name %>" + s.version = "0.0.1" + s.authors = ["TODO: Your name"] + s.email = ["TODO: Your email"] + s.homepage = "TODO" + s.summary = "TODO: Summary of <%= camelized %>." + s.description = "TODO: Description of <%= camelized %>." + s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"] <% unless options.skip_test_unit? -%> s.test_files = Dir["test/**/*"] <% end -%> - s.version = "0.0.1" end -- cgit v1.2.3 From d9b59c341c5cc5848a42e936588a67130bf7ff4a Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Tue, 26 Jul 2011 18:51:44 -0400 Subject: Extracted version from gemspec and placed it in its own file. This is consistent with the approach taken by "bundle gem", and is expected by gems such as svenfuchs/gem-release which can be used to bump / tag versions of gems. --- .../rails/generators/rails/plugin_new/plugin_new_generator.rb | 1 + .../rails/generators/rails/plugin_new/templates/%name%.gemspec | 10 +++++++--- .../rails/plugin_new/templates/lib/%name%/version.rb | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 7c0a2b9cf4..56b1587760 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -46,6 +46,7 @@ module Rails def lib template "lib/%name%.rb" template "lib/tasks/%name%_tasks.rake" + template "lib/%name%/version.rb" if full? template "lib/%name%/engine.rb" end diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec index b469edd772..736d114901 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec @@ -1,8 +1,12 @@ -# Provide a simple gemspec so you can easily use your -# project in your rails apps through git. +$:.push File.expand_path("../lib", __FILE__) + +# Maintain your gem's version: +require "<%= name %>/version" + +# Describe your gem and declare its dependencies: Gem::Specification.new do |s| s.name = "<%= name %>" - s.version = "0.0.1" + s.version = <%= camelized %>::VERSION s.authors = ["TODO: Your name"] s.email = ["TODO: Your email"] s.homepage = "TODO" diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb b/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb new file mode 100644 index 0000000000..ef07ef2e19 --- /dev/null +++ b/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb @@ -0,0 +1,3 @@ +module <%= camelized %> + VERSION = "0.0.1" +end -- cgit v1.2.3 From a74e4736f95befa7a22c208019bf11a155ff7543 Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Tue, 26 Jul 2011 21:54:45 -0400 Subject: Moved dependencies from Gemfile to gemspec to eliminate redundant declarations. --- .../rails/plugin_new/templates/%name%.gemspec | 11 +++++++++++ .../generators/rails/plugin_new/templates/Gemfile | 20 +++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec index 736d114901..b8d68ad0bc 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec @@ -17,4 +17,15 @@ Gem::Specification.new do |s| <% unless options.skip_test_unit? -%> s.test_files = Dir["test/**/*"] <% end -%> + + # If your gem is dependent on a specific version (or higher) of Rails: + <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", ">= <%= Rails::VERSION::STRING %>" + +<% unless options[:skip_javascript] || !full? -%> + # If your gem contains any <%= "#{options[:javascript]}-specific" %> javascript: + # s.add_dependency "<%= "#{options[:javascript]}-rails" %>" + +<% end -%> + # Declare development-specific dependencies: + s.add_development_dependency "<%= gem_for_database %>" end diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile index 7e6eb18341..160baa6906 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile +++ b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile @@ -1,14 +1,20 @@ source "http://rubygems.org" -<%= rails_gemfile_entry -%> +# Declare your gem's dependencies in <%= name %>.gemspec. +# Bundler will treat runtime dependencies like base dependencies, and +# development dependencies will be added by default to the :development group. +gemspec -<% if full? -%> -<%= database_gemfile_entry -%> -<% end -%> +# Declare any dependencies that are still in development here instead of in +# your gemspec. These might include edge Rails or gems from your path or +# Git. Remember to move these dependencies to your gemspec before releasing +# your gem to rubygems.org. -<% if mountable? -%> -<%= javascript_gemfile_entry -%> -<% end -%> +<% if options.dev? || options.edge? -%> +# Your gem is dependent on dev or edge Rails. Once you can lock this +# dependency down to a specific version, move it to your gemspec. +<%= rails_gemfile_entry -%> +<% end -%> # To use debugger # <%= ruby_debugger_gemfile_entry %> \ No newline at end of file -- cgit v1.2.3 From d10f268d2057a4e9d46bd003afeceb4e910d1153 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 28 Jul 2011 11:48:21 -0300 Subject: Tidy up a bit plugin new gemspec --- .../rails/generators/rails/plugin_new/templates/%name%.gemspec | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec index b8d68ad0bc..8588e88077 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec @@ -18,14 +18,10 @@ Gem::Specification.new do |s| s.test_files = Dir["test/**/*"] <% end -%> - # If your gem is dependent on a specific version (or higher) of Rails: - <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", ">= <%= Rails::VERSION::STRING %>" - -<% unless options[:skip_javascript] || !full? -%> - # If your gem contains any <%= "#{options[:javascript]}-specific" %> javascript: + <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", "~> <%= Rails::VERSION::STRING %>" +<% if full? && !options[:skip_javascript] -%> # s.add_dependency "<%= "#{options[:javascript]}-rails" %>" - <% end -%> - # Declare development-specific dependencies: + s.add_development_dependency "<%= gem_for_database %>" end -- cgit v1.2.3 From 5a4e8f5514a65c583f54d52e476d1bebcd5785e3 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Thu, 28 Jul 2011 21:14:29 +0530 Subject: pluging generator test fix --- railties/test/generators/plugin_new_generator_test.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'railties') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 0ccb2ae9da..e6ea1cbc33 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -69,13 +69,13 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_database_entry_is_generated_for_sqlite3_by_default_in_full_mode run_generator([destination_root, "--full"]) assert_file "test/dummy/config/database.yml", /sqlite/ - assert_file "Gemfile", /^gem\s+["']sqlite3["']$/ + assert_file "bukkits.gemspec", /sqlite3/ end def test_config_another_database run_generator([destination_root, "-d", "mysql", "--full"]) assert_file "test/dummy/config/database.yml", /mysql/ - assert_file "Gemfile", /^gem\s+["']mysql2["']$/ + assert_file "bukkits.gemspec", /mysql/ end def test_active_record_is_removed_from_frameworks_if_skip_active_record_is_given @@ -117,8 +117,8 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_match %r{^//= require jquery}, contents assert_match %r{^//= require jquery_ujs}, contents end - assert_file 'Gemfile' do |contents| - assert_match(/^gem 'jquery-rails'/, contents) + assert_file 'bukkits.gemspec' do |contents| + assert_match(/jquery-rails/, contents) end end @@ -128,8 +128,8 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_match %r{^//= require prototype}, contents assert_match %r{^//= require prototype_ujs}, contents end - assert_file 'Gemfile' do |contents| - assert_match(/^gem 'prototype-rails'/, contents) + assert_file 'bukkits.gemspec' do |contents| + assert_match(/prototype-rails/, contents) end end @@ -205,10 +205,10 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_creating_gemspec run_generator - assert_file "bukkits.gemspec", /s.name = "bukkits"/ + assert_file "bukkits.gemspec", /s.name\s+= "bukkits"/ assert_file "bukkits.gemspec", /s.files = Dir\["\{app,config,db,lib\}\/\*\*\/\*"\]/ assert_file "bukkits.gemspec", /s.test_files = Dir\["test\/\*\*\/\*"\]/ - assert_file "bukkits.gemspec", /s.version = "0.0.1"/ + assert_file "bukkits.gemspec", /s.version\s+ = Bukkits::VERSION/ end def test_usage_of_engine_commands -- cgit v1.2.3 From 54463592cbfd78e1eb03bc1ac90e044dd30900a0 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 28 Jul 2011 16:46:39 -0300 Subject: Tidy up --- railties/lib/rails/generators/app_base.rb | 6 ++++-- railties/lib/rails/generators/rails/app/templates/Gemfile | 3 --- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index bbdd000ad9..21a2ae4e28 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -200,9 +200,11 @@ module Rails def assets_gemfile_entry <<-GEMFILE.strip_heredoc + # Gems used only for assets and not required + # in production environments by default. group :assets do - gem 'sass-rails', :git => 'git://github.com/rails/sass-rails' - gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails' + gem 'sass-rails', :git => 'git://github.com/rails/sass-rails.git' + gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails.git' gem 'uglifier' end GEMFILE diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 88eea40b1b..c83e7ddf80 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -7,10 +7,7 @@ source 'http://rubygems.org' <%= "gem 'jruby-openssl'\n" if defined?(JRUBY_VERSION) -%> <%= "gem 'json'\n" if RUBY_VERSION < "1.9.2" -%> -# Gems used only for assets and not required -# in production environments by default. <%= assets_gemfile_entry %> - <%= javascript_gemfile_entry %> # Use unicorn as the web server -- cgit v1.2.3 From d8e62a93e388c674aa95b32b8688ba6e8366a643 Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Tue, 26 Jul 2011 15:41:08 -0400 Subject: Include empty app/mailers directory in mountable and full plugins --- railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb | 1 + .../generators/rails/plugin_new/templates/app/mailers/.empty_directory | 0 2 files changed, 1 insertion(+) create mode 100644 railties/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 56b1587760..c46422437d 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -19,6 +19,7 @@ module Rails empty_directory_with_gitkeep "app/controllers" empty_directory_with_gitkeep "app/views" empty_directory_with_gitkeep "app/helpers" + empty_directory_with_gitkeep "app/mailers" empty_directory_with_gitkeep "app/assets/images/#{name}" end end diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory b/railties/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory new file mode 100644 index 0000000000..e69de29bb2 -- cgit v1.2.3 From 4fe2c99052928a8669d7bbc70bfdfe059eba67bc Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Fri, 29 Jul 2011 22:06:36 +0530 Subject: Test add for plugin new generator generate mailer --- railties/test/generators/plugin_new_generator_test.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index e6ea1cbc33..19e80eee89 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -25,10 +25,6 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase # brings setup, teardown, and some tests include SharedGeneratorTests - def default_files - ::DEFAULT_PLUGIN_FILES - end - def test_invalid_plugin_name_raises_an_error content = capture(:stderr){ run_generator [File.join(destination_root, "43-things")] } assert_equal "Invalid plugin name 43-things. Please give a name which does not start with numbers.\n", content @@ -176,6 +172,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "app/controllers" assert_file "app/views" assert_file "app/helpers" + assert_file "app/mailers" assert_file "config/routes.rb", /Rails.application.routes.draw do/ assert_file "lib/bukkits/engine.rb", /module Bukkits\n class Engine < ::Rails::Engine\n end\nend/ assert_file "lib/bukkits.rb", /require "bukkits\/engine"/ @@ -257,6 +254,10 @@ protected silence(:stdout){ generator.send(*args, &block) } end +protected + def default_files + ::DEFAULT_PLUGIN_FILES + end end class CustomPluginGeneratorTest < Rails::Generators::TestCase -- cgit v1.2.3 From 6969638020ae04cc4bf63605f603f6fdab9e4b39 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 29 Jul 2011 23:05:40 +0530 Subject: Covering more files in test for plugin new generator. --- railties/test/generators/plugin_new_generator_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 19e80eee89..b49945f153 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -7,11 +7,13 @@ DEFAULT_PLUGIN_FILES = %w( .gitignore Gemfile Rakefile + README.rdoc bukkits.gemspec MIT-LICENSE lib lib/bukkits.rb lib/tasks/bukkits_tasks.rake + lib/bukkits/version.rb test/bukkits_test.rb test/test_helper.rb test/dummy -- cgit v1.2.3 From 040f65b0913793bd6f2f03500e6e6a50b83f3e56 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 31 Jul 2011 21:39:10 +0530 Subject: fixes #2368. rake about not showing the middleware, db adapter and db schema version --- railties/lib/rails/tasks/misc.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/tasks/misc.rake b/railties/lib/rails/tasks/misc.rake index 833fcb6f72..8b4775d1d3 100644 --- a/railties/lib/rails/tasks/misc.rake +++ b/railties/lib/rails/tasks/misc.rake @@ -14,7 +14,7 @@ task :secret do end desc 'List versions of all Rails frameworks and the environment' -task :about do +task :about => :environment do puts Rails::Info end -- cgit v1.2.3 From 6dda2167154c856e8776a192e90118c3b3129b78 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 1 Aug 2011 12:32:17 -0700 Subject: Merge pull request #2324 from zenapsis/3-1-stable Rails 3.1 throws a Errno::ENOTDIR if files are put in assets directories --- railties/lib/rails/engine.rb | 6 +++--- railties/lib/rails/paths.rb | 4 ++++ railties/test/application/assets_test.rb | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index c41f7d7c2e..2c3f61f404 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -542,9 +542,9 @@ module Rails end initializer :append_assets_path do |app| - app.config.assets.paths.unshift(*paths["vendor/assets"].existent) - app.config.assets.paths.unshift(*paths["lib/assets"].existent) - app.config.assets.paths.unshift(*paths["app/assets"].existent) + app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories) + app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories) + app.config.assets.paths.unshift(*paths["app/assets"].existent_directories) end initializer :prepend_helpers_path do |app| diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index de3d0b6fc5..55b820b12e 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -171,6 +171,10 @@ module Rails def existent expanded.select { |f| File.exists?(f) } end + + def existent_directories + expanded.select {|d| Dir.exists?(d) } + end alias to_a expanded end diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 7fb930bd99..802b737483 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -109,5 +109,19 @@ module ApplicationTests assert_match "alert()", last_response.body assert_equal nil, last_response.headers["Set-Cookie"] end + + test "files in any assets/ directories are not added to Sprockets" do + %w[app lib vendor].each do |dir| + app_file "#{dir}/assets/#{dir}_test.erb", "testing" + end + + app_file "app/assets/javascripts/demo.js", "alert();" + + require "#{app_path}/config/environment" + + get "/assets/demo.js" + assert_match "alert();", last_response.body + assert_equal 200, last_response.status + end end end -- cgit v1.2.3 From 3a4dc9d34c1cde8bf34dfa4b4600fb8bcef9eb45 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 1 Aug 2011 17:29:03 -0700 Subject: use File.directory? as Dir.exists? is only 1.9.2+ --- railties/lib/rails/paths.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index 55b820b12e..b37421c09c 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -171,9 +171,9 @@ module Rails def existent expanded.select { |f| File.exists?(f) } end - + def existent_directories - expanded.select {|d| Dir.exists?(d) } + expanded.select { |d| File.directory?(d) } end alias to_a expanded -- cgit v1.2.3 From 3c7b29da1b1fff83fb72a19426193332eaf63577 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Mon, 1 Aug 2011 20:31:19 +0530 Subject: Test added to check mass_assignment_sanitizer is not present if --skip-active-record provided. --- railties/test/generators/app_generator_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index fb7ebaa1fa..0db9b99234 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -314,6 +314,15 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_generated_environments_file_for_sanitizer + run_generator [destination_root, "--skip-active-record"] + ["config/environments/development.rb", "config/environments/test.rb"].each do |env_file| + assert_file env_file do |file| + assert_no_match(/config.active_record.mass_assignment_sanitizer = :strict/, file) + end + end + end + protected def action(*args, &block) -- cgit v1.2.3 From bf5d1d46623d478bb4371a60bead97022cef11ed Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 3 Aug 2011 19:18:34 -0300 Subject: Don't require assets group in production by default, you can change this default in the application.rb anyways --- .../rails/generators/rails/app/templates/config/application.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index 7687b1beac..dd0cf64650 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -13,9 +13,13 @@ require "active_resource/railtie" <% end -%> # If you have a Gemfile, require the default gems, the ones in the -# current environment and also include :assets gems if in development -# or test environments. -Bundler.require *Rails.groups(:assets) if defined?(Bundler) +# current environment and also include :assets gems if you ... +if defined?(Bundler) + # ... precompile your assets + Bundler.require *Rails.groups(:assets => %w(development test)) + # ... want your assets to be lazily compiled also in production + # Bundler.require(:default, :assets, Rails.env) +end module <%= app_const_base %> class Application < Rails::Application -- cgit v1.2.3 From 7d4321711ebb99d2669c02b2030ade0de69655af Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 3 Aug 2011 21:04:32 -0300 Subject: Fix a bit precompile and lazy compile comments --- .../lib/rails/generators/rails/app/templates/config/application.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index dd0cf64650..86c9bd2d1d 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -12,12 +12,10 @@ require "active_resource/railtie" <%= comment_if :skip_test_unit %>require "rails/test_unit/railtie" <% end -%> -# If you have a Gemfile, require the default gems, the ones in the -# current environment and also include :assets gems if you ... if defined?(Bundler) - # ... precompile your assets + # If you precompile assets before deploying to production, use this line Bundler.require *Rails.groups(:assets => %w(development test)) - # ... want your assets to be lazily compiled also in production + # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end -- cgit v1.2.3 From 4265f2eaa50b9783059bc84c3f8d2d4001fa9b7a Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 25 Jul 2011 15:10:13 -0700 Subject: sync the getting started guide with master --- railties/guides/source/getting_started.textile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 0b89021392..6c8aa668b2 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -197,9 +197,10 @@ For example, the following HTTP request: DELETE /photos/17 -refers to a photo resource with an ID of 17 and indicates an action to be taken -upon it: deletion. REST is a natural web application architecture which Rails -abstracts, shielding you from RESTful complexities and browser quirks. +would be understood to refer to a photo resource with the ID of 17, and to +indicate a desired action - deleting that resource. REST is a natural style for +the architecture of web applications, and Rails hooks into this shielding you +from many of the RESTful complexities and browser quirks. If you'd like more details on REST as an architectural style, these resources are more approachable than Fielding's thesis: -- cgit v1.2.3 From 2dc6cca773380e55d2afe0d3de34fa7c68f9f7d7 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 26 Jul 2011 19:35:16 +0530 Subject: move the note after the scaffold files listing --- railties/guides/source/getting_started.textile | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 6c8aa668b2..3cca383616 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -536,21 +536,8 @@ command in your terminal: $ rails generate scaffold Post name:string title:string content:text -This will create a new database table called posts (plural of Post). The table -will have three columns, name (type string), title (type string) and content -(type text). It will also hook this new database up to Rails (details below). - -NOTE. While scaffolding will get you up and running quickly, the code it -generates is unlikely to be a perfect fit for your application. You'll most -probably want to customize the generated code. Many experienced Rails developers -avoid scaffolding entirely, preferring to write all or most of their source code -from scratch. Rails, however, makes it really simple to customize templates for -generated models, controllers, views and other source files. You'll find more -information in the "Creating and Customizing Rails Generators & -Templates":generators.html guide. - -The scaffold generator will build 17 files in your application, along with some -folders, and edit one more. Here's a quick overview of what it creates: +The scaffold generator will build several files in your application, along with some +folders, and edit config/routes.rb. Here's a quick overview of what it creates: |_.File |_.Purpose| |db/migrate/20100207214725_create_posts.rb |Migration to create the posts table in your database (your name will include a different timestamp)| @@ -571,6 +558,15 @@ folders, and edit one more. Here's a quick overview of what it creates: |test/unit/helpers/posts_helper_test.rb |Unit testing harness for the posts helper| |config/routes.rb |Edited to include routing information for posts| +NOTE. While scaffolding will get you up and running quickly, the code it +generates is unlikely to be a perfect fit for your application. You'll most +probably want to customize the generated code. Many experienced Rails developers +avoid scaffolding entirely, preferring to write all or most of their source code +from scratch. Rails, however, makes it really simple to customize templates for +generated models, controllers, views and other source files. You'll find more +information in the "Creating and Customizing Rails Generators & +Templates":generators.html guide. + h4. Running a Migration One of the products of the +rails generate scaffold+ command is a _database -- cgit v1.2.3 From e84ea65e71062109d9e95e36ea0c5640fb0d6d6f Mon Sep 17 00:00:00 2001 From: Alberto Perdomo Date: Thu, 28 Jul 2011 00:51:14 +0100 Subject: Association and Callbacks guide: Added section on shortcut syntax 'validates'. --- .../active_record_validations_callbacks.textile | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index ce0b5416de..e2ec874190 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -612,6 +612,61 @@ class Movie < ActiveRecord::Base end +h3. Shortcut helper + +There is a special method +validates+ that is a shortcut to all default validators and any custom validator classes ending in 'Validator'. Note that Rails default validators can be overridden inside specific classes by creating custom validator classes in their place such as +PresenceValidator+. + +h4. Multiple validations for a single attribue + +In cases where you want multiple validations for a single attribute you can do it with a one-liner. + + +class User < ActiveRecord::Base + validates :password, :presence => true, :confirmation => true, :length => { :minimum => 6 } +end + + +h4. Combining standard validations with custom validators + +You can also combine standard validations with your own custom validators. + + +class EmailValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + record.errors[attribute] << (options[:message] || "is not an email") unless + value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i + end +end + +class Person + include ActiveModel::Validations + attr_accessor :name, :email + + validates :name, :presence => true, :uniqueness => true, :length => { :maximum => 100 } + validates :email, :presence => true, :email => true +end + + +h4. Validating multiple attributes with the same criteria + +If you have a case where you want to apply the same validations to multiple attributes you can do that as well. + + +class BlogPost < ActiveRecord::Base + validates :title, :body, :presence => true +end + + +h4. Using the standard options + +The shortcut syntax is also compatible with the standard options +:allow_nil+, +:allow_blank+, etc. as well as the conditional options +:if+ and +unless+. + + +class User < ActiveRecord::Base + validates :password, :presence => { :if => :password_required? }, :confirmation => true +end + + h3. Working with Validation Errors In addition to the +valid?+ and +invalid?+ methods covered earlier, Rails provides a number of methods for working with the +errors+ collection and inquiring about the validity of objects. -- cgit v1.2.3 From 60af023107c8b11e2a07b8950d9fea8849fe2c32 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Fri, 19 Aug 2011 09:47:46 +0000 Subject: Extra "l" removed before h2. --- railties/guides/source/i18n.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index 0c8e4e974d..5a6343472c 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -1,4 +1,4 @@ -lh2. Rails Internationalization (I18n) API +h2. Rails Internationalization (I18n) API The Ruby I18n (shorthand for _internationalization_) gem which is shipped with Ruby on Rails (starting from Rails 2.2) provides an easy-to-use and extensible framework for *translating your application to a single custom language* other than English or for *providing multi-language support* in your application. -- cgit v1.2.3 From f56c2b88c58c33643050551c6824dfbf2b7b421e Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Sat, 30 Jul 2011 18:19:43 +0530 Subject: Active Resouce guide initial load --- railties/guides/source/active_resource_basics.textile | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 railties/guides/source/active_resource_basics.textile (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile new file mode 100644 index 0000000000..5df8b6612d --- /dev/null +++ b/railties/guides/source/active_resource_basics.textile @@ -0,0 +1,11 @@ +h2. Active Resource Basics + +This guide should provide you with all you need to get started managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics. + +endprologue. + +WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails. + +h3. Changelog + +* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file -- cgit v1.2.3 From e898556543fbfcbaeed88420590d555c857315cc Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Sat, 30 Jul 2011 18:21:21 +0530 Subject: Introduction for active resource --- railties/guides/source/active_resource_basics.textile | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 5df8b6612d..5cf22f8e39 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -6,6 +6,10 @@ endprologue. WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails. +h3. Introduction + +Active Resource allows you to connect with RESTful web services. So, in Rails, Resource classes inherited from +ActiveResource::Base+ and live in +app/models+. + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file -- cgit v1.2.3 From 8d1c642cae05cbf4c4fa44b9f7afb7c7a3727bd3 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Sat, 30 Jul 2011 18:23:05 +0530 Subject: configuration for active resource --- railties/guides/source/active_resource_basics.textile | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 5cf22f8e39..f0cd25bfc2 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -10,6 +10,17 @@ h3. Introduction Active Resource allows you to connect with RESTful web services. So, in Rails, Resource classes inherited from +ActiveResource::Base+ and live in +app/models+. +h3. Configuration and Usage + +Putting Active Resource to use is very similar to Active Record. It's as simple as creating a model class +that inherits from ActiveResource::Base and providing a site class variable to it: + + +class Person < ActiveResource::Base + self.site = "http://api.people.com:3000/" +end + + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file -- cgit v1.2.3 From c62cb2f2fbbd7987a4e09e9ffd63b60560785e6f Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Sat, 30 Jul 2011 18:24:18 +0530 Subject: usages of active resouce --- railties/guides/source/active_resource_basics.textile | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index f0cd25bfc2..64f0949475 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -21,6 +21,15 @@ class Person < ActiveResource::Base end +Now the Person class is REST enabled and can invoke REST services very similarly to how Active Record invokes +life cycle methods that operate against a persistent store. + + +# Find a person with id = 1 +ryan = Person.find(1) +Person.exists?(1) # => true + + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file -- cgit v1.2.3 From 29772a136a6f148f3cc27ddfccc29bd9ddc672e3 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 30 Jul 2011 23:50:31 +0530 Subject: remove some parts of the section on shortcut helpers, document custom validators --- .../active_record_validations_callbacks.textile | 104 +++++++++------------ 1 file changed, 45 insertions(+), 59 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index e2ec874190..5789d36c6d 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -569,101 +569,87 @@ end All validations inside of +with_options+ block will have automatically passed the condition +:if => :is_admin?+ -h3. Creating Custom Validation Methods +h3. Performing Custom Validations -When the built-in validation helpers are not enough for your needs, you can write your own validation methods. +When the built-in validation helpers are not enough for your needs, you can write your own validators or validation methods as you prefer. -Simply create methods that verify the state of your models and add messages to the +errors+ collection when they are invalid. You must then register these methods by using one or more of the +validate+, +validate_on_create+ or +validate_on_update+ class methods, passing in the symbols for the validation methods' names. +h4. Custom Validators -You can pass more than one symbol for each class method and the respective validations will be run in the same order as they were registered. +Custom validators are classes that extend ActiveModel::Validator. These classes must implement a +validate+ method which takes a record as an argument and performs the validation on it. The custom validator is called using the +validates_with+ method. -class Invoice < ActiveRecord::Base - validate :expiration_date_cannot_be_in_the_past, - :discount_cannot_be_greater_than_total_value - - def expiration_date_cannot_be_in_the_past - errors.add(:expiration_date, "can't be in the past") if - !expiration_date.blank? and expiration_date < Date.today +class MyValidator < ActiveModel::Validator + def validate(record) + if record.name.starts_with? 'X' + record.errors[:name] << 'Need a name starting with X please!' + end end +end - def discount_cannot_be_greater_than_total_value - errors.add(:discount, "can't be greater than total value") if - discount > total_value - end +class Person + include ActiveModel::Validations + validates_with MyValidator end -You can even create your own validation helpers and reuse them in several different models. For example, an application that manages surveys may find it useful to express that a certain field corresponds to a set of choices: +The easiest way to add custom validators for validating individual attributes is with the convenient ActiveModel::EachValidator. In this case, the custom validator class must implement a +validate_each+ method which takes three arguments: record, attribute and value which correspond to the instance, the attribute to be validated and the value of the attribute in the passed instance. -ActiveRecord::Base.class_eval do - def self.validates_as_choice(attr_name, n, options={}) - validates attr_name, :inclusion => { {:in => 1..n}.merge(options) } +class EmailValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i + record.errors[attribute] << (options[:message] || "is not an email") + end end end - - -Simply reopen +ActiveRecord::Base+ and define a class method like that. You'd typically put this code somewhere in +config/initializers+. You can use this helper like this: - -class Movie < ActiveRecord::Base - validates_as_choice :rating, 5 +class Person < ActiveRecord::Base + validates :email, :presence => true, :email => true end -h3. Shortcut helper +As shown in the example, you can also combine standard validations with your own custom validators. -There is a special method +validates+ that is a shortcut to all default validators and any custom validator classes ending in 'Validator'. Note that Rails default validators can be overridden inside specific classes by creating custom validator classes in their place such as +PresenceValidator+. +h4. Custom Methods -h4. Multiple validations for a single attribue +You can also create methods that verify the state of your models and add messages to the +errors+ collection when they are invalid. You must then register these methods by using one or more of the +validate+, +validate_on_create+ or +validate_on_update+ class methods, passing in the symbols for the validation methods' names. -In cases where you want multiple validations for a single attribute you can do it with a one-liner. +You can pass more than one symbol for each class method and the respective validations will be run in the same order as they were registered. -class User < ActiveRecord::Base - validates :password, :presence => true, :confirmation => true, :length => { :minimum => 6 } -end - - -h4. Combining standard validations with custom validators - -You can also combine standard validations with your own custom validators. +class Invoice < ActiveRecord::Base + validate :expiration_date_cannot_be_in_the_past, + :discount_cannot_be_greater_than_total_value - -class EmailValidator < ActiveModel::EachValidator - def validate_each(record, attribute, value) - record.errors[attribute] << (options[:message] || "is not an email") unless - value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i + def expiration_date_cannot_be_in_the_past + if !expiration_date.blank? and expiration_date < Date.today + errors.add(:expiration_date, "can't be in the past") + end end -end - -class Person - include ActiveModel::Validations - attr_accessor :name, :email - validates :name, :presence => true, :uniqueness => true, :length => { :maximum => 100 } - validates :email, :presence => true, :email => true + def discount_cannot_be_greater_than_total_value + if discount > total_value + errors.add(:discount, "can't be greater than total value") + end + end end -h4. Validating multiple attributes with the same criteria - -If you have a case where you want to apply the same validations to multiple attributes you can do that as well. +You can even create your own validation helpers and reuse them in several different models. For example, an application that manages surveys may find it useful to express that a certain field corresponds to a set of choices: -class BlogPost < ActiveRecord::Base - validates :title, :body, :presence => true +ActiveRecord::Base.class_eval do + def self.validates_as_choice(attr_name, n, options={}) + validates attr_name, :inclusion => { {:in => 1..n}.merge(options) } + end end -h4. Using the standard options - -The shortcut syntax is also compatible with the standard options +:allow_nil+, +:allow_blank+, etc. as well as the conditional options +:if+ and +unless+. +Simply reopen +ActiveRecord::Base+ and define a class method like that. You'd typically put this code somewhere in +config/initializers+. You can use this helper like this: -class User < ActiveRecord::Base - validates :password, :presence => { :if => :password_required? }, :confirmation => true +class Movie < ActiveRecord::Base + validates_as_choice :rating, 5 end -- cgit v1.2.3 From 54e7694982510e22810c064ae3594f74209c94b9 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 30 Jul 2011 23:53:11 +0530 Subject: prefer to use if..end unless the condition is simple/compact --- .../guides/source/active_record_validations_callbacks.textile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 5789d36c6d..977e736d25 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -1143,8 +1143,9 @@ Here's an example where we create a class with an +after_destroy+ callback for a class PictureFileCallbacks def after_destroy(picture_file) - File.delete(picture_file.filepath) - if File.exists?(picture_file.filepath) + if File.exists?(picture_file.filepath) + File.delete(picture_file.filepath) + end end end @@ -1162,8 +1163,9 @@ Note that we needed to instantiate a new +PictureFileCallbacks+ object, since we class PictureFileCallbacks def self.after_destroy(picture_file) - File.delete(picture_file.filepath) - if File.exists?(picture_file.filepath) + if File.exists?(picture_file.filepath) + File.delete(picture_file.filepath) + end end end -- cgit v1.2.3 From 4e28c40bfd16a1d9f41c8c713f2b4cc19d5dd1f7 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 31 Jul 2011 01:32:20 +0530 Subject: 3.1 release notes draft --- railties/guides/source/3_1_release_notes.textile | 136 +++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 railties/guides/source/3_1_release_notes.textile (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile new file mode 100644 index 0000000000..0348259668 --- /dev/null +++ b/railties/guides/source/3_1_release_notes.textile @@ -0,0 +1,136 @@ +h2. Ruby on Rails 3.1 Release Notes + +Highlights in Rails 3.1: + +* Streaming +* Reversible Migrations +* Assets Pipeline +* jQuery as the default JavaScript library + +This release notes cover the major changes, but don't include every little bug fix and change. If you want to see everything, check out the "list of commits":https://github.com/rails/rails/commits/master in the main Rails repository on GitHub. + +endprologue. + +h3. Upgrading to Rails 3.1 + +If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 3 and make sure your application still runs as expected before attempting to update to Rails 3.1. Then take heed of the following changes: + +h4. Rails 3.1 requires at least Ruby 1.8.7 + +Rails 3.1 requires Ruby 1.8.7 or higher. Support for all of the previous Ruby versions has been dropped officially and you should upgrade as early as possible. Rails 3.1 is also compatible with Ruby 1.9.2. + +TIP: Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults, so if you want to use 1.9.x jump on 1.9.2 for smooth sailing. + +TODO. What else? + +h3. Creating a Rails 3.1 application + + +# You should have the 'rails' rubygem installed +$ rails new myapp +$ cd myapp + + +h4. Vendoring Gems + +Rails now uses a +Gemfile+ in the application root to determine the gems you require for your application to start. This +Gemfile+ is processed by the "Bundler":https://github.com/carlhuda/bundler, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems. + +More information: - "bundler homepage":http://gembundler.com + +h4. Living on the Edge + ++Bundler+ and +Gemfile+ makes freezing your Rails application easy as pie with the new dedicated bundle command. If you want to bundle straight from the Git repository, you can pass the +--edge+ flag: + + +$ rails new myapp --edge + + +If you have a local checkout of the Rails repository and want to generate an application using that, you can pass the +--dev+ flag: + + +$ ruby /path/to/rails/bin/rails new myapp --dev + + +h3. Rails Architectural Changes + +h4. Assets Pipeline + +h3. Documentation + +The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released). + +More Information: - "Rails Documentation Projects":http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects. + +h3. Internationalization + +h3. Railties + +h3. Action Pack + +h4. Abstract Controller + +h4. Action Controller + +h4. Action Dispatch + +h4. Action View + +h3. Active Record + +h3. Active Model + +The major changes in Active Model are: + +* +attr_accessible+ accepts an option +:as+ to specify a role. + +* +InclusionValidator+, +ExclusionValidator+, and +FormatValidator+ now accepts an option which can be a proc, a lambda, or anything that respond to +call+. This option will be called with the current record as an argument and returns an object which respond to +include?+ for +InclusionValidator+ and +ExclusionValidator+, and returns a regular expression object for +FormatValidator+. + +* Added ActiveModel::SecurePassword to encapsulate dead-simple password usage with BCrypt encryption and salting. + +* ActiveModel::AttributeMethods allows attributes to be defined on demand. + +h3. Active Resource + +The changes in Active Resource are: + +* The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. For example, + + +class User < ActiveResource::Base + self.format = :xml +end + + +h3. Active Support + +The main changes in Active Support are: + +* ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant. + +* Added a new reporting method Kernel#quietly which silences both STDOUT and STDERR. + +* Added String#inquiry as a convenience method for turning a String into a +StringInquirer+ object. + +* Added Object#in? to test if an object is included in another object. + +* LocalCache strategy is now a real middleware class and no longer an anonymous class. + +* ActiveSupport::Dependencies::ClassCache class has been introduced for holding references to reloadable classes. + +* ActiveSupport::Dependencies::Reference has been refactored to take direct advantage of the new ClassCache. + +* Backports Range#cover? as an alias for Range#include? in Ruby 1.8. + +* Added +weeks_ago+ and +prev_week+ to Date/DateTime/Time. + +* Added +before_remove_const+ callback to ActiveSupport::Dependencies.remove_unloadable_constants! + +Deprecations: + +* ActiveSupport::SecureRandom is deprecated in favor of +SecureRandom+ from the Ruby standard library. + +h3. Credits + +See the "full list of contributors to Rails":http://contributors.rubyonrails.org/ for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them. + +Rails 3.1 Release Notes were compiled by "Vijay Dev":https://github.com/vijaydev. -- cgit v1.2.3 From fe6b967aea0c562a5bcae54225dbce29013991b9 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 31 Jul 2011 03:05:24 +0530 Subject: 3.1 release notes - added AP and Railties sections --- railties/guides/source/3_1_release_notes.textile | 142 +++++++++++++++++++++++ 1 file changed, 142 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index 0348259668..f520e4dfea 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -55,6 +55,8 @@ h3. Rails Architectural Changes h4. Assets Pipeline +TODO. point to assets guide, talk about rake assets:* tasks + h3. Documentation The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released). @@ -65,8 +67,148 @@ h3. Internationalization h3. Railties +* jQuery is the new default JavaScript library. + +* jQuery and prototype are no longer vendored and is provided from now on by the jquery-rails and prototype-rails gems. + +* The application generator accepts an option -j which can be an arbitrary string. If passed "foo", the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest requires "foo" and "foo_ujs". Currently only "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline. + +* Generating an application or a plugin runs bundle install unless --skip-gemfile or --skip-bundle is specified. + +* The controller and resource generators will now automatically produce asset stubs (this can be turned off with --skip-assets). These stubs will use CoffeeScript and Sass, if those libraries are available. + +* Scaffold and app generators use the Ruby 1.9 style hash when running on Ruby 1.9. To generate old style hash, --old-style-hash can be passed. + +* Scaffold controller generator creates format block for JSON instead of XML. + +* Active Record logging is directed to STDOUT and shown inline in the console. + +* Added +config.force_ssl+ configuration which loads Rack::SSL middleware and force all requests to be under HTTPS protocol. + +* Added +rails plugin new+ command which generates a Rails plugin with gemspec, tests and a dummy application for testing. + +* Added Rack::Etag and Rack::ConditionalGet to the default middleware stack. + +* Added Rack::Cache to the default middleware stack. + +* TODO Engine related changes + h3. Action Pack +TODO split items into controller/view sections. + +* A warning is given out if the CSRF token authenticity cannot be verified. + +* Allows AM/PM format in datetime selectors. + +* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink + +* Added streaming support, you can enable it with: + + +class PostsController < ActionController::Base + stream :only => :index +end + + +Please read the docs at ActionController::Streaming for more information. TODO add links to api docs. + +* Added ActionDispatch::Request.ignore_accept_header to ignore accept headers. + +* Created ActionView::Renderer and specified an API for ActionView::Context. + +* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. + +* Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call. + + +class PostsController < ApplicationController + USER_NAME, PASSWORD = "dhh", "secret" + + before_filter :authenticate, :except => [ :index ] + + def index + render :text => "Everyone can see me!" + end + + def edit + render :text => "I'm only accessible if you know the password" + end + + private + def authenticate + authenticate_or_request_with_http_basic do |user_name, password| + user_name == USER_NAME && password == PASSWORD + end + end +end + + +..can now be written as + + +class PostsController < ApplicationController + http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index + + def index + render :text => "Everyone can see me!" + end + + def edit + render :text => "I'm only accessible if you know the password" + end +end + + +* Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, :only or :except can be used. + +* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete }) + +* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper. + +* Sensitive query string parameters specified in config.filter_parameters will now be filtered out from the request paths in the log. + +* URL parameters which return nil for +to_param+ are now removed from the query string. + +* ActionDispatch::MiddlewareStack now uses composition over inheritance and is no longer an array. + +* Added an :authenticity_token option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false. + +* Added HTML5 button_tag helper. + +* Template lookup now searches further up in the inheritance chain. + +* config.action_view.cache_template_loading is brought back which allows to decide whether templates should be cached or not. TODO from which version? + +* url_for and named url helpers now accept :subdomain and :domain as options. + +* The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused. + +* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller). + +* Added a convenience idiom to generate HTML5 data-* attributes in tag helpers from a :data hash of options: + + +tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)}) +# =>
+ + +Keys are dasherized. Values are JSON-encoded, except for strings and symbols. + +* The old template handler API is deprecated and the new API simply requires a template handler to respond to call. + +* rhtml and rxml are finally removed as template handlers. + +* Moved etag responsibility from ActionDispatch::Response to the middleware stack. + +* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy. + +* file_field automatically adds :multipart => true to the enclosing form. + +* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases csrf_meta_tag for backwards compatibility. + +* Added Rack::Cache to the default stack. + h4. Abstract Controller h4. Action Controller -- cgit v1.2.3 From 8362b070dc959a11042afc9a9a5a8529178c4090 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sun, 31 Jul 2011 16:56:40 +0530 Subject: Rack::Sendfile is no more default middleware. --- railties/guides/source/command_line.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index b34506d4d8..627e22f2de 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -386,7 +386,7 @@ Action Pack version 3.1.0 Active Resource version 3.1.0 Action Mailer version 3.1.0 Active Support version 3.1.0 -Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, Rack::Sendfile, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head +Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head Application root /home/foobar/commandsapp Environment development -- cgit v1.2.3 From f63599825b440e214c09646501be33933d265562 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sun, 31 Jul 2011 21:58:59 +0530 Subject: Adding more info as rake about is fixed --- railties/guides/source/command_line.textile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 627e22f2de..f48fa96451 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -389,6 +389,8 @@ Active Support version 3.1.0 Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head Application root /home/foobar/commandsapp Environment development +Database adapter sqlite3 +Database schema version 0 h4. +assets+ -- cgit v1.2.3 From 05f6135895d74f9058f550e6ece4593d2b6501fe Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 31 Jul 2011 23:23:25 +0530 Subject: 3.1 release notes Active Record changes, Architectural changes and organizing sections. --- railties/guides/source/3_1_release_notes.textile | 189 ++++++++++++++++++++--- 1 file changed, 165 insertions(+), 24 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index f520e4dfea..7d85d7a600 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -55,15 +55,23 @@ h3. Rails Architectural Changes h4. Assets Pipeline -TODO. point to assets guide, talk about rake assets:* tasks +The major change in Rails 3.1 is the Assets Pipeline. It makes CSS and JavaScript first-class code citizens and enables proper organization, including use in plugins and engines. -h3. Documentation +The assets pipeline is powered by "Sprockets":https://github.com/sstephenson/sprockets and is covered in the "Asset Pipeline":asset_pipeline.html guide. -The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released). +h4. HTTP Streaming -More Information: - "Rails Documentation Projects":http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects. +HTTP Streaming is another change that is new in Rails 3.1. This lets the browser download your stylesheets and JavaScript files while the server is still generating the response. This requires Ruby 1.9.2, is opt-in and requires support from the web server as well, but the popular combo of nginx and unicorn is ready to take advantage of it. -h3. Internationalization +h4. Default JS library is now jQuery + +jQuery is the default JavaScript library that ships with Rails 3.1. But if you use Prototype, it's simple to switch. + +h4. Identity Map + +Active Record has an Identity Map in Rails 3.1. An identity map keeps previously instantiated records and returns the object associated with the record if accessed again. The identity map is created on a per-request basis and is flushed at request completion. + +Rails 3.1 comes with the identity map turned off by default. h3. Railties @@ -95,13 +103,9 @@ h3. Railties h3. Action Pack -TODO split items into controller/view sections. - -* A warning is given out if the CSRF token authenticity cannot be verified. - -* Allows AM/PM format in datetime selectors. +h4. Abstract Controller -* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink +h4. Action Controller * Added streaming support, you can enable it with: @@ -111,13 +115,25 @@ class PostsController < ActionController::Base end -Please read the docs at ActionController::Streaming for more information. TODO add links to api docs. +Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information. + +* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. + +h4. Action Dispatch * Added ActionDispatch::Request.ignore_accept_header to ignore accept headers. +h4. Action View + * Created ActionView::Renderer and specified an API for ActionView::Context. -* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. +TODO + +* A warning is given out if the CSRF token authenticity cannot be verified. + +* Allows AM/PM format in datetime selectors. + +* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink * Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call. @@ -209,19 +225,148 @@ Keys are dasherized. Values are JSON-encoded, except for strings and symbols. * Added Rack::Cache to the default stack. -h4. Abstract Controller +h3. Active Record -h4. Action Controller +* Added a class method pluralize_table_names to singularize/pluralize table names of individual models. Previously this could only be set globally for all models through ActiveRecord::Base.pluralize_table_names. + +class User < ActiveRecord::Base + self.pluralize_table_names = false +end + -h4. Action Dispatch +* Added block setting of attributes to singular associations. The block will get called after the instance is initialized. -h4. Action View + +class User < ActiveRecord::Base + has_one :account +end -h3. Active Record +user.build_account{ |a| a.credit_limit => 100.0 } + -h3. Active Model +* Added ActiveRecord::Base.attribute_names to return a list of attribute names. This will return an empty array if the model is abstract or the table does not exist. + +* CSV Fixtures are deprecated and support will be removed in Rails 3.2.0 + +* ActiveRecord#new, ActiveRecord#create and ActiveRecord#update_attributes all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of ActiveModel's new mass assignment capabilities: + + +class Post < ActiveRecord::Base + attr_accessible :title + attr_accessible :title, :published_at, :as => :admin +end + +Post.new(params[:post], :as => :admin) + + +* default_scope can now take a block, lambda, or any other object which responds to call for lazy evaluation: + +* Default scopes are now evaluated at the latest possible moment, to avoid problems where scopes would be created which would implicitly contain the default scope, which would then be impossible to get rid of via Model.unscoped. + +* PostgreSQL adapter only supports PostgreSQL version 8.2 and higher. + +* ConnectionManagement middleware is changed to clean up the connection pool after the rack body has been flushed. + +* Added an update_column method on ActiveRecord. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use #update_attribute unless you are sure you do not want to execute any callback, including the modification of the updated_at column. It should not be called on new records. + +* Associations with a :through option can now use any association as the through or source association, including other associations which have a :through option and has_and_belongs_to_many associations. + +* The configuration for the current database connection is now accessible via ActiveRecord::Base.connection_config. -The major changes in Active Model are: +* limits and offsets are removed from COUNT queries unless both are supplied. + +People.limit(1).count # => 'SELECT COUNT(*) FROM people' +People.offset(1).count # => 'SELECT COUNT(*) FROM people' +People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET 1' + + +* ActiveRecord::Associations::AssociationProxy has been split. There is now an +Association+ class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper +called+ CollectionProxy, which proxies collection associations. This prevents namespace pollution, separates concerns, and will allow further refactorings. + +* Singular associations (has_one, belongs_to) no longer have a proxy and simply returns the associated record or nil. This means that you should not use undocumented methods such as bob.mother.create - use bob.create_mother instead. + +* Support the :dependent option on has_many :through associations. For historical and practical reasons, :delete_all is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is :nullify for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association. + +* The behavior of association.destroy for has_and_belongs_to_many and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'. + +* Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It would not delete any records in the join table. Now, it deletes the records in the join table. + +* Previously, has_many_through.destroy(*records) would destroy the records themselves, and the records in the join table. [Note: This has not always been the case; previous version of Rails only deleted the records themselves.] Now, it destroys only the records in the join table. + +* Note that this change is backwards-incompatible to an extent, but there is unfortunately no way to 'deprecate' it before changing it. The change is being made in order to have consistency as to the meaning of 'destroy' or 'delete' across the different types of associations. If you wish to destroy the records themselves, you can do records.association.each(&:destroy) + +* Add :bulk => true option to +change_table+ to make all the schema changes defined in a block using a single ALTER statement. + + +change_table(:users, :bulk => true) do |t| + t.string :company_name + t.change :birthdate, :datetime +end + + +* Removed support for accessing attributes on a +has_and_belongs_to_many+ join table. has_many :through needs to be used. + +* Added a +create_association!+ method for +has_one+ and +belongs_to+ associations. + +* Migrations are now reversible, meaning that Rails will figure out how to reverse your migrations. To use reversible migrations, just define the +change+ method. + +class MyMigration < ActiveRecord::Migration + def change + create_table(:horses) do + t.column :content, :text + t.column :remind_at, :datetime + end + end +end + + +* Some things cannot be automatically reversed for you. If you know how to reverse those things, you should define 'up' and 'down' in your migration. If you define something in change that cannot be reversed, an +IrreversibleMigration+ exception will be raised when going down. + +* Migrations now use instance methods rather than class methods: + +class FooMigration < ActiveRecord::Migration + def up # Not self.up + ... + end +end + + +* Migration files generated from model and constructive migration generators (for example, add_name_to_users) use the reversible migration's change method instead of the ordinary up and down methods. + +* Removed support for interpolating string SQL conditions on associations. Instead, a proc should be used. + + +has_many :things, :conditions => 'foo = #{bar}' # before +has_many :things, :conditions => proc { "foo = #{bar}" } # after + + +Inside the proc, 'self' is the object which is the owner of the association, unless you are eager loading the association, in which case 'self' is the class which the association is within. + +You can have any "normal" conditions inside the proc, so the following will work too: + +has_many :things, :conditions => proc { ["foo = ?", bar] } + + +* Previously :insert_sql and :delete_sql on has_and_belongs_to_many association allowed you to call 'record' to get the record being inserted or deleted. This is now passed as an argument to the proc. + +* Added ActiveRecord::Base#has_secure_password (via ActiveModel::SecurePassword) to encapsulate dead-simple password usage with BCrypt encryption and salting. + +# Schema: User(name:string, password_digest:string, password_salt:string) +class User < ActiveRecord::Base + has_secure_password +end + + +* When a model is generated +add_index+ is added by default for +belongs_to+ or +references+ columns. + +* Setting the id of a belongs_to object will update the reference to the object. + +* ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed to closer match normal Ruby dup and clone semantics. + +* Calling ActiveRecord::Base#clone will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called. + +* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable. + +h3. Active Model * +attr_accessible+ accepts an option +:as+ to specify a role. @@ -233,8 +378,6 @@ The major changes in Active Model are: h3. Active Resource -The changes in Active Resource are: - * The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. For example, @@ -245,8 +388,6 @@ end h3. Active Support -The main changes in Active Support are: - * ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant. * Added a new reporting method Kernel#quietly which silences both STDOUT and STDERR. -- cgit v1.2.3 From abfbab2713211dc6094165a1bb74fde5c17c2a74 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Mon, 1 Aug 2011 20:37:42 +0530 Subject: Active Resource - guide for reading and writing data --- railties/guides/source/active_resource_basics.textile | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 64f0949475..8a36622814 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -24,10 +24,21 @@ end Now the Person class is REST enabled and can invoke REST services very similarly to how Active Record invokes life cycle methods that operate against a persistent store. +h3. Reading and Writing Data + +Active Resource make request over HTTP using a standard JSON format. It mirrors the RESTful routing built into Action Controller but will also work with any other REST service that properly implements the protocol. + +h4. Read + +Read requests use the GET method and expect the JSON form of whatever resource/resources is/are being requested. + # Find a person with id = 1 ryan = Person.find(1) +# Check if a person exists with id = 1 Person.exists?(1) # => true +# Get all resources of Person class +Person.all h3. Changelog -- cgit v1.2.3 From 163533b17d968d23eef0023e4c93338d5357d022 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Mon, 1 Aug 2011 20:48:45 +0530 Subject: Active Resource - guide for create --- railties/guides/source/active_resource_basics.textile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 8a36622814..e40ca4fc42 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -34,13 +34,22 @@ Read requests use the GET method and expect the JSON form of whatever resource/r # Find a person with id = 1 -ryan = Person.find(1) +person = Person.find(1) # Check if a person exists with id = 1 Person.exists?(1) # => true # Get all resources of Person class Person.all +h4. Create + +Creating a new resource submits the JSON form of the resource as the body of the request with HTTP POST method and parse the response into Active Resource object. + + +person = Person.create(:name => 'Vishnu') +person.id # => 1 + + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file -- cgit v1.2.3 From eed1026e83e04aef4c455a15636dab2e0e28efe3 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Mon, 1 Aug 2011 20:57:57 +0530 Subject: Active Resource - guide for update/save --- railties/guides/source/active_resource_basics.textile | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index e40ca4fc42..1115b9848f 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -50,6 +50,16 @@ person = Person.create(:name => 'Vishnu') person.id # => 1 +h4. Update + +To update an existing resource, 'save' method is used. This method make a HTTP PUT request in JSON format. + + +person = Person.find(1) +person.name = 'Atrai' +person.save + + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file -- cgit v1.2.3 From f3564b9e22ae318dadee6c21c52aba01f91b27bb Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Mon, 1 Aug 2011 21:02:48 +0530 Subject: Active Resource - guide for destroy --- railties/guides/source/active_resource_basics.textile | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 1115b9848f..332d113fa7 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -60,6 +60,15 @@ person.name = 'Atrai' person.save +h4. Delete + +'destroy' method makes a HTTP DELETE request for an existing resource in JSON format to delete that resource. + + +person = Person.find(1) +person.destroy + + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file -- cgit v1.2.3 From 9e1a27a0ac4ef246079ac6f61f5b5916c68d0497 Mon Sep 17 00:00:00 2001 From: pbflinn Date: Mon, 1 Aug 2011 12:53:43 -0300 Subject: Fix typo 'console' -> 'constant' --- railties/guides/source/initialization.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 477ee5a3a2..9b92edd250 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -71,7 +71,7 @@ module Rails end -The +rails/script_rails_loader+ file uses +RbConfig::Config+ to gather up the +bin_dir+ and +ruby_install_name+ values for the configuration which will result in a path such as +/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby+, which is the default path on Mac OS X. If you're running Windows the path may be something such as +C:/Ruby192/bin/ruby+. Anyway, the path on your system may be different, but the point of this is that it will point at the known ruby executable location for your install. The +RbConfig::CONFIG["EXEEXT"]+ will suffix this path with ".exe" if the script is running on Windows. This constant is used later on in +exec_script_rails!+. As for the +SCRIPT_RAILS+ console, we'll see that when we get to the +in_rails_application?+ method. +The +rails/script_rails_loader+ file uses +RbConfig::Config+ to gather up the +bin_dir+ and +ruby_install_name+ values for the configuration which will result in a path such as +/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby+, which is the default path on Mac OS X. If you're running Windows the path may be something such as +C:/Ruby192/bin/ruby+. Anyway, the path on your system may be different, but the point of this is that it will point at the known ruby executable location for your install. The +RbConfig::CONFIG["EXEEXT"]+ will suffix this path with ".exe" if the script is running on Windows. This constant is used later on in +exec_script_rails!+. As for the +SCRIPT_RAILS+ constant, we'll see that when we get to the +in_rails_application?+ method. Back in +rails/cli+, the next line is this: -- cgit v1.2.3 From b3719ee7ed4693c782087c56c2ba5984a473deb7 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 3 Aug 2011 19:11:22 +0530 Subject: fixed incorrect tags --- railties/guides/source/migrations.textile | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index e51ee0f535..7b501807d6 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -477,7 +477,7 @@ Several methods are provided that allow you to control all this: For example, this migration -
+
 class CreateProducts < ActiveRecord::Migration
   def change
     suppress_messages do
@@ -496,7 +496,7 @@ class CreateProducts < ActiveRecord::Migration
     end
   end
 end
-
+ generates the following output @@ -525,7 +525,7 @@ Bob goes on vacation. Alice creates a migration for the +products+ table which adds a new column and initializes it. She also adds a validation to the Product model for the new column. -
+
 # db/migrate/20100513121110_add_flag_to_product.rb
 
 class AddFlagToProduct < ActiveRecord::Migration
@@ -534,19 +534,19 @@ class AddFlagToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes!(:flag => 'false') }
   end
 end
-
+ -
+
 # app/model/product.rb
 
 class Product < ActiveRecord::Base
   validates_presence_of :flag
 end
-
+ Alice adds a second migration which adds and initializes another column to the +products+ table and also adds a validation to the Product model for the new column. -
+
 # db/migrate/20100515121110_add_fuzz_to_product.rb
 
 class AddFuzzToProduct < ActiveRecord::Migration
@@ -555,16 +555,16 @@ class AddFuzzToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes! :fuzz => 'fuzzy' }
   end
 end
-
+ -
+
 # app/model/product.rb
 
 class Product < ActiveRecord::Base
   validates_presence_of :flag
   validates_presence_of :fuzz
 end
-
+ Both migrations work for Alice. @@ -575,12 +575,12 @@ Bob comes back from vacation and: The migration crashes because when the model attempts to save, it tries to validate the second added column, which is not in the database when the _first_ migration runs. -
+
 rake aborted!
 An error has occurred, this and all later migrations canceled:
 
 undefined method `fuzz' for #
-
+ A fix for this is to create a local model within the migration. This keeps rails from running the validations, so that the migrations run to completion. @@ -588,7 +588,7 @@ When using a faux model, it's a good idea to call +Product.reset_column_informat If Alice had done this instead, there would have been no problem: -
+
 # db/migrate/20100513121110_add_flag_to_product.rb
 
 class AddFlagToProduct < ActiveRecord::Migration
@@ -600,9 +600,9 @@ class AddFlagToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes!(:flag => false) }
   end
 end
-
+ -
+
 # db/migrate/20100515121110_add_fuzz_to_product.rb
 
 class AddFuzzToProduct < ActiveRecord::Migration
@@ -614,7 +614,7 @@ class AddFuzzToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes! :fuzz => 'fuzzy' }
   end
 end
-
+ h3. Schema Dumping and You -- cgit v1.2.3 From febdd6c96c827b8faee22ba9d15c1d943a70a6d3 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 3 Aug 2011 19:13:12 +0530 Subject: minor changes in migrations guide --- railties/guides/source/migrations.textile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index 7b501807d6..4476e067a6 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -540,7 +540,7 @@ end # app/model/product.rb class Product < ActiveRecord::Base - validates_presence_of :flag + validates :flag, :presence => true end @@ -561,8 +561,7 @@ end # app/model/product.rb class Product < ActiveRecord::Base - validates_presence_of :flag - validates_presence_of :fuzz + validates :flag, :fuzz, :presence => true end @@ -594,9 +593,10 @@ If Alice had done this instead, there would have been no problem: class AddFlagToProduct < ActiveRecord::Migration class Product < ActiveRecord::Base end + def change add_column :products, :flag, :int - Product.reset_column_information + Product.reset_column_information Product.all.each { |f| f.update_attributes!(:flag => false) } end end -- cgit v1.2.3 From 25845b3d42c899749913d948f952f332e275fd26 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 3 Aug 2011 19:34:23 +0530 Subject: typo fix --- railties/guides/source/initialization.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 9b92edd250..6ab2706d6b 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -33,7 +33,7 @@ end This file will attempt to load +rails/cli+ and if it cannot find it then add the +railties/lib+ path to the load path (+$:+) and will then try to require it again. -h4. +railites/lib/rails/cli.rb+ +h4. +railties/lib/rails/cli.rb+ This file looks like this: -- cgit v1.2.3 From 2e764c5fd1ae4757da2cd834ca310f3eeb8db3e0 Mon Sep 17 00:00:00 2001 From: JudeArasu Date: Wed, 3 Aug 2011 23:00:24 +0530 Subject: grammatical changes --- railties/guides/source/form_helpers.textile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index bf2a7369a7..fa0ca5827a 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -45,7 +45,7 @@ NOTE: Throughout this guide, the +div+ with the hidden input elements will be ex h4. A Generic Search Form -One of the most basic forms you see on the web is a search form. This form contains: +One of the most basic forms you will see on the web is a search form. This form contains: # a form element with "GET" method, # a label for the input, @@ -807,3 +807,4 @@ h3. Authors * Mislav Marohnić * "Frederick Cheung":credits.html#fcheung + -- cgit v1.2.3 From e82b4901eb8f5f3582a079e88c75a4fbc7dea767 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 4 Aug 2011 15:02:13 -0700 Subject: Revert "grammatical changes" Reason: As discussed in GitHub, it is debatable, and present tense is fine (and simple, and preferred). This reverts commit 54ccda9f0a5e4a5e72a4c159dc8787faaf65e8a2. --- railties/guides/source/form_helpers.textile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index fa0ca5827a..bf2a7369a7 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -45,7 +45,7 @@ NOTE: Throughout this guide, the +div+ with the hidden input elements will be ex h4. A Generic Search Form -One of the most basic forms you will see on the web is a search form. This form contains: +One of the most basic forms you see on the web is a search form. This form contains: # a form element with "GET" method, # a label for the input, @@ -807,4 +807,3 @@ h3. Authors * Mislav Marohnić * "Frederick Cheung":credits.html#fcheung - -- cgit v1.2.3 From 050c1510b6041a0de21899de1c08d2b816ec0e66 Mon Sep 17 00:00:00 2001 From: Ilya Grigorik Date: Thu, 4 Aug 2011 19:17:03 -0400 Subject: Clear out tmp/cache when assets:clean is invoked. Otherwise, if bad data is cached in tmp/clear then the next invocation of assets:precompile (or a regular incoming request) will pickup files from tmp without regenerating them from source. --- railties/test/application/assets_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 802b737483..38dd3f5a3f 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -80,7 +80,7 @@ module ApplicationTests Dir.chdir(app_path){ `bundle exec rake assets:clean` } end - files = Dir["#{app_path}/public/assets/**/*"] + files = Dir["#{app_path}/public/assets/**/*", "#{app_path}/tmp/cache/*"] assert_equal 0, files.length, "Expected no assets, but found #{files.join(', ')}" end -- cgit v1.2.3 From 201e41e11aa0380265d09f763a4e6ef10868e6e7 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 5 Aug 2011 21:28:14 -0300 Subject: Avoid generating app/views/layouts/application.html.erb on mountable engines, just generate the namespaced one --- .../generators/rails/plugin_new/plugin_new_generator.rb | 2 -- .../app/views/layouts/%name%/application.html.erb.tt | 14 ++++++++++++++ .../templates/app/views/layouts/application.html.erb.tt | 14 -------------- 3 files changed, 14 insertions(+), 16 deletions(-) create mode 100644 railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt delete mode 100644 railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/application.html.erb.tt (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index c46422437d..4baa2110e7 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -11,8 +11,6 @@ module Rails def app if mountable? directory "app" - template "app/views/layouts/application.html.erb.tt", - "app/views/layouts/#{name}/application.html.erb" empty_directory_with_gitkeep "app/assets/images/#{name}" elsif full? empty_directory_with_gitkeep "app/models" diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt b/railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt new file mode 100644 index 0000000000..01550dec2f --- /dev/null +++ b/railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt @@ -0,0 +1,14 @@ + + + + <%= camelized %> + <%%= stylesheet_link_tag "<%= name %>/application" %> + <%%= javascript_include_tag "<%= name %>/application" %> + <%%= csrf_meta_tags %> + + + +<%%= yield %> + + + diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/application.html.erb.tt b/railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/application.html.erb.tt deleted file mode 100644 index 01550dec2f..0000000000 --- a/railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/application.html.erb.tt +++ /dev/null @@ -1,14 +0,0 @@ - - - - <%= camelized %> - <%%= stylesheet_link_tag "<%= name %>/application" %> - <%%= javascript_include_tag "<%= name %>/application" %> - <%%= csrf_meta_tags %> - - - -<%%= yield %> - - - -- cgit v1.2.3 From 8845ae683e2688bc619baade49510c17e978518f Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 7 Aug 2011 12:34:49 -0300 Subject: x_sendfile_header now defaults to nil and production.rb env file doesn't set a particular value for it. This allows servers to set it through X-Sendfile-Type, read https://github.com/rack/rack/blob/master/lib/rack/sendfile.rb for more info. Anyways you can force this value in your production.rb --- railties/lib/rails/application.rb | 4 +--- .../rails/app/templates/config/environments/production.rb.tt | 4 ++-- railties/test/application/middleware/sendfile_test.rb | 3 ++- railties/test/application/middleware_test.rb | 8 -------- 4 files changed, 5 insertions(+), 14 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index fb60ddd9b5..9e2f1a4b7a 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -163,9 +163,7 @@ module Rails middleware.use ::Rails::Rack::Logger # must come after Rack::MethodOverride to properly log overridden methods middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies - if config.action_dispatch.x_sendfile_header.present? - middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header - end + middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header middleware.use ::ActionDispatch::Reloader unless config.cache_classes middleware.use ::ActionDispatch::Callbacks middleware.use ::ActionDispatch::Cookies diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index 06ed890e05..de56d47688 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -15,8 +15,8 @@ config.assets.compress = true # 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_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 diff --git a/railties/test/application/middleware/sendfile_test.rb b/railties/test/application/middleware/sendfile_test.rb index c7a1c573f9..d2ad2668bb 100644 --- a/railties/test/application/middleware/sendfile_test.rb +++ b/railties/test/application/middleware/sendfile_test.rb @@ -27,11 +27,12 @@ module ApplicationTests end # x_sendfile_header middleware - test "config.action_dispatch.x_sendfile_header defaults to ''" do + test "config.action_dispatch.x_sendfile_header defaults to nil" do make_basic_app simple_controller get "/" + assert !last_response.headers["X-Sendfile"] assert_equal File.read(__FILE__), last_response.body end diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index bed5ba503f..6a0a272073 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -20,8 +20,6 @@ module ApplicationTests end test "default middleware stack" do - add_to_config "config.action_dispatch.x_sendfile_header = 'X-Sendfile'" - boot! assert_equal [ @@ -49,12 +47,6 @@ module ApplicationTests ], middleware end - test "Rack::Sendfile is not included by default" do - boot! - - assert !middleware.include?("Rack::Sendfile"), "Rack::Sendfile is not included in the default stack unless you set config.action_dispatch.x_sendfile_header" - end - test "Rack::Cache is present when action_controller.perform_caching is set" do add_to_config "config.action_controller.perform_caching = true" -- cgit v1.2.3 From e746980507ed48e30ab35daf587bf9863d5b9261 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 7 Aug 2011 16:20:31 -0700 Subject: guides generation: apparently this workaround for RedCloth is not needed anymore --- railties/guides/rails_guides/generator.rb | 48 ++-------------------- railties/guides/rails_guides/textile_extensions.rb | 25 +++++++++-- 2 files changed, 26 insertions(+), 47 deletions(-) (limited to 'railties') diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index d304512ff7..4682ead66e 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -199,50 +199,10 @@ module RailsGuides end def textile(body, lite_mode=false) - # If the issue with notextile is fixed just remove the wrapper. - with_workaround_for_notextile(body) do |body| - t = RedCloth.new(body) - t.hard_breaks = false - t.lite_mode = lite_mode - t.to_html(:notestuff, :plusplus, :code) - end - end - - # For some reason the notextile tag does not always turn off textile. See - # LH ticket of the security guide (#7). As a temporary workaround we deal - # with code blocks by hand. - def with_workaround_for_notextile(body) - code_blocks = [] - - body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)}m) do |m| - brush = case $1 - when 'ruby', 'sql', 'plain' - $1 - when 'erb' - 'ruby; html-script: true' - when 'html' - 'xml' # html is understood, but there are .xml rules in the CSS - else - 'plain' - end - - code_blocks.push(< -
-
-#{ERB::Util.h($2).strip}
-
-
- -HTML - "\ndirty_workaround_for_notextile_#{code_blocks.size - 1}\n" - end - - body = yield body - - body.gsub(%r{

dirty_workaround_for_notextile_(\d+)

}) do |_| - code_blocks[$1.to_i] - end + t = RedCloth.new(body) + t.hard_breaks = false + t.lite_mode = lite_mode + t.to_html(:notestuff, :plusplus, :code) end def warn_about_broken_links(html) diff --git a/railties/guides/rails_guides/textile_extensions.rb b/railties/guides/rails_guides/textile_extensions.rb index b3e0e32357..4677fae504 100644 --- a/railties/guides/rails_guides/textile_extensions.rb +++ b/railties/guides/rails_guides/textile_extensions.rb @@ -33,11 +33,30 @@ module RailsGuides body.gsub!('', '+') end + def brush_for(code_type) + case code_type + when 'ruby', 'sql', 'plain' + code_type + when 'erb' + 'ruby; html-script: true' + when 'html' + 'xml' # html is understood, but there are .xml rules in the CSS + else + 'plain' + end + end + def code(body) body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)}m) do |m| - es = ERB::Util.h($2) - css_class = $1.in?(['erb', 'shell']) ? 'html' : $1 - %{
#{es}
} + < +
+
+#{ERB::Util.h($2).strip}
+
+
+ +HTML end end end -- cgit v1.2.3 From 8360d7196515ba66fe5d535f6dbeeea5394e966a Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 8 Aug 2011 12:49:10 -0300 Subject: Initialize config.assets.version the same way it's done in Sprockets --- railties/lib/rails/application/configuration.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 975e159999..cd850b6a75 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -37,6 +37,7 @@ module Rails @assets.paths = [] @assets.precompile = [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ] @assets.prefix = "/assets" + @assets.version = '' @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] @assets.js_compressor = nil -- cgit v1.2.3 From 396e12155aacdb4904fa13e3dc617b6554f48c5f Mon Sep 17 00:00:00 2001 From: Pivotal Casebook Date: Mon, 8 Aug 2011 13:47:24 -0300 Subject: Further monkey-patching to avoid deprecation warnings --- railties/lib/rails/tasks/documentation.rake | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake index 5d613e0698..ca8875ad9b 100644 --- a/railties/lib/rails/tasks/documentation.rake +++ b/railties/lib/rails/tasks/documentation.rake @@ -8,6 +8,8 @@ end # Monkey-patch to remove redoc'ing and clobber descriptions to cut down on rake -T noise class RDocTaskWithoutDescriptions < RDoc::Task + include ::Rake::DSL + def define task rdoc_task_name -- cgit v1.2.3 From 2177282262195f9decf564b237304a6ff94c3048 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Sat, 30 Jul 2011 18:19:43 +0530 Subject: Active Resouce guide initial load --- railties/guides/source/active_resource_basics.textile | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 railties/guides/source/active_resource_basics.textile (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile new file mode 100644 index 0000000000..5df8b6612d --- /dev/null +++ b/railties/guides/source/active_resource_basics.textile @@ -0,0 +1,11 @@ +h2. Active Resource Basics + +This guide should provide you with all you need to get started managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics. + +endprologue. + +WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails. + +h3. Changelog + +* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file -- cgit v1.2.3 From 5da1ddb7506d4dc1b314f6634e4c28e13e6eeaa2 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Sat, 30 Jul 2011 18:21:21 +0530 Subject: Introduction for active resource --- railties/guides/source/active_resource_basics.textile | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 5df8b6612d..5cf22f8e39 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -6,6 +6,10 @@ endprologue. WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails. +h3. Introduction + +Active Resource allows you to connect with RESTful web services. So, in Rails, Resource classes inherited from +ActiveResource::Base+ and live in +app/models+. + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file -- cgit v1.2.3 From 95c2230f0577c8f3ef2312fe9268dc9c0ed3bf8a Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Sat, 30 Jul 2011 18:23:05 +0530 Subject: configuration for active resource --- railties/guides/source/active_resource_basics.textile | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 5cf22f8e39..f0cd25bfc2 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -10,6 +10,17 @@ h3. Introduction Active Resource allows you to connect with RESTful web services. So, in Rails, Resource classes inherited from +ActiveResource::Base+ and live in +app/models+. +h3. Configuration and Usage + +Putting Active Resource to use is very similar to Active Record. It's as simple as creating a model class +that inherits from ActiveResource::Base and providing a site class variable to it: + + +class Person < ActiveResource::Base + self.site = "http://api.people.com:3000/" +end + + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file -- cgit v1.2.3 From ad55b1aa86a1d8b7d6e9e35c7cce77b122bca1e1 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Sat, 30 Jul 2011 18:24:18 +0530 Subject: usages of active resouce --- railties/guides/source/active_resource_basics.textile | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index f0cd25bfc2..64f0949475 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -21,6 +21,15 @@ class Person < ActiveResource::Base end +Now the Person class is REST enabled and can invoke REST services very similarly to how Active Record invokes +life cycle methods that operate against a persistent store. + + +# Find a person with id = 1 +ryan = Person.find(1) +Person.exists?(1) # => true + + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file -- cgit v1.2.3 From 225a2482c19fa3a1acdc05371a44b090c6cb4d7c Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 30 Jul 2011 23:50:31 +0530 Subject: remove some parts of the section on shortcut helpers, document custom validators --- .../active_record_validations_callbacks.textile | 104 +++++++++------------ 1 file changed, 45 insertions(+), 59 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index e2ec874190..5789d36c6d 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -569,101 +569,87 @@ end All validations inside of +with_options+ block will have automatically passed the condition +:if => :is_admin?+ -h3. Creating Custom Validation Methods +h3. Performing Custom Validations -When the built-in validation helpers are not enough for your needs, you can write your own validation methods. +When the built-in validation helpers are not enough for your needs, you can write your own validators or validation methods as you prefer. -Simply create methods that verify the state of your models and add messages to the +errors+ collection when they are invalid. You must then register these methods by using one or more of the +validate+, +validate_on_create+ or +validate_on_update+ class methods, passing in the symbols for the validation methods' names. +h4. Custom Validators -You can pass more than one symbol for each class method and the respective validations will be run in the same order as they were registered. +Custom validators are classes that extend ActiveModel::Validator. These classes must implement a +validate+ method which takes a record as an argument and performs the validation on it. The custom validator is called using the +validates_with+ method. -class Invoice < ActiveRecord::Base - validate :expiration_date_cannot_be_in_the_past, - :discount_cannot_be_greater_than_total_value - - def expiration_date_cannot_be_in_the_past - errors.add(:expiration_date, "can't be in the past") if - !expiration_date.blank? and expiration_date < Date.today +class MyValidator < ActiveModel::Validator + def validate(record) + if record.name.starts_with? 'X' + record.errors[:name] << 'Need a name starting with X please!' + end end +end - def discount_cannot_be_greater_than_total_value - errors.add(:discount, "can't be greater than total value") if - discount > total_value - end +class Person + include ActiveModel::Validations + validates_with MyValidator end -You can even create your own validation helpers and reuse them in several different models. For example, an application that manages surveys may find it useful to express that a certain field corresponds to a set of choices: +The easiest way to add custom validators for validating individual attributes is with the convenient ActiveModel::EachValidator. In this case, the custom validator class must implement a +validate_each+ method which takes three arguments: record, attribute and value which correspond to the instance, the attribute to be validated and the value of the attribute in the passed instance. -ActiveRecord::Base.class_eval do - def self.validates_as_choice(attr_name, n, options={}) - validates attr_name, :inclusion => { {:in => 1..n}.merge(options) } +class EmailValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i + record.errors[attribute] << (options[:message] || "is not an email") + end end end - - -Simply reopen +ActiveRecord::Base+ and define a class method like that. You'd typically put this code somewhere in +config/initializers+. You can use this helper like this: - -class Movie < ActiveRecord::Base - validates_as_choice :rating, 5 +class Person < ActiveRecord::Base + validates :email, :presence => true, :email => true end -h3. Shortcut helper +As shown in the example, you can also combine standard validations with your own custom validators. -There is a special method +validates+ that is a shortcut to all default validators and any custom validator classes ending in 'Validator'. Note that Rails default validators can be overridden inside specific classes by creating custom validator classes in their place such as +PresenceValidator+. +h4. Custom Methods -h4. Multiple validations for a single attribue +You can also create methods that verify the state of your models and add messages to the +errors+ collection when they are invalid. You must then register these methods by using one or more of the +validate+, +validate_on_create+ or +validate_on_update+ class methods, passing in the symbols for the validation methods' names. -In cases where you want multiple validations for a single attribute you can do it with a one-liner. +You can pass more than one symbol for each class method and the respective validations will be run in the same order as they were registered. -class User < ActiveRecord::Base - validates :password, :presence => true, :confirmation => true, :length => { :minimum => 6 } -end - - -h4. Combining standard validations with custom validators - -You can also combine standard validations with your own custom validators. +class Invoice < ActiveRecord::Base + validate :expiration_date_cannot_be_in_the_past, + :discount_cannot_be_greater_than_total_value - -class EmailValidator < ActiveModel::EachValidator - def validate_each(record, attribute, value) - record.errors[attribute] << (options[:message] || "is not an email") unless - value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i + def expiration_date_cannot_be_in_the_past + if !expiration_date.blank? and expiration_date < Date.today + errors.add(:expiration_date, "can't be in the past") + end end -end - -class Person - include ActiveModel::Validations - attr_accessor :name, :email - validates :name, :presence => true, :uniqueness => true, :length => { :maximum => 100 } - validates :email, :presence => true, :email => true + def discount_cannot_be_greater_than_total_value + if discount > total_value + errors.add(:discount, "can't be greater than total value") + end + end end -h4. Validating multiple attributes with the same criteria - -If you have a case where you want to apply the same validations to multiple attributes you can do that as well. +You can even create your own validation helpers and reuse them in several different models. For example, an application that manages surveys may find it useful to express that a certain field corresponds to a set of choices: -class BlogPost < ActiveRecord::Base - validates :title, :body, :presence => true +ActiveRecord::Base.class_eval do + def self.validates_as_choice(attr_name, n, options={}) + validates attr_name, :inclusion => { {:in => 1..n}.merge(options) } + end end -h4. Using the standard options - -The shortcut syntax is also compatible with the standard options +:allow_nil+, +:allow_blank+, etc. as well as the conditional options +:if+ and +unless+. +Simply reopen +ActiveRecord::Base+ and define a class method like that. You'd typically put this code somewhere in +config/initializers+. You can use this helper like this: -class User < ActiveRecord::Base - validates :password, :presence => { :if => :password_required? }, :confirmation => true +class Movie < ActiveRecord::Base + validates_as_choice :rating, 5 end -- cgit v1.2.3 From ad9e52f156575f28949837a3dd0fa433fa824d57 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 30 Jul 2011 23:53:11 +0530 Subject: prefer to use if..end unless the condition is simple/compact --- .../guides/source/active_record_validations_callbacks.textile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 5789d36c6d..977e736d25 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -1143,8 +1143,9 @@ Here's an example where we create a class with an +after_destroy+ callback for a class PictureFileCallbacks def after_destroy(picture_file) - File.delete(picture_file.filepath) - if File.exists?(picture_file.filepath) + if File.exists?(picture_file.filepath) + File.delete(picture_file.filepath) + end end end @@ -1162,8 +1163,9 @@ Note that we needed to instantiate a new +PictureFileCallbacks+ object, since we class PictureFileCallbacks def self.after_destroy(picture_file) - File.delete(picture_file.filepath) - if File.exists?(picture_file.filepath) + if File.exists?(picture_file.filepath) + File.delete(picture_file.filepath) + end end end -- cgit v1.2.3 From ebbf010d4d3f1001ccd6e22e417109135652cafb Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 31 Jul 2011 01:32:20 +0530 Subject: 3.1 release notes draft --- railties/guides/source/3_1_release_notes.textile | 136 +++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 railties/guides/source/3_1_release_notes.textile (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile new file mode 100644 index 0000000000..0348259668 --- /dev/null +++ b/railties/guides/source/3_1_release_notes.textile @@ -0,0 +1,136 @@ +h2. Ruby on Rails 3.1 Release Notes + +Highlights in Rails 3.1: + +* Streaming +* Reversible Migrations +* Assets Pipeline +* jQuery as the default JavaScript library + +This release notes cover the major changes, but don't include every little bug fix and change. If you want to see everything, check out the "list of commits":https://github.com/rails/rails/commits/master in the main Rails repository on GitHub. + +endprologue. + +h3. Upgrading to Rails 3.1 + +If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 3 and make sure your application still runs as expected before attempting to update to Rails 3.1. Then take heed of the following changes: + +h4. Rails 3.1 requires at least Ruby 1.8.7 + +Rails 3.1 requires Ruby 1.8.7 or higher. Support for all of the previous Ruby versions has been dropped officially and you should upgrade as early as possible. Rails 3.1 is also compatible with Ruby 1.9.2. + +TIP: Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults, so if you want to use 1.9.x jump on 1.9.2 for smooth sailing. + +TODO. What else? + +h3. Creating a Rails 3.1 application + + +# You should have the 'rails' rubygem installed +$ rails new myapp +$ cd myapp + + +h4. Vendoring Gems + +Rails now uses a +Gemfile+ in the application root to determine the gems you require for your application to start. This +Gemfile+ is processed by the "Bundler":https://github.com/carlhuda/bundler, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems. + +More information: - "bundler homepage":http://gembundler.com + +h4. Living on the Edge + ++Bundler+ and +Gemfile+ makes freezing your Rails application easy as pie with the new dedicated bundle command. If you want to bundle straight from the Git repository, you can pass the +--edge+ flag: + + +$ rails new myapp --edge + + +If you have a local checkout of the Rails repository and want to generate an application using that, you can pass the +--dev+ flag: + + +$ ruby /path/to/rails/bin/rails new myapp --dev + + +h3. Rails Architectural Changes + +h4. Assets Pipeline + +h3. Documentation + +The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released). + +More Information: - "Rails Documentation Projects":http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects. + +h3. Internationalization + +h3. Railties + +h3. Action Pack + +h4. Abstract Controller + +h4. Action Controller + +h4. Action Dispatch + +h4. Action View + +h3. Active Record + +h3. Active Model + +The major changes in Active Model are: + +* +attr_accessible+ accepts an option +:as+ to specify a role. + +* +InclusionValidator+, +ExclusionValidator+, and +FormatValidator+ now accepts an option which can be a proc, a lambda, or anything that respond to +call+. This option will be called with the current record as an argument and returns an object which respond to +include?+ for +InclusionValidator+ and +ExclusionValidator+, and returns a regular expression object for +FormatValidator+. + +* Added ActiveModel::SecurePassword to encapsulate dead-simple password usage with BCrypt encryption and salting. + +* ActiveModel::AttributeMethods allows attributes to be defined on demand. + +h3. Active Resource + +The changes in Active Resource are: + +* The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. For example, + + +class User < ActiveResource::Base + self.format = :xml +end + + +h3. Active Support + +The main changes in Active Support are: + +* ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant. + +* Added a new reporting method Kernel#quietly which silences both STDOUT and STDERR. + +* Added String#inquiry as a convenience method for turning a String into a +StringInquirer+ object. + +* Added Object#in? to test if an object is included in another object. + +* LocalCache strategy is now a real middleware class and no longer an anonymous class. + +* ActiveSupport::Dependencies::ClassCache class has been introduced for holding references to reloadable classes. + +* ActiveSupport::Dependencies::Reference has been refactored to take direct advantage of the new ClassCache. + +* Backports Range#cover? as an alias for Range#include? in Ruby 1.8. + +* Added +weeks_ago+ and +prev_week+ to Date/DateTime/Time. + +* Added +before_remove_const+ callback to ActiveSupport::Dependencies.remove_unloadable_constants! + +Deprecations: + +* ActiveSupport::SecureRandom is deprecated in favor of +SecureRandom+ from the Ruby standard library. + +h3. Credits + +See the "full list of contributors to Rails":http://contributors.rubyonrails.org/ for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them. + +Rails 3.1 Release Notes were compiled by "Vijay Dev":https://github.com/vijaydev. -- cgit v1.2.3 From f40723996453470c2b00ff49a25282e0f8bbd691 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 31 Jul 2011 03:05:24 +0530 Subject: 3.1 release notes - added AP and Railties sections --- railties/guides/source/3_1_release_notes.textile | 142 +++++++++++++++++++++++ 1 file changed, 142 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index 0348259668..f520e4dfea 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -55,6 +55,8 @@ h3. Rails Architectural Changes h4. Assets Pipeline +TODO. point to assets guide, talk about rake assets:* tasks + h3. Documentation The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released). @@ -65,8 +67,148 @@ h3. Internationalization h3. Railties +* jQuery is the new default JavaScript library. + +* jQuery and prototype are no longer vendored and is provided from now on by the jquery-rails and prototype-rails gems. + +* The application generator accepts an option -j which can be an arbitrary string. If passed "foo", the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest requires "foo" and "foo_ujs". Currently only "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline. + +* Generating an application or a plugin runs bundle install unless --skip-gemfile or --skip-bundle is specified. + +* The controller and resource generators will now automatically produce asset stubs (this can be turned off with --skip-assets). These stubs will use CoffeeScript and Sass, if those libraries are available. + +* Scaffold and app generators use the Ruby 1.9 style hash when running on Ruby 1.9. To generate old style hash, --old-style-hash can be passed. + +* Scaffold controller generator creates format block for JSON instead of XML. + +* Active Record logging is directed to STDOUT and shown inline in the console. + +* Added +config.force_ssl+ configuration which loads Rack::SSL middleware and force all requests to be under HTTPS protocol. + +* Added +rails plugin new+ command which generates a Rails plugin with gemspec, tests and a dummy application for testing. + +* Added Rack::Etag and Rack::ConditionalGet to the default middleware stack. + +* Added Rack::Cache to the default middleware stack. + +* TODO Engine related changes + h3. Action Pack +TODO split items into controller/view sections. + +* A warning is given out if the CSRF token authenticity cannot be verified. + +* Allows AM/PM format in datetime selectors. + +* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink + +* Added streaming support, you can enable it with: + + +class PostsController < ActionController::Base + stream :only => :index +end + + +Please read the docs at ActionController::Streaming for more information. TODO add links to api docs. + +* Added ActionDispatch::Request.ignore_accept_header to ignore accept headers. + +* Created ActionView::Renderer and specified an API for ActionView::Context. + +* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. + +* Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call. + + +class PostsController < ApplicationController + USER_NAME, PASSWORD = "dhh", "secret" + + before_filter :authenticate, :except => [ :index ] + + def index + render :text => "Everyone can see me!" + end + + def edit + render :text => "I'm only accessible if you know the password" + end + + private + def authenticate + authenticate_or_request_with_http_basic do |user_name, password| + user_name == USER_NAME && password == PASSWORD + end + end +end + + +..can now be written as + + +class PostsController < ApplicationController + http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index + + def index + render :text => "Everyone can see me!" + end + + def edit + render :text => "I'm only accessible if you know the password" + end +end + + +* Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, :only or :except can be used. + +* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete }) + +* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper. + +* Sensitive query string parameters specified in config.filter_parameters will now be filtered out from the request paths in the log. + +* URL parameters which return nil for +to_param+ are now removed from the query string. + +* ActionDispatch::MiddlewareStack now uses composition over inheritance and is no longer an array. + +* Added an :authenticity_token option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false. + +* Added HTML5 button_tag helper. + +* Template lookup now searches further up in the inheritance chain. + +* config.action_view.cache_template_loading is brought back which allows to decide whether templates should be cached or not. TODO from which version? + +* url_for and named url helpers now accept :subdomain and :domain as options. + +* The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused. + +* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller). + +* Added a convenience idiom to generate HTML5 data-* attributes in tag helpers from a :data hash of options: + + +tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)}) +# =>
+ + +Keys are dasherized. Values are JSON-encoded, except for strings and symbols. + +* The old template handler API is deprecated and the new API simply requires a template handler to respond to call. + +* rhtml and rxml are finally removed as template handlers. + +* Moved etag responsibility from ActionDispatch::Response to the middleware stack. + +* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy. + +* file_field automatically adds :multipart => true to the enclosing form. + +* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases csrf_meta_tag for backwards compatibility. + +* Added Rack::Cache to the default stack. + h4. Abstract Controller h4. Action Controller -- cgit v1.2.3 From 0e715d0b8ca83fd3053b8a8fa0a5cafbb0cccc79 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sun, 31 Jul 2011 16:56:40 +0530 Subject: Rack::Sendfile is no more default middleware. --- railties/guides/source/command_line.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index b34506d4d8..627e22f2de 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -386,7 +386,7 @@ Action Pack version 3.1.0 Active Resource version 3.1.0 Action Mailer version 3.1.0 Active Support version 3.1.0 -Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, Rack::Sendfile, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head +Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head Application root /home/foobar/commandsapp Environment development -- cgit v1.2.3 From 8015acf0324f83477e18437a192bcafa11101c93 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sun, 31 Jul 2011 21:58:59 +0530 Subject: Adding more info as rake about is fixed --- railties/guides/source/command_line.textile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 627e22f2de..f48fa96451 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -389,6 +389,8 @@ Active Support version 3.1.0 Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head Application root /home/foobar/commandsapp Environment development +Database adapter sqlite3 +Database schema version 0 h4. +assets+ -- cgit v1.2.3 From 8f6959d5a4aa933b31fdb53f2687301dc5da0b47 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 31 Jul 2011 23:23:25 +0530 Subject: 3.1 release notes Active Record changes, Architectural changes and organizing sections. --- railties/guides/source/3_1_release_notes.textile | 189 ++++++++++++++++++++--- 1 file changed, 165 insertions(+), 24 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index f520e4dfea..7d85d7a600 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -55,15 +55,23 @@ h3. Rails Architectural Changes h4. Assets Pipeline -TODO. point to assets guide, talk about rake assets:* tasks +The major change in Rails 3.1 is the Assets Pipeline. It makes CSS and JavaScript first-class code citizens and enables proper organization, including use in plugins and engines. -h3. Documentation +The assets pipeline is powered by "Sprockets":https://github.com/sstephenson/sprockets and is covered in the "Asset Pipeline":asset_pipeline.html guide. -The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released). +h4. HTTP Streaming -More Information: - "Rails Documentation Projects":http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects. +HTTP Streaming is another change that is new in Rails 3.1. This lets the browser download your stylesheets and JavaScript files while the server is still generating the response. This requires Ruby 1.9.2, is opt-in and requires support from the web server as well, but the popular combo of nginx and unicorn is ready to take advantage of it. -h3. Internationalization +h4. Default JS library is now jQuery + +jQuery is the default JavaScript library that ships with Rails 3.1. But if you use Prototype, it's simple to switch. + +h4. Identity Map + +Active Record has an Identity Map in Rails 3.1. An identity map keeps previously instantiated records and returns the object associated with the record if accessed again. The identity map is created on a per-request basis and is flushed at request completion. + +Rails 3.1 comes with the identity map turned off by default. h3. Railties @@ -95,13 +103,9 @@ h3. Railties h3. Action Pack -TODO split items into controller/view sections. - -* A warning is given out if the CSRF token authenticity cannot be verified. - -* Allows AM/PM format in datetime selectors. +h4. Abstract Controller -* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink +h4. Action Controller * Added streaming support, you can enable it with: @@ -111,13 +115,25 @@ class PostsController < ActionController::Base end -Please read the docs at ActionController::Streaming for more information. TODO add links to api docs. +Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information. + +* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. + +h4. Action Dispatch * Added ActionDispatch::Request.ignore_accept_header to ignore accept headers. +h4. Action View + * Created ActionView::Renderer and specified an API for ActionView::Context. -* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. +TODO + +* A warning is given out if the CSRF token authenticity cannot be verified. + +* Allows AM/PM format in datetime selectors. + +* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink * Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call. @@ -209,19 +225,148 @@ Keys are dasherized. Values are JSON-encoded, except for strings and symbols. * Added Rack::Cache to the default stack. -h4. Abstract Controller +h3. Active Record -h4. Action Controller +* Added a class method pluralize_table_names to singularize/pluralize table names of individual models. Previously this could only be set globally for all models through ActiveRecord::Base.pluralize_table_names. + +class User < ActiveRecord::Base + self.pluralize_table_names = false +end + -h4. Action Dispatch +* Added block setting of attributes to singular associations. The block will get called after the instance is initialized. -h4. Action View + +class User < ActiveRecord::Base + has_one :account +end -h3. Active Record +user.build_account{ |a| a.credit_limit => 100.0 } + -h3. Active Model +* Added ActiveRecord::Base.attribute_names to return a list of attribute names. This will return an empty array if the model is abstract or the table does not exist. + +* CSV Fixtures are deprecated and support will be removed in Rails 3.2.0 + +* ActiveRecord#new, ActiveRecord#create and ActiveRecord#update_attributes all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of ActiveModel's new mass assignment capabilities: + + +class Post < ActiveRecord::Base + attr_accessible :title + attr_accessible :title, :published_at, :as => :admin +end + +Post.new(params[:post], :as => :admin) + + +* default_scope can now take a block, lambda, or any other object which responds to call for lazy evaluation: + +* Default scopes are now evaluated at the latest possible moment, to avoid problems where scopes would be created which would implicitly contain the default scope, which would then be impossible to get rid of via Model.unscoped. + +* PostgreSQL adapter only supports PostgreSQL version 8.2 and higher. + +* ConnectionManagement middleware is changed to clean up the connection pool after the rack body has been flushed. + +* Added an update_column method on ActiveRecord. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use #update_attribute unless you are sure you do not want to execute any callback, including the modification of the updated_at column. It should not be called on new records. + +* Associations with a :through option can now use any association as the through or source association, including other associations which have a :through option and has_and_belongs_to_many associations. + +* The configuration for the current database connection is now accessible via ActiveRecord::Base.connection_config. -The major changes in Active Model are: +* limits and offsets are removed from COUNT queries unless both are supplied. + +People.limit(1).count # => 'SELECT COUNT(*) FROM people' +People.offset(1).count # => 'SELECT COUNT(*) FROM people' +People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET 1' + + +* ActiveRecord::Associations::AssociationProxy has been split. There is now an +Association+ class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper +called+ CollectionProxy, which proxies collection associations. This prevents namespace pollution, separates concerns, and will allow further refactorings. + +* Singular associations (has_one, belongs_to) no longer have a proxy and simply returns the associated record or nil. This means that you should not use undocumented methods such as bob.mother.create - use bob.create_mother instead. + +* Support the :dependent option on has_many :through associations. For historical and practical reasons, :delete_all is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is :nullify for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association. + +* The behavior of association.destroy for has_and_belongs_to_many and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'. + +* Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It would not delete any records in the join table. Now, it deletes the records in the join table. + +* Previously, has_many_through.destroy(*records) would destroy the records themselves, and the records in the join table. [Note: This has not always been the case; previous version of Rails only deleted the records themselves.] Now, it destroys only the records in the join table. + +* Note that this change is backwards-incompatible to an extent, but there is unfortunately no way to 'deprecate' it before changing it. The change is being made in order to have consistency as to the meaning of 'destroy' or 'delete' across the different types of associations. If you wish to destroy the records themselves, you can do records.association.each(&:destroy) + +* Add :bulk => true option to +change_table+ to make all the schema changes defined in a block using a single ALTER statement. + + +change_table(:users, :bulk => true) do |t| + t.string :company_name + t.change :birthdate, :datetime +end + + +* Removed support for accessing attributes on a +has_and_belongs_to_many+ join table. has_many :through needs to be used. + +* Added a +create_association!+ method for +has_one+ and +belongs_to+ associations. + +* Migrations are now reversible, meaning that Rails will figure out how to reverse your migrations. To use reversible migrations, just define the +change+ method. + +class MyMigration < ActiveRecord::Migration + def change + create_table(:horses) do + t.column :content, :text + t.column :remind_at, :datetime + end + end +end + + +* Some things cannot be automatically reversed for you. If you know how to reverse those things, you should define 'up' and 'down' in your migration. If you define something in change that cannot be reversed, an +IrreversibleMigration+ exception will be raised when going down. + +* Migrations now use instance methods rather than class methods: + +class FooMigration < ActiveRecord::Migration + def up # Not self.up + ... + end +end + + +* Migration files generated from model and constructive migration generators (for example, add_name_to_users) use the reversible migration's change method instead of the ordinary up and down methods. + +* Removed support for interpolating string SQL conditions on associations. Instead, a proc should be used. + + +has_many :things, :conditions => 'foo = #{bar}' # before +has_many :things, :conditions => proc { "foo = #{bar}" } # after + + +Inside the proc, 'self' is the object which is the owner of the association, unless you are eager loading the association, in which case 'self' is the class which the association is within. + +You can have any "normal" conditions inside the proc, so the following will work too: + +has_many :things, :conditions => proc { ["foo = ?", bar] } + + +* Previously :insert_sql and :delete_sql on has_and_belongs_to_many association allowed you to call 'record' to get the record being inserted or deleted. This is now passed as an argument to the proc. + +* Added ActiveRecord::Base#has_secure_password (via ActiveModel::SecurePassword) to encapsulate dead-simple password usage with BCrypt encryption and salting. + +# Schema: User(name:string, password_digest:string, password_salt:string) +class User < ActiveRecord::Base + has_secure_password +end + + +* When a model is generated +add_index+ is added by default for +belongs_to+ or +references+ columns. + +* Setting the id of a belongs_to object will update the reference to the object. + +* ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed to closer match normal Ruby dup and clone semantics. + +* Calling ActiveRecord::Base#clone will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called. + +* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable. + +h3. Active Model * +attr_accessible+ accepts an option +:as+ to specify a role. @@ -233,8 +378,6 @@ The major changes in Active Model are: h3. Active Resource -The changes in Active Resource are: - * The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. For example, @@ -245,8 +388,6 @@ end h3. Active Support -The main changes in Active Support are: - * ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant. * Added a new reporting method Kernel#quietly which silences both STDOUT and STDERR. -- cgit v1.2.3 From 61899bff17e161dbd706bfb900ac212fe90c3acd Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Mon, 1 Aug 2011 20:37:42 +0530 Subject: Active Resource - guide for reading and writing data --- railties/guides/source/active_resource_basics.textile | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 64f0949475..8a36622814 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -24,10 +24,21 @@ end Now the Person class is REST enabled and can invoke REST services very similarly to how Active Record invokes life cycle methods that operate against a persistent store. +h3. Reading and Writing Data + +Active Resource make request over HTTP using a standard JSON format. It mirrors the RESTful routing built into Action Controller but will also work with any other REST service that properly implements the protocol. + +h4. Read + +Read requests use the GET method and expect the JSON form of whatever resource/resources is/are being requested. + # Find a person with id = 1 ryan = Person.find(1) +# Check if a person exists with id = 1 Person.exists?(1) # => true +# Get all resources of Person class +Person.all h3. Changelog -- cgit v1.2.3 From aa9da1fe70a109f86922b4ee83039f1cae1e6584 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Mon, 1 Aug 2011 20:48:45 +0530 Subject: Active Resource - guide for create --- railties/guides/source/active_resource_basics.textile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 8a36622814..e40ca4fc42 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -34,13 +34,22 @@ Read requests use the GET method and expect the JSON form of whatever resource/r # Find a person with id = 1 -ryan = Person.find(1) +person = Person.find(1) # Check if a person exists with id = 1 Person.exists?(1) # => true # Get all resources of Person class Person.all +h4. Create + +Creating a new resource submits the JSON form of the resource as the body of the request with HTTP POST method and parse the response into Active Resource object. + + +person = Person.create(:name => 'Vishnu') +person.id # => 1 + + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file -- cgit v1.2.3 From 212654be02e28ee97d75819b0f799ccb6f7b9130 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Mon, 1 Aug 2011 20:57:57 +0530 Subject: Active Resource - guide for update/save --- railties/guides/source/active_resource_basics.textile | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index e40ca4fc42..1115b9848f 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -50,6 +50,16 @@ person = Person.create(:name => 'Vishnu') person.id # => 1 +h4. Update + +To update an existing resource, 'save' method is used. This method make a HTTP PUT request in JSON format. + + +person = Person.find(1) +person.name = 'Atrai' +person.save + + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file -- cgit v1.2.3 From 1ea8d9c38d280e6f55ac3ad1ad4d27d48dcddc15 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Mon, 1 Aug 2011 21:02:48 +0530 Subject: Active Resource - guide for destroy --- railties/guides/source/active_resource_basics.textile | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 1115b9848f..332d113fa7 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -60,6 +60,15 @@ person.name = 'Atrai' person.save +h4. Delete + +'destroy' method makes a HTTP DELETE request for an existing resource in JSON format to delete that resource. + + +person = Person.find(1) +person.destroy + + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file -- cgit v1.2.3 From ff0b1a3cc65ca8b2af02e62f940aaeffad606b16 Mon Sep 17 00:00:00 2001 From: pbflinn Date: Mon, 1 Aug 2011 12:53:43 -0300 Subject: Fix typo 'console' -> 'constant' --- railties/guides/source/initialization.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 477ee5a3a2..9b92edd250 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -71,7 +71,7 @@ module Rails end -The +rails/script_rails_loader+ file uses +RbConfig::Config+ to gather up the +bin_dir+ and +ruby_install_name+ values for the configuration which will result in a path such as +/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby+, which is the default path on Mac OS X. If you're running Windows the path may be something such as +C:/Ruby192/bin/ruby+. Anyway, the path on your system may be different, but the point of this is that it will point at the known ruby executable location for your install. The +RbConfig::CONFIG["EXEEXT"]+ will suffix this path with ".exe" if the script is running on Windows. This constant is used later on in +exec_script_rails!+. As for the +SCRIPT_RAILS+ console, we'll see that when we get to the +in_rails_application?+ method. +The +rails/script_rails_loader+ file uses +RbConfig::Config+ to gather up the +bin_dir+ and +ruby_install_name+ values for the configuration which will result in a path such as +/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby+, which is the default path on Mac OS X. If you're running Windows the path may be something such as +C:/Ruby192/bin/ruby+. Anyway, the path on your system may be different, but the point of this is that it will point at the known ruby executable location for your install. The +RbConfig::CONFIG["EXEEXT"]+ will suffix this path with ".exe" if the script is running on Windows. This constant is used later on in +exec_script_rails!+. As for the +SCRIPT_RAILS+ constant, we'll see that when we get to the +in_rails_application?+ method. Back in +rails/cli+, the next line is this: -- cgit v1.2.3 From 5adb90a14f3fc3441a53476dd75217d1ecb8de97 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 3 Aug 2011 19:11:22 +0530 Subject: fixed incorrect tags --- railties/guides/source/migrations.textile | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index e51ee0f535..7b501807d6 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -477,7 +477,7 @@ Several methods are provided that allow you to control all this: For example, this migration -
+
 class CreateProducts < ActiveRecord::Migration
   def change
     suppress_messages do
@@ -496,7 +496,7 @@ class CreateProducts < ActiveRecord::Migration
     end
   end
 end
-
+ generates the following output @@ -525,7 +525,7 @@ Bob goes on vacation. Alice creates a migration for the +products+ table which adds a new column and initializes it. She also adds a validation to the Product model for the new column. -
+
 # db/migrate/20100513121110_add_flag_to_product.rb
 
 class AddFlagToProduct < ActiveRecord::Migration
@@ -534,19 +534,19 @@ class AddFlagToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes!(:flag => 'false') }
   end
 end
-
+ -
+
 # app/model/product.rb
 
 class Product < ActiveRecord::Base
   validates_presence_of :flag
 end
-
+ Alice adds a second migration which adds and initializes another column to the +products+ table and also adds a validation to the Product model for the new column. -
+
 # db/migrate/20100515121110_add_fuzz_to_product.rb
 
 class AddFuzzToProduct < ActiveRecord::Migration
@@ -555,16 +555,16 @@ class AddFuzzToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes! :fuzz => 'fuzzy' }
   end
 end
-
+ -
+
 # app/model/product.rb
 
 class Product < ActiveRecord::Base
   validates_presence_of :flag
   validates_presence_of :fuzz
 end
-
+ Both migrations work for Alice. @@ -575,12 +575,12 @@ Bob comes back from vacation and: The migration crashes because when the model attempts to save, it tries to validate the second added column, which is not in the database when the _first_ migration runs. -
+
 rake aborted!
 An error has occurred, this and all later migrations canceled:
 
 undefined method `fuzz' for #
-
+ A fix for this is to create a local model within the migration. This keeps rails from running the validations, so that the migrations run to completion. @@ -588,7 +588,7 @@ When using a faux model, it's a good idea to call +Product.reset_column_informat If Alice had done this instead, there would have been no problem: -
+
 # db/migrate/20100513121110_add_flag_to_product.rb
 
 class AddFlagToProduct < ActiveRecord::Migration
@@ -600,9 +600,9 @@ class AddFlagToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes!(:flag => false) }
   end
 end
-
+ -
+
 # db/migrate/20100515121110_add_fuzz_to_product.rb
 
 class AddFuzzToProduct < ActiveRecord::Migration
@@ -614,7 +614,7 @@ class AddFuzzToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes! :fuzz => 'fuzzy' }
   end
 end
-
+ h3. Schema Dumping and You -- cgit v1.2.3 From 688b0c318f411a65bb2e27614dd9fe004427a344 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 3 Aug 2011 19:13:12 +0530 Subject: minor changes in migrations guide --- railties/guides/source/migrations.textile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index 7b501807d6..4476e067a6 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -540,7 +540,7 @@ end # app/model/product.rb class Product < ActiveRecord::Base - validates_presence_of :flag + validates :flag, :presence => true end @@ -561,8 +561,7 @@ end # app/model/product.rb class Product < ActiveRecord::Base - validates_presence_of :flag - validates_presence_of :fuzz + validates :flag, :fuzz, :presence => true end @@ -594,9 +593,10 @@ If Alice had done this instead, there would have been no problem: class AddFlagToProduct < ActiveRecord::Migration class Product < ActiveRecord::Base end + def change add_column :products, :flag, :int - Product.reset_column_information + Product.reset_column_information Product.all.each { |f| f.update_attributes!(:flag => false) } end end -- cgit v1.2.3 From e4d8a95443bbb86cb9a446397469229e85f21867 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 3 Aug 2011 19:34:23 +0530 Subject: typo fix --- railties/guides/source/initialization.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 9b92edd250..6ab2706d6b 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -33,7 +33,7 @@ end This file will attempt to load +rails/cli+ and if it cannot find it then add the +railties/lib+ path to the load path (+$:+) and will then try to require it again. -h4. +railites/lib/rails/cli.rb+ +h4. +railties/lib/rails/cli.rb+ This file looks like this: -- cgit v1.2.3 From fbd3e38d76e68ea49b5360a174e1a48f3079101e Mon Sep 17 00:00:00 2001 From: JudeArasu Date: Wed, 3 Aug 2011 23:00:24 +0530 Subject: grammatical changes --- railties/guides/source/form_helpers.textile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index bf2a7369a7..fa0ca5827a 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -45,7 +45,7 @@ NOTE: Throughout this guide, the +div+ with the hidden input elements will be ex h4. A Generic Search Form -One of the most basic forms you see on the web is a search form. This form contains: +One of the most basic forms you will see on the web is a search form. This form contains: # a form element with "GET" method, # a label for the input, @@ -807,3 +807,4 @@ h3. Authors * Mislav Marohnić * "Frederick Cheung":credits.html#fcheung + -- cgit v1.2.3 From 19122e767ca199f6b2b3e8f21d2634eb2f17a8b4 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 4 Aug 2011 15:02:13 -0700 Subject: Revert "grammatical changes" Reason: As discussed in GitHub, it is debatable, and present tense is fine (and simple, and preferred). This reverts commit 54ccda9f0a5e4a5e72a4c159dc8787faaf65e8a2. --- railties/guides/source/form_helpers.textile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index fa0ca5827a..bf2a7369a7 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -45,7 +45,7 @@ NOTE: Throughout this guide, the +div+ with the hidden input elements will be ex h4. A Generic Search Form -One of the most basic forms you will see on the web is a search form. This form contains: +One of the most basic forms you see on the web is a search form. This form contains: # a form element with "GET" method, # a label for the input, @@ -807,4 +807,3 @@ h3. Authors * Mislav Marohnić * "Frederick Cheung":credits.html#fcheung - -- cgit v1.2.3 From 19ac034bdc9be175eff7cf54208ba14b43d97681 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 25 Jul 2011 18:54:25 -0300 Subject: Don't use Rack::Sendfile middleware if x_sendfile_header is not present --- railties/lib/rails/application.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 9e2f1a4b7a..fb60ddd9b5 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -163,7 +163,9 @@ module Rails middleware.use ::Rails::Rack::Logger # must come after Rack::MethodOverride to properly log overridden methods middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies - middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header + if config.action_dispatch.x_sendfile_header.present? + middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header + end middleware.use ::ActionDispatch::Reloader unless config.cache_classes middleware.use ::ActionDispatch::Callbacks middleware.use ::ActionDispatch::Cookies -- cgit v1.2.3 From 6d4f91621871a23576ec6f343f08fd68dda95e0c Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Mon, 25 Jul 2011 14:13:26 -0700 Subject: Add documentation for :format => true --- railties/guides/source/routing.textile | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 68fb22f5d8..99dd9a1cd2 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -569,6 +569,12 @@ NOTE: By requesting +"/foo/bar.json"+, your +params[:pages]+ will be equals to + match '*pages' => 'pages#show', :format => false +NOTE: If you want to make the format segment mandatory, so it cannot be omitted, you can supply +:format => true+ like this: + + +match '*pages' => 'pages#show', :format => true + + h4. Redirection You can redirect any path to another path using the +redirect+ helper in your router: -- cgit v1.2.3 From 34ca9c122c26dc3e073e52ecdf267cb23885c1df Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 26 Jul 2011 00:18:56 -0300 Subject: Check that Rack::Sendfile is not included unless config.action_dispatch.x_sendfile_header is set --- railties/test/application/middleware_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'railties') diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 6a0a272073..bed5ba503f 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -20,6 +20,8 @@ module ApplicationTests end test "default middleware stack" do + add_to_config "config.action_dispatch.x_sendfile_header = 'X-Sendfile'" + boot! assert_equal [ @@ -47,6 +49,12 @@ module ApplicationTests ], middleware end + test "Rack::Sendfile is not included by default" do + boot! + + assert !middleware.include?("Rack::Sendfile"), "Rack::Sendfile is not included in the default stack unless you set config.action_dispatch.x_sendfile_header" + end + test "Rack::Cache is present when action_controller.perform_caching is set" do add_to_config "config.action_controller.perform_caching = true" -- cgit v1.2.3 From b82e226b7fb2e4dd443a4016f586ce06516d3d85 Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Tue, 26 Jul 2011 17:25:32 -0400 Subject: Expanded meta-data in gemspec to include author, email, etc.; Defaults include "TODO" to prevent gems from being built without review. --- .../generators/rails/plugin_new/templates/%name%.gemspec | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec index eb1a1e5054..b469edd772 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec @@ -1,12 +1,16 @@ # Provide a simple gemspec so you can easily use your # project in your rails apps through git. Gem::Specification.new do |s| - s.name = "<%= name %>" - s.summary = "Insert <%= camelized %> summary." - s.description = "Insert <%= camelized %> description." + s.name = "<%= name %>" + s.version = "0.0.1" + s.authors = ["TODO: Your name"] + s.email = ["TODO: Your email"] + s.homepage = "TODO" + s.summary = "TODO: Summary of <%= camelized %>." + s.description = "TODO: Description of <%= camelized %>." + s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"] <% unless options.skip_test_unit? -%> s.test_files = Dir["test/**/*"] <% end -%> - s.version = "0.0.1" end -- cgit v1.2.3 From f9eadb8b432f220865c5205a81e6dd5af90f35b5 Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Tue, 26 Jul 2011 18:51:44 -0400 Subject: Extracted version from gemspec and placed it in its own file. This is consistent with the approach taken by "bundle gem", and is expected by gems such as svenfuchs/gem-release which can be used to bump / tag versions of gems. --- .../rails/generators/rails/plugin_new/plugin_new_generator.rb | 1 + .../rails/generators/rails/plugin_new/templates/%name%.gemspec | 10 +++++++--- .../rails/plugin_new/templates/lib/%name%/version.rb | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 7c0a2b9cf4..56b1587760 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -46,6 +46,7 @@ module Rails def lib template "lib/%name%.rb" template "lib/tasks/%name%_tasks.rake" + template "lib/%name%/version.rb" if full? template "lib/%name%/engine.rb" end diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec index b469edd772..736d114901 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec @@ -1,8 +1,12 @@ -# Provide a simple gemspec so you can easily use your -# project in your rails apps through git. +$:.push File.expand_path("../lib", __FILE__) + +# Maintain your gem's version: +require "<%= name %>/version" + +# Describe your gem and declare its dependencies: Gem::Specification.new do |s| s.name = "<%= name %>" - s.version = "0.0.1" + s.version = <%= camelized %>::VERSION s.authors = ["TODO: Your name"] s.email = ["TODO: Your email"] s.homepage = "TODO" diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb b/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb new file mode 100644 index 0000000000..ef07ef2e19 --- /dev/null +++ b/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb @@ -0,0 +1,3 @@ +module <%= camelized %> + VERSION = "0.0.1" +end -- cgit v1.2.3 From 47cc214600b9f099140a1df34bc68432ad1d2b23 Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Tue, 26 Jul 2011 21:54:45 -0400 Subject: Moved dependencies from Gemfile to gemspec to eliminate redundant declarations. --- .../rails/plugin_new/templates/%name%.gemspec | 11 +++++++++++ .../generators/rails/plugin_new/templates/Gemfile | 20 +++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec index 736d114901..b8d68ad0bc 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec @@ -17,4 +17,15 @@ Gem::Specification.new do |s| <% unless options.skip_test_unit? -%> s.test_files = Dir["test/**/*"] <% end -%> + + # If your gem is dependent on a specific version (or higher) of Rails: + <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", ">= <%= Rails::VERSION::STRING %>" + +<% unless options[:skip_javascript] || !full? -%> + # If your gem contains any <%= "#{options[:javascript]}-specific" %> javascript: + # s.add_dependency "<%= "#{options[:javascript]}-rails" %>" + +<% end -%> + # Declare development-specific dependencies: + s.add_development_dependency "<%= gem_for_database %>" end diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile index 7e6eb18341..160baa6906 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile +++ b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile @@ -1,14 +1,20 @@ source "http://rubygems.org" -<%= rails_gemfile_entry -%> +# Declare your gem's dependencies in <%= name %>.gemspec. +# Bundler will treat runtime dependencies like base dependencies, and +# development dependencies will be added by default to the :development group. +gemspec -<% if full? -%> -<%= database_gemfile_entry -%> -<% end -%> +# Declare any dependencies that are still in development here instead of in +# your gemspec. These might include edge Rails or gems from your path or +# Git. Remember to move these dependencies to your gemspec before releasing +# your gem to rubygems.org. -<% if mountable? -%> -<%= javascript_gemfile_entry -%> -<% end -%> +<% if options.dev? || options.edge? -%> +# Your gem is dependent on dev or edge Rails. Once you can lock this +# dependency down to a specific version, move it to your gemspec. +<%= rails_gemfile_entry -%> +<% end -%> # To use debugger # <%= ruby_debugger_gemfile_entry %> \ No newline at end of file -- cgit v1.2.3 From 60f593dc548e5a62cd1a6de7512eaf344beff788 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 28 Jul 2011 11:48:21 -0300 Subject: Tidy up a bit plugin new gemspec --- .../rails/generators/rails/plugin_new/templates/%name%.gemspec | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec index b8d68ad0bc..8588e88077 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec @@ -18,14 +18,10 @@ Gem::Specification.new do |s| s.test_files = Dir["test/**/*"] <% end -%> - # If your gem is dependent on a specific version (or higher) of Rails: - <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", ">= <%= Rails::VERSION::STRING %>" - -<% unless options[:skip_javascript] || !full? -%> - # If your gem contains any <%= "#{options[:javascript]}-specific" %> javascript: + <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", "~> <%= Rails::VERSION::STRING %>" +<% if full? && !options[:skip_javascript] -%> # s.add_dependency "<%= "#{options[:javascript]}-rails" %>" - <% end -%> - # Declare development-specific dependencies: + s.add_development_dependency "<%= gem_for_database %>" end -- cgit v1.2.3 From b50dfce6018bb5d380a6faa18d93cec41cf458ca Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Thu, 28 Jul 2011 21:14:29 +0530 Subject: pluging generator test fix --- railties/test/generators/plugin_new_generator_test.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'railties') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 0ccb2ae9da..e6ea1cbc33 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -69,13 +69,13 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_database_entry_is_generated_for_sqlite3_by_default_in_full_mode run_generator([destination_root, "--full"]) assert_file "test/dummy/config/database.yml", /sqlite/ - assert_file "Gemfile", /^gem\s+["']sqlite3["']$/ + assert_file "bukkits.gemspec", /sqlite3/ end def test_config_another_database run_generator([destination_root, "-d", "mysql", "--full"]) assert_file "test/dummy/config/database.yml", /mysql/ - assert_file "Gemfile", /^gem\s+["']mysql2["']$/ + assert_file "bukkits.gemspec", /mysql/ end def test_active_record_is_removed_from_frameworks_if_skip_active_record_is_given @@ -117,8 +117,8 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_match %r{^//= require jquery}, contents assert_match %r{^//= require jquery_ujs}, contents end - assert_file 'Gemfile' do |contents| - assert_match(/^gem 'jquery-rails'/, contents) + assert_file 'bukkits.gemspec' do |contents| + assert_match(/jquery-rails/, contents) end end @@ -128,8 +128,8 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_match %r{^//= require prototype}, contents assert_match %r{^//= require prototype_ujs}, contents end - assert_file 'Gemfile' do |contents| - assert_match(/^gem 'prototype-rails'/, contents) + assert_file 'bukkits.gemspec' do |contents| + assert_match(/prototype-rails/, contents) end end @@ -205,10 +205,10 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_creating_gemspec run_generator - assert_file "bukkits.gemspec", /s.name = "bukkits"/ + assert_file "bukkits.gemspec", /s.name\s+= "bukkits"/ assert_file "bukkits.gemspec", /s.files = Dir\["\{app,config,db,lib\}\/\*\*\/\*"\]/ assert_file "bukkits.gemspec", /s.test_files = Dir\["test\/\*\*\/\*"\]/ - assert_file "bukkits.gemspec", /s.version = "0.0.1"/ + assert_file "bukkits.gemspec", /s.version\s+ = Bukkits::VERSION/ end def test_usage_of_engine_commands -- cgit v1.2.3 From 651a9c93be23651bf33b53813f1124aa69ae53de Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 28 Jul 2011 16:46:39 -0300 Subject: Tidy up --- railties/lib/rails/generators/app_base.rb | 6 ++++-- railties/lib/rails/generators/rails/app/templates/Gemfile | 3 --- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index bbdd000ad9..21a2ae4e28 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -200,9 +200,11 @@ module Rails def assets_gemfile_entry <<-GEMFILE.strip_heredoc + # Gems used only for assets and not required + # in production environments by default. group :assets do - gem 'sass-rails', :git => 'git://github.com/rails/sass-rails' - gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails' + gem 'sass-rails', :git => 'git://github.com/rails/sass-rails.git' + gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails.git' gem 'uglifier' end GEMFILE diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 88eea40b1b..c83e7ddf80 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -7,10 +7,7 @@ source 'http://rubygems.org' <%= "gem 'jruby-openssl'\n" if defined?(JRUBY_VERSION) -%> <%= "gem 'json'\n" if RUBY_VERSION < "1.9.2" -%> -# Gems used only for assets and not required -# in production environments by default. <%= assets_gemfile_entry %> - <%= javascript_gemfile_entry %> # Use unicorn as the web server -- cgit v1.2.3 From bfde0636dd1b1252436ea3c42ddae2eecd2e554b Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Tue, 26 Jul 2011 15:41:08 -0400 Subject: Include empty app/mailers directory in mountable and full plugins --- railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb | 1 + .../generators/rails/plugin_new/templates/app/mailers/.empty_directory | 0 2 files changed, 1 insertion(+) create mode 100644 railties/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 56b1587760..c46422437d 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -19,6 +19,7 @@ module Rails empty_directory_with_gitkeep "app/controllers" empty_directory_with_gitkeep "app/views" empty_directory_with_gitkeep "app/helpers" + empty_directory_with_gitkeep "app/mailers" empty_directory_with_gitkeep "app/assets/images/#{name}" end end diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory b/railties/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory new file mode 100644 index 0000000000..e69de29bb2 -- cgit v1.2.3 From 1deb0253aee8ea96eaa118dba7cf8eaa42dcbeba Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Fri, 29 Jul 2011 22:06:36 +0530 Subject: Test add for plugin new generator generate mailer --- railties/test/generators/plugin_new_generator_test.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index e6ea1cbc33..19e80eee89 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -25,10 +25,6 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase # brings setup, teardown, and some tests include SharedGeneratorTests - def default_files - ::DEFAULT_PLUGIN_FILES - end - def test_invalid_plugin_name_raises_an_error content = capture(:stderr){ run_generator [File.join(destination_root, "43-things")] } assert_equal "Invalid plugin name 43-things. Please give a name which does not start with numbers.\n", content @@ -176,6 +172,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "app/controllers" assert_file "app/views" assert_file "app/helpers" + assert_file "app/mailers" assert_file "config/routes.rb", /Rails.application.routes.draw do/ assert_file "lib/bukkits/engine.rb", /module Bukkits\n class Engine < ::Rails::Engine\n end\nend/ assert_file "lib/bukkits.rb", /require "bukkits\/engine"/ @@ -257,6 +254,10 @@ protected silence(:stdout){ generator.send(*args, &block) } end +protected + def default_files + ::DEFAULT_PLUGIN_FILES + end end class CustomPluginGeneratorTest < Rails::Generators::TestCase -- cgit v1.2.3 From 67d76f43a047a24c3bfcdde7a81257e5cdfa65be Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 29 Jul 2011 23:05:40 +0530 Subject: Covering more files in test for plugin new generator. --- railties/test/generators/plugin_new_generator_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 19e80eee89..b49945f153 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -7,11 +7,13 @@ DEFAULT_PLUGIN_FILES = %w( .gitignore Gemfile Rakefile + README.rdoc bukkits.gemspec MIT-LICENSE lib lib/bukkits.rb lib/tasks/bukkits_tasks.rake + lib/bukkits/version.rb test/bukkits_test.rb test/test_helper.rb test/dummy -- cgit v1.2.3 From 076afd0e22caaa307f5fddeca8a5749586654852 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 31 Jul 2011 21:39:10 +0530 Subject: fixes #2368. rake about not showing the middleware, db adapter and db schema version --- railties/lib/rails/tasks/misc.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/tasks/misc.rake b/railties/lib/rails/tasks/misc.rake index 833fcb6f72..8b4775d1d3 100644 --- a/railties/lib/rails/tasks/misc.rake +++ b/railties/lib/rails/tasks/misc.rake @@ -14,7 +14,7 @@ task :secret do end desc 'List versions of all Rails frameworks and the environment' -task :about do +task :about => :environment do puts Rails::Info end -- cgit v1.2.3 From f86f7702507f477eb8f0a8e914bdb53219fac953 Mon Sep 17 00:00:00 2001 From: Bogdan Gusiev Date: Thu, 28 Jul 2011 11:56:08 +0300 Subject: MassAssignmentProtection: consider 'id' insensetive in StrictSanitizer In order to use StrictSanitizer in test mode Consider :id as not sensetive attribute that can be filtered from mass assignement without exception. --- .../generators/rails/app/templates/config/environments/test.rb.tt | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index ee068b0202..80198cc21e 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -34,6 +34,11 @@ # like if you have constraints or database-specific column types # config.active_record.schema_format = :sql + <%- unless options.skip_active_record? -%> + # Raise exception on mass assignment protection for ActiveRecord models + config.active_record.mass_assignment_sanitizer = :strict + <%- end -%> + # Print deprecation notices to the stderr config.active_support.deprecation = :stderr end -- cgit v1.2.3 From f9a69e8744546602b567dc5787f7d8ee23073bec Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 1 Aug 2011 12:32:17 -0700 Subject: Merge pull request #2324 from zenapsis/3-1-stable Rails 3.1 throws a Errno::ENOTDIR if files are put in assets directories --- railties/lib/rails/engine.rb | 6 +++--- railties/lib/rails/paths.rb | 4 ++++ railties/test/application/assets_test.rb | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index c41f7d7c2e..2c3f61f404 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -542,9 +542,9 @@ module Rails end initializer :append_assets_path do |app| - app.config.assets.paths.unshift(*paths["vendor/assets"].existent) - app.config.assets.paths.unshift(*paths["lib/assets"].existent) - app.config.assets.paths.unshift(*paths["app/assets"].existent) + app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories) + app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories) + app.config.assets.paths.unshift(*paths["app/assets"].existent_directories) end initializer :prepend_helpers_path do |app| diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index de3d0b6fc5..55b820b12e 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -171,6 +171,10 @@ module Rails def existent expanded.select { |f| File.exists?(f) } end + + def existent_directories + expanded.select {|d| Dir.exists?(d) } + end alias to_a expanded end diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 7fb930bd99..802b737483 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -109,5 +109,19 @@ module ApplicationTests assert_match "alert()", last_response.body assert_equal nil, last_response.headers["Set-Cookie"] end + + test "files in any assets/ directories are not added to Sprockets" do + %w[app lib vendor].each do |dir| + app_file "#{dir}/assets/#{dir}_test.erb", "testing" + end + + app_file "app/assets/javascripts/demo.js", "alert();" + + require "#{app_path}/config/environment" + + get "/assets/demo.js" + assert_match "alert();", last_response.body + assert_equal 200, last_response.status + end end end -- cgit v1.2.3 From 8293b10425bfe621b4bed85bf3db57cccd70e43b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 1 Aug 2011 17:29:03 -0700 Subject: use File.directory? as Dir.exists? is only 1.9.2+ --- railties/lib/rails/paths.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index 55b820b12e..b37421c09c 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -171,9 +171,9 @@ module Rails def existent expanded.select { |f| File.exists?(f) } end - + def existent_directories - expanded.select {|d| Dir.exists?(d) } + expanded.select { |d| File.directory?(d) } end alias to_a expanded -- cgit v1.2.3 From ab6b61e34c046da944d9b517876a032fe3d0a8a1 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 3 Aug 2011 19:18:34 -0300 Subject: Don't require assets group in production by default, you can change this default in the application.rb anyways --- .../rails/generators/rails/app/templates/config/application.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index 7687b1beac..dd0cf64650 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -13,9 +13,13 @@ require "active_resource/railtie" <% end -%> # If you have a Gemfile, require the default gems, the ones in the -# current environment and also include :assets gems if in development -# or test environments. -Bundler.require *Rails.groups(:assets) if defined?(Bundler) +# current environment and also include :assets gems if you ... +if defined?(Bundler) + # ... precompile your assets + Bundler.require *Rails.groups(:assets => %w(development test)) + # ... want your assets to be lazily compiled also in production + # Bundler.require(:default, :assets, Rails.env) +end module <%= app_const_base %> class Application < Rails::Application -- cgit v1.2.3 From f2ea1ddc278d5466f3d3b7c8feb73aa9c78d2628 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 3 Aug 2011 21:04:32 -0300 Subject: Fix a bit precompile and lazy compile comments --- .../lib/rails/generators/rails/app/templates/config/application.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index dd0cf64650..86c9bd2d1d 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -12,12 +12,10 @@ require "active_resource/railtie" <%= comment_if :skip_test_unit %>require "rails/test_unit/railtie" <% end -%> -# If you have a Gemfile, require the default gems, the ones in the -# current environment and also include :assets gems if you ... if defined?(Bundler) - # ... precompile your assets + # If you precompile assets before deploying to production, use this line Bundler.require *Rails.groups(:assets => %w(development test)) - # ... want your assets to be lazily compiled also in production + # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end -- cgit v1.2.3 From ac287b2aa04c8376bf7d1f95c99047796442406e Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Fri, 5 Aug 2011 12:16:53 +0530 Subject: Adding Basic file for ActiveModel. @vatrai and @sukeerthiadiga is going to take care other detailed stuff. --- railties/guides/source/active_model_basics.textile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 railties/guides/source/active_model_basics.textile (limited to 'railties') diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile new file mode 100644 index 0000000000..5e41d39447 --- /dev/null +++ b/railties/guides/source/active_model_basics.textile @@ -0,0 +1,16 @@ +h2. Active Model Basics + +This guide should provide you with all you need to get started using model classes. Active Model allow for Action Pack helpers to interact with non-ActiveRecord models. Active Model also helps building custom ORMs for use outside of the Rails framework. + +endprologue. + +WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails. + +h3. Introduction + +Active Model is a library containing various modules used in developing frameworks that need to interact with the Rails Action Pack library. Active Model provides a known set of interfaces for usage in classes. + + +h3. Changelog + +* August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw \ No newline at end of file -- cgit v1.2.3 From 4bde1b0041d73accf75525697461ac6b9fad5404 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 5 Aug 2011 13:13:22 +0530 Subject: ActiveModel::AttributeMethods basic guide --- railties/guides/source/active_model_basics.textile | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index 5e41d39447..c76469f62c 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -8,8 +8,33 @@ WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not h3. Introduction -Active Model is a library containing various modules used in developing frameworks that need to interact with the Rails Action Pack library. Active Model provides a known set of interfaces for usage in classes. +Active Model is a library containing various modules used in developing frameworks that need to interact with the Rails Action Pack library. Active Model provides a known set of interfaces for usage in classes. Some of modules are explained below - +h4. AttributeMethods + +AttributeMethods module can add custom prefixes and suffixes on methods of a class. It is used by defining the prefixes and suffixes, which methods on the object will use them. + + +class Person + include ActiveModel::AttributeMethods + + attribute_method_prefix 'reset_' + attribute_method_suffix '_highest?' + define_attribute_methods ['age'] + + attr_accessor :age + +private + def reset_attribute(attribute) + send("#{attribute}=", 0) + end + + def attribute_highest?(attribute) + attribute > 100 ? true : false + end + +end + h3. Changelog -- cgit v1.2.3 From 7963099b904031fef7d593d5be7e2061d1bcbfe8 Mon Sep 17 00:00:00 2001 From: Sukeerthi Adiga G Date: Fri, 5 Aug 2011 13:13:31 +0530 Subject: ActiveResource::Validations module basics updated --- .../guides/source/active_resource_basics.textile | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 332d113fa7..3294227f7b 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -69,6 +69,56 @@ person = Person.find(1) person.destroy +h3. Validations + +Module to support validation and errors with Active Resource objects. The module overrides Base#save to rescue ActiveResource::ResourceInvalid exceptions and parse the errors returned in the web service response. The module also adds an errors collection that mimics the interface of the errors provided by ActiveRecord::Errors. + +h4. Validating client side resources by overriding validation methods in base class + + +class Person < ActiveResource::Base + self.site = "http://api.people.com:3000/" + + protected + + def validate + errors.add("last", "has invalid characters") unless last =~ /[a-zA-Z]*/ + end +end + + +h4. Validating client side resources + +Consider a Person resource on the server requiring both a first_name and a last_name with a validates_presence_of :first_name, :last_name declaration in the model: + + +person = Person.new(:first_name => "Jim", :last_name => "") +person.save # => false (server returns an HTTP 422 status code and errors) +person.valid? # => false +person.errors.empty? # => false +person.errors.count # => 1 +person.errors.full_messages # => ["Last name can't be empty"] +person.errors[:last_name] # => ["can't be empty"] +person.last_name = "Halpert" +person.save # => true (and person is now saved to the remote service) + + +h4. Public instance methods + +ActiveResource::Validations have three public instance methods + +h5. errors() + +This will return errors object that holds all information about attribute error messages + +h5. save_with_validation(options=nil) + +This validates the resource with any local validations written in base class and then it will try to POST if there are no errors. + +h5. valid? + +Runs all the local validations and will return true if no errors. + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file -- cgit v1.2.3 From 9eb3e637fb7ffa7a35847b5dd577c3a2736e5101 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 5 Aug 2011 13:34:28 +0530 Subject: AttributeMethods refector suffix method added some usages --- railties/guides/source/active_model_basics.textile | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index c76469f62c..87a9658a94 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -30,12 +30,23 @@ private end def attribute_highest?(attribute) - attribute > 100 ? true : false + send(attribute) > 100 ? true : false end end + +person = Person.new +person.age = 110 +person.age_highest? # true +person.reset_age # 0 +person.age_highest? # false + +h4. Callbacks + + + h3. Changelog * August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw \ No newline at end of file -- cgit v1.2.3 From b905f8c96326c86caafc20bec7e3722cf4813d2c Mon Sep 17 00:00:00 2001 From: Sukeerthi Adiga Date: Fri, 5 Aug 2011 14:04:43 +0530 Subject: Rubygems => RubyGems --- railties/README.rdoc | 2 +- railties/guides/source/performance_testing.textile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/README.rdoc b/railties/README.rdoc index 0457227473..eb7ed961e3 100644 --- a/railties/README.rdoc +++ b/railties/README.rdoc @@ -11,7 +11,7 @@ Railties is responsible to glue all frameworks together. Overall, it: == Download -The latest version of Railties can be installed with Rubygems: +The latest version of Railties can be installed with RubyGems: * gem install railties diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile index dbe6f97f5c..75f81cf13d 100644 --- a/railties/guides/source/performance_testing.textile +++ b/railties/guides/source/performance_testing.textile @@ -438,9 +438,9 @@ alias gcrails='~/rubygc/bin/rails' Don't forget to use your aliases from now on. -h6. Install Rubygems (1.8 only!) +h6. Install RubyGems (1.8 only!) -Download "Rubygems":http://rubyforge.org/projects/rubygems and install it from source. Rubygem's README file should have necessary installation instructions. Please note that this step isn't necessary if you've installed Ruby 1.9 and above. +Download "RubyGems":http://rubyforge.org/projects/rubygems and install it from source. Rubygem's README file should have necessary installation instructions. Please note that this step isn't necessary if you've installed Ruby 1.9 and above. h4. Using Ruby-Prof on MRI and REE -- cgit v1.2.3 From bc49d6d1eb075900657b0f94d03c51d18a95a54d Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Fri, 5 Aug 2011 20:46:20 +1200 Subject: [asset pipeline] fixed example Changed << to += because we are _concatenating_ this new array to the end of config array, NOT pushing this array in it. --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 51cb332e38..13e28a25ba 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -297,7 +297,7 @@ The default matcher for compiling files will include +application.js+, +applicat If you have other manifests or individual stylesheets and JavaScript files to include, you can append them to the +precompile+ array: -config.assets.precompile << ['admin.js', 'admin.css', 'swfObject.js'] +config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js'] Precompiled assets exist on the filesystem and are served directly by your webserver. They do not have far-future headers by default, so to get the benefit of fingerprinting you'll have to update your server configuration to add them. -- cgit v1.2.3 From 33d7a6bc55a983ea690961d3a434096fe80d0fca Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 5 Aug 2011 14:35:04 +0530 Subject: ActiveModel::Callbacks basic guide --- railties/guides/source/active_model_basics.textile | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index 87a9658a94..e4c84365d3 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -45,7 +45,31 @@ person.age_highest? # false h4. Callbacks +Callbacks gives Active Record style callbacks. This provides the ability to define the callbacks and those will run at appropriate time. After defining a callbacks you can wrap with before, after and around custom methods. + +class Person + extend ActiveModel::Callbacks + + define_model_callbacks :update + + before_update :reset_me + + def update + _run_update_callbacks do + puts 'saving...' + end + end + + def reset_me + puts 'before saving...' + end +end + +person = Person.new +person.update # before saving... + # saving... + h3. Changelog -- cgit v1.2.3 From d5adaf2d38f81429e21d9670b6a852668edb3757 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 5 Aug 2011 14:48:00 +0530 Subject: ActiveModel::Callbacks basic guide --- railties/guides/source/active_model_basics.textile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index e4c84365d3..92fa5bc8f4 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -57,18 +57,14 @@ class Person def update _run_update_callbacks do - puts 'saving...' + # This will call when we are trying to call update on object. end end def reset_me - puts 'before saving...' + # This method will call when you are calling update on object as a before_update callback as defined. end end - -person = Person.new -person.update # before saving... - # saving... h3. Changelog -- cgit v1.2.3 From a3cf68291df3e9f5b23f56a90929c601ffc26ebd Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 5 Aug 2011 15:28:01 +0530 Subject: ActiveModel::Conversion basic guide --- railties/guides/source/active_model_basics.textile | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index 92fa5bc8f4..daf41d2296 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -67,6 +67,29 @@ class Person end +h4. Conversion + +If a class defines persisted? and id methods then you can include Conversion module in that class and you can able to call Rails conversion methods to objects of that class. + + +class Person + include ActiveModel::Conversion + + def persisted? + false + end + + def id + nil + end +end + +person = Person.new +person.to_model == person #=> true +person.to_key #=> nil +person.to_param #=> nil + + h3. Changelog * August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw \ No newline at end of file -- cgit v1.2.3 From 86ae14df4733cac1748513994caec2f9775ae224 Mon Sep 17 00:00:00 2001 From: Sukeerthi Adiga G Date: Fri, 5 Aug 2011 15:21:12 +0530 Subject: Dirty object methods added to active model basics --- railties/guides/source/active_model_basics.textile | 88 +++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index daf41d2296..404cc71c50 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -90,6 +90,92 @@ person.to_key #=> nil person.to_param #=> nil +h4. Dirty + +An object becomes dirty when an object is gone through one or more changes to its attributes and not yet saved. This gives the ability to check whether an object has been changed or not. It also has attribute based accessor methods. Lets consider a Person class with attributes first_name and last_name + + +require 'rubygems' +require 'active_model' + +class Person + include ActiveModel::Dirty + define_attribute_methods [:first_name, :last_name] + + def first_name + @first_name + end + + def first_name=(value) + first_name_will_change! + @first_name = value + end + + def last_name + @last_name + end + + def last_name=(value) + last_name_will_change! + @last_name = value + end + + def save + @previously_changed = changes + end + +end + + +h5. Querying object directly for its list of all changed attributes. + + +person = Person.new +person.first_name = "First Name" + +person.first_name #=> "First Name" +person.first_name = "First Name Changed" + +person.changed? #=> true + +#returns an list of fields arry which all has been changed before saved. +person.changed #=> ["first_name"] + +#returns a hash of the fields that have changed with their original values. +person.changed_attributes #=> {"first_name" => "First Name Changed"} + +#returns a hash of changes, with the attribute names as the keys, and the values will be an array of the old and new value for that field. +person.changes #=> {"first_name" => ["First Name","First Name Changed"]} + + +h5. Attribute based accessor methods + +Track whether the particular attribute has been changed or not. + + +#attr_name_changed? +person.first_name #=> "First Name" + +#assign some other value to first_name attribute +person.first_name = "First Name 1" + +person.first_name_changed? #=> true + + +Track what was the previous value of the attribute. + +#attr_name_was accessor +person.first_name_was #=> "First Name" + + + +Track both previous and current value of the changed attribute. Returns an array if changed else returns nil + +#attr_name_change +person.first_name_change #=> ["First Name", "First Name 1"] +person.last_name_change #=> nil + + h3. Changelog -* August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw \ No newline at end of file +* August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw -- cgit v1.2.3 From bc9eaf422d9731bb4deb599f7b1e2e9014b870a0 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 6 Aug 2011 01:01:54 +0530 Subject: indentation fixes --- railties/guides/source/initialization.textile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 6ab2706d6b..154df51cdc 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -348,10 +348,10 @@ The class *is* defined in +Rack::Server+, but is overwritten in +Rails::Server+ def parse!(args) args, options = args.dup, {} - opt_parser = OptionParser.new do |opts| - opts.banner = "Usage: rails server [mongrel, thin, etc] [options]" - opts.on("-p", "--port=port", Integer, - "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v } + opt_parser = OptionParser.new do |opts| + opts.banner = "Usage: rails server [mongrel, thin, etc] [options]" + opts.on("-p", "--port=port", Integer, + "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v } ... -- cgit v1.2.3 From 31b820eef92e218349a4a7f033868fc387a92e5b Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 6 Aug 2011 01:39:05 +0530 Subject: expand tmp:* tasks, and a few more additions in the command line guide --- railties/guides/source/command_line.textile | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index f48fa96451..6d5132a1bf 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -381,6 +381,7 @@ Ruby version 1.8.7 (x86_64-linux) RubyGems version 1.3.6 Rack version 1.1 Rails version 3.1.0 +JavaScript Runtime Node.js (V8) Active Record version 3.1.0 Action Pack version 3.1.0 Active Resource version 3.1.0 @@ -390,12 +391,12 @@ Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rai Application root /home/foobar/commandsapp Environment development Database adapter sqlite3 -Database schema version 0 +Database schema version 20110805173523 h4. +assets+ -You can precompile the assets in app/assets using rake assets:precompile and remove compiled assets using rake assets:clean. +You can precompile the assets in app/assets using rake assets:precompile and remove those compiled assets using rake assets:clean. h4. +db+ @@ -460,13 +461,18 @@ h4. +test+ INFO: A good description of unit testing in Rails is given in "A Guide to Testing Rails Applications":testing.html -Rails comes with a test suite called Test::Unit. It is through the use of tests that Rails itself is so stable, and the slew of people working on Rails can prove that everything works as it should. - -The +test:+ namespace helps in running the different tests you will (hopefully!) write. +Rails comes with a test suite called Test::Unit. Rails owes its stability to the use of tests. The tasks available in the +test:+ namespace helps in running the different tests you will hopefully write. h4. +tmp+ -The Rails.root/tmp directory is, like the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for files), process id files, and cached actions. The +tmp:+ namespace tasks will help you clear them if you need to if they've become overgrown, or create them in case of deletions gone awry. +The Rails.root/tmp directory is, like the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for files), process id files, and cached actions. + +The +tmp:+ namespaced tasks will help you clear the Rails.root/tmp directory: + +* +rake tmp:cache:clear+ clears tmp/cache. +* +rake tmp:sessions:clear+ clears tmp/sessions. +* +rake tmp:sockets:clear+ clears tmp/sockets. +* +rake tmp:clear+ clears all the three: cache, sessions and sockets. h4. Miscellaneous -- cgit v1.2.3 From 8320fbb3b01be05d133de445ecf0bbc172225dc5 Mon Sep 17 00:00:00 2001 From: JudeArasu Date: Sat, 6 Aug 2011 05:21:27 +0530 Subject: prototype switch --- railties/guides/source/3_1_release_notes.textile | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index 7d85d7a600..b1eaca1ef9 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -67,6 +67,10 @@ h4. Default JS library is now jQuery jQuery is the default JavaScript library that ships with Rails 3.1. But if you use Prototype, it's simple to switch. + +$ ruby /path/to/rails/bin/rails new myapp -j prototype --dev + + h4. Identity Map Active Record has an Identity Map in Rails 3.1. An identity map keeps previously instantiated records and returns the object associated with the record if accessed again. The identity map is created on a per-request basis and is flushed at request completion. @@ -417,3 +421,4 @@ h3. Credits See the "full list of contributors to Rails":http://contributors.rubyonrails.org/ for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them. Rails 3.1 Release Notes were compiled by "Vijay Dev":https://github.com/vijaydev. + -- cgit v1.2.3 From dbf22560c627c9b639d201887c137e822e4464be Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 6 Aug 2011 23:53:53 +0530 Subject: 3.1 release notes: organize action_pack notes --- railties/guides/source/3_1_release_notes.textile | 86 ++++++++++++------------ 1 file changed, 43 insertions(+), 43 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index b1eaca1ef9..eb4f775ff0 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -21,8 +21,6 @@ Rails 3.1 requires Ruby 1.8.7 or higher. Support for all of the previous Ruby ve TIP: Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults, so if you want to use 1.9.x jump on 1.9.2 for smooth sailing. -TODO. What else? - h3. Creating a Rails 3.1 application @@ -68,7 +66,7 @@ h4. Default JS library is now jQuery jQuery is the default JavaScript library that ships with Rails 3.1. But if you use Prototype, it's simple to switch. -$ ruby /path/to/rails/bin/rails new myapp -j prototype --dev +$ rails new myapp -j prototype h4. Identity Map @@ -103,41 +101,25 @@ h3. Railties * Added Rack::Cache to the default middleware stack. -* TODO Engine related changes +* Engines received a major update - You can mount them at any path, enable assets, run generators etc. h3. Action Pack -h4. Abstract Controller - h4. Action Controller -* Added streaming support, you can enable it with: - - -class PostsController < ActionController::Base - stream :only => :index -end - - -Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information. - -* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. - -h4. Action Dispatch - -* Added ActionDispatch::Request.ignore_accept_header to ignore accept headers. +* A warning is given out if the CSRF token authenticity cannot be verified. -h4. Action View +* Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, :only or :except can be used. -* Created ActionView::Renderer and specified an API for ActionView::Context. +* Sensitive query string parameters specified in config.filter_parameters will now be filtered out from the request paths in the log. -TODO +* URL parameters which return nil for +to_param+ are now removed from the query string. -* A warning is given out if the CSRF token authenticity cannot be verified. +* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. -* Allows AM/PM format in datetime selectors. +* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller). -* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink +* +url_for+ and named url helpers now accept +:subdomain+ and +:domain+ as options. * Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call. @@ -180,31 +162,43 @@ class PostsController < ApplicationController end -* Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, :only or :except can be used. +* Added streaming support, you can enable it with: -* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete }) + +class PostsController < ActionController::Base + stream :only => :index +end + -* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper. +Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information. -* Sensitive query string parameters specified in config.filter_parameters will now be filtered out from the request paths in the log. +* The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused. -* URL parameters which return nil for +to_param+ are now removed from the query string. +h4. Action Dispatch * ActionDispatch::MiddlewareStack now uses composition over inheritance and is no longer an array. -* Added an :authenticity_token option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false. +* Added ActionDispatch::Request.ignore_accept_header to ignore accept headers. -* Added HTML5 button_tag helper. +* Added Rack::Cache to the default stack. + +* Moved etag responsibility from ActionDispatch::Response to the middleware stack. + +* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy. * Template lookup now searches further up in the inheritance chain. -* config.action_view.cache_template_loading is brought back which allows to decide whether templates should be cached or not. TODO from which version? +h4. Action View -* url_for and named url helpers now accept :subdomain and :domain as options. +* Added an :authenticity_token option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false. -* The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused. +* Created ActionView::Renderer and specified an API for ActionView::Context. -* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller). +* In place SafeBuffer mutation is prohibited in Rails 3.1. + +* Added HTML5 button_tag helper. + +* +file_field+ automatically adds :multipart => true to the enclosing form. * Added a convenience idiom to generate HTML5 data-* attributes in tag helpers from a :data hash of options: @@ -215,19 +209,23 @@ tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)}) Keys are dasherized. Values are JSON-encoded, except for strings and symbols. +* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases csrf_meta_tag for backwards compatibility. + * The old template handler API is deprecated and the new API simply requires a template handler to respond to call. * rhtml and rxml are finally removed as template handlers. -* Moved etag responsibility from ActionDispatch::Response to the middleware stack. +* config.action_view.cache_template_loading is brought back which allows to decide whether templates should be cached or not. -* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy. +* The submit form helper does not generate an id "object_name_id" anymore. -* file_field automatically adds :multipart => true to the enclosing form. +* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete }) -* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases csrf_meta_tag for backwards compatibility. +* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper. -* Added Rack::Cache to the default stack. +* Allows AM/PM format in datetime selectors. + +* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink h3. Active Record @@ -380,6 +378,8 @@ h3. Active Model * ActiveModel::AttributeMethods allows attributes to be defined on demand. +* Added support for selectively enabling and disabling observers. + h3. Active Resource * The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. For example, -- cgit v1.2.3 From b840d71bfb702b121b48832f984090e202793f10 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Sun, 7 Aug 2011 09:37:39 +1200 Subject: [asset pipeline] Update Capistrano info v2.8.0 of Capistrano has a recipe to handle precompile and symlinking. --- railties/guides/source/asset_pipeline.textile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 13e28a25ba..3a87c90516 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -276,17 +276,15 @@ The rake task is: rake assets:precompile -You can run this as part of a Capistrano deployment: +Capistrano (v2.8.0+) has a recipe to to handle this in deployment. Add the following line to +Capfile+: -before 'deploy:symlink' do - run "cd #{release_path}; RAILS_ENV=#{rails_env} rake assets:precompile" -end +load 'deploy/assets' -If you are not precompiling your assets, and you are using the default cache file store (which is the file system), you will need to symlink +rails_root/tmp/cache/assets+ from the shared folder that is part of the Capistrano deployment structure in order to persist the cached file between deployments. +This links the folder specified in +config.assets.prefix+ to +shared/assets+. If you already use this folder you'll need to write your own deployment task. -TODO: Extend above task to allow for this and add task to set it up (See commits 8f0e0b6 and 704ee0df). Note: Capistrano folks are working on a recipe - update this when it available (see https://github.com/capistrano/capistrano/pull/35). +It is important for this folder is shared between deployments so that remotely cached pages that reference the old compiled assets still work for the life of the cached page. The default matcher for compiling files will include +application.js+, +application.css+ and all files that do not end in +js+ or +css+: -- cgit v1.2.3 From 8c133fc4c0c04ddfe6f964062c4dcfc65ceb0222 Mon Sep 17 00:00:00 2001 From: ov3y Date: Sun, 7 Aug 2011 07:55:59 -0300 Subject: Point to current, official upgrade plugin --- railties/guides/source/3_0_release_notes.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile index fbb684978a..d22c76dd81 100644 --- a/railties/guides/source/3_0_release_notes.textile +++ b/railties/guides/source/3_0_release_notes.textile @@ -59,12 +59,12 @@ The +config.gem+ method is gone and has been replaced by using +bundler+ and a + h4. Upgrade Process -To help with the upgrade process, a plugin named "Rails Upgrade":http://github.com/jm/rails_upgrade has been created to automate part of it. +To help with the upgrade process, a plugin named "Rails Upgrade":http://github.com/rails/rails_upgrade has been created to automate part of it. Simply install the plugin, then run +rake rails:upgrade:check+ to check your app for pieces that need to be updated (with links to information on how to update them). It also offers a task to generate a +Gemfile+ based on your current +config.gem+ calls and a task to generate a new routes file from your current one. To get the plugin, simply run the following: -$ ruby script/plugin install git://github.com/jm/rails_upgrade.git +$ ruby script/plugin install git://github.com/rails/rails_upgrade.git You can see an example of how that works at "Rails Upgrade is now an Official Plugin":http://omgbloglol.com/post/364624593/rails-upgrade-is-now-an-official-plugin -- cgit v1.2.3 From 93ec7bb59a62702051377e9beb43501ccd9d0f2a Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 7 Aug 2011 21:45:12 +0530 Subject: 3.1 release notes: fixed font changes --- railties/guides/source/3_1_release_notes.textile | 43 ++++++++++++------------ 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index eb4f775ff0..5f09d8fd2b 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -121,7 +121,7 @@ h4. Action Controller * +url_for+ and named url helpers now accept +:subdomain+ and +:domain+ as options. -* Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call. +* Added +Base.http_basic_authenticate_with+ to do simple http basic authentication with a single class method call. class PostsController < ApplicationController @@ -190,13 +190,13 @@ h4. Action Dispatch h4. Action View -* Added an :authenticity_token option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false. +* Added an +:authenticity_token+ option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false. * Created ActionView::Renderer and specified an API for ActionView::Context. -* In place SafeBuffer mutation is prohibited in Rails 3.1. +* In place +SafeBuffer+ mutation is prohibited in Rails 3.1. -* Added HTML5 button_tag helper. +* Added HTML5 +button_tag+ helper. * +file_field+ automatically adds :multipart => true to the enclosing form. @@ -248,9 +248,9 @@ user.build_account{ |a| a.credit_limit => 100.0 } * Added ActiveRecord::Base.attribute_names to return a list of attribute names. This will return an empty array if the model is abstract or the table does not exist. -* CSV Fixtures are deprecated and support will be removed in Rails 3.2.0 +* CSV Fixtures are deprecated and support will be removed in Rails 3.2.0. -* ActiveRecord#new, ActiveRecord#create and ActiveRecord#update_attributes all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of ActiveModel's new mass assignment capabilities: +* ActiveRecord#new, ActiveRecord#create and ActiveRecord#update_attributes all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of ActiveModel's new mass assignment capabilities: class Post < ActiveRecord::Base @@ -261,19 +261,19 @@ end Post.new(params[:post], :as => :admin) -* default_scope can now take a block, lambda, or any other object which responds to call for lazy evaluation: +* +default_scope+ can now take a block, lambda, or any other object which responds to call for lazy evaluation: * Default scopes are now evaluated at the latest possible moment, to avoid problems where scopes would be created which would implicitly contain the default scope, which would then be impossible to get rid of via Model.unscoped. * PostgreSQL adapter only supports PostgreSQL version 8.2 and higher. -* ConnectionManagement middleware is changed to clean up the connection pool after the rack body has been flushed. +* +ConnectionManagement+ middleware is changed to clean up the connection pool after the rack body has been flushed. -* Added an update_column method on ActiveRecord. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use #update_attribute unless you are sure you do not want to execute any callback, including the modification of the updated_at column. It should not be called on new records. +* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records. -* Associations with a :through option can now use any association as the through or source association, including other associations which have a :through option and has_and_belongs_to_many associations. +* Associations with a +:through+ option can now use any association as the through or source association, including other associations which have a +:through+ option and +has_and_belongs_to_many+ associations. -* The configuration for the current database connection is now accessible via ActiveRecord::Base.connection_config. +* The configuration for the current database connection is now accessible via ActiveRecord::Base.connection_config. * limits and offsets are removed from COUNT queries unless both are supplied. @@ -286,9 +286,9 @@ People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET * Singular associations (has_one, belongs_to) no longer have a proxy and simply returns the associated record or nil. This means that you should not use undocumented methods such as bob.mother.create - use bob.create_mother instead. -* Support the :dependent option on has_many :through associations. For historical and practical reasons, :delete_all is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is :nullify for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association. +* Support the :dependent option on has_many :through associations. For historical and practical reasons, :delete_all is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is :nullify for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association. -* The behavior of association.destroy for has_and_belongs_to_many and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'. +* The behavior of association.destroy for +has_and_belongs_to_many+ and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'. * Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It would not delete any records in the join table. Now, it deletes the records in the join table. @@ -332,7 +332,7 @@ class FooMigration < ActiveRecord::Migration end -* Migration files generated from model and constructive migration generators (for example, add_name_to_users) use the reversible migration's change method instead of the ordinary up and down methods. +* Migration files generated from model and constructive migration generators (for example, add_name_to_users) use the reversible migration's +change+ method instead of the ordinary +up+ and +down+ methods. * Removed support for interpolating string SQL conditions on associations. Instead, a proc should be used. @@ -348,7 +348,7 @@ You can have any "normal" conditions inside the proc, so the following will work has_many :things, :conditions => proc { ["foo = ?", bar] } -* Previously :insert_sql and :delete_sql on has_and_belongs_to_many association allowed you to call 'record' to get the record being inserted or deleted. This is now passed as an argument to the proc. +* Previously +:insert_sql+ and +:delete_sql+ on +has_and_belongs_to_many+ association allowed you to call 'record' to get the record being inserted or deleted. This is now passed as an argument to the proc. * Added ActiveRecord::Base#has_secure_password (via ActiveModel::SecurePassword) to encapsulate dead-simple password usage with BCrypt encryption and salting. @@ -360,13 +360,13 @@ end * When a model is generated +add_index+ is added by default for +belongs_to+ or +references+ columns. -* Setting the id of a belongs_to object will update the reference to the object. +* Setting the id of a +belongs_to+ object will update the reference to the object. -* ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed to closer match normal Ruby dup and clone semantics. +* ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed to closer match normal Ruby dup and clone semantics. -* Calling ActiveRecord::Base#clone will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called. +* Calling ActiveRecord::Base#clone will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called. -* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable. +* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable. h3. Active Model @@ -394,13 +394,13 @@ h3. Active Support * ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant. -* Added a new reporting method Kernel#quietly which silences both STDOUT and STDERR. +* Added a new reporting method Kernel#quietly which silences both +STDOUT+ and +STDERR+. * Added String#inquiry as a convenience method for turning a String into a +StringInquirer+ object. * Added Object#in? to test if an object is included in another object. -* LocalCache strategy is now a real middleware class and no longer an anonymous class. +* +LocalCache+ strategy is now a real middleware class and no longer an anonymous class. * ActiveSupport::Dependencies::ClassCache class has been introduced for holding references to reloadable classes. @@ -421,4 +421,3 @@ h3. Credits See the "full list of contributors to Rails":http://contributors.rubyonrails.org/ for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them. Rails 3.1 Release Notes were compiled by "Vijay Dev":https://github.com/vijaydev. - -- cgit v1.2.3 From 32da2f864eb9e1f626f25e5d46a38d0c0d214d15 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Mon, 8 Aug 2011 18:02:19 +1200 Subject: [asset pipeline] update to reflect new sendfile header default X-Sendfile headers are now set to nil and are off by default. See commit eff7fddeb26eaa346827 --- railties/guides/source/asset_pipeline.textile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 3a87c90516..3eede31572 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -385,16 +385,14 @@ This is a handy option if you have any existing project (pre Rails 3.1) that alr h4. X-Sendfile Headers -The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. In production Rails (via Sprockets) does not send the asset - just the location and a zero-length response - relying on the web server to do the file serving, which is usually faster. Both Apache and nginx support this option. +The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. This option is off be default, but can be enabled if your server supports it. When enabled, this passes responsibility for serving the file to the web server, which is faster. -The configuration is available in config/environments/production.rb. +Apache and nginx support this option which is enabled in config/environments/production.rb. config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx -You should check that your server or hosting service actually supports this, otherwise comment it out. - WARNING: If you are upgrading an existing application and intend to use this option, take care to paste this configuration option only into +production.rb+ (and not +application.rb+) and any other environment you define with production behavior. h3. How Caching Works -- cgit v1.2.3 From 49e81f21a3e6facac06c49739644dbb36c94f794 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Mon, 8 Aug 2011 22:21:25 +1200 Subject: [asset pipeline] update snippet to reflect patch Two commented lines in example to match the commit (8845ae683e2688) --- railties/guides/source/asset_pipeline.textile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 3eede31572..8a4d61dc3a 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -390,7 +390,8 @@ The X-Sendfile header is a directive to the server to ignore the response from t Apache and nginx support this option which is enabled in config/environments/production.rb. -config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx +# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache +# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx WARNING: If you are upgrading an existing application and intend to use this option, take care to paste this configuration option only into +production.rb+ (and not +application.rb+) and any other environment you define with production behavior. -- cgit v1.2.3 From 9cf56c709b6ec2ab0479f664761596f6c64f8887 Mon Sep 17 00:00:00 2001 From: Floris Huetink Date: Tue, 9 Aug 2011 15:48:34 +0200 Subject: Fixed typo (attachments method name was missing an s) in Action Mailer basics guide --- railties/guides/source/action_mailer_basics.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile index f05d9dcf1c..5b2212d9cb 100644 --- a/railties/guides/source/action_mailer_basics.textile +++ b/railties/guides/source/action_mailer_basics.textile @@ -404,7 +404,7 @@ Will put the HTML part first, and the plain text part second. h4. Sending Emails with Attachments -Attachments can be added by using the +attachment+ method: +Attachments can be added by using the +attachments+ method: class UserMailer < ActionMailer::Base -- cgit v1.2.3 From 3b4e7c9f8e38bdc7517e85c413f48f5aadf17eec Mon Sep 17 00:00:00 2001 From: "Mr. Wolfe" Date: Wed, 10 Aug 2011 23:22:16 +0200 Subject: update rails on rack guide, section 2 needs to be changed or maybe deleted --- railties/guides/source/rails_on_rack.textile | 33 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile index 8d5985dba8..ea26334ba0 100644 --- a/railties/guides/source/rails_on_rack.textile +++ b/railties/guides/source/rails_on_rack.textile @@ -89,23 +89,32 @@ $ rake middleware For a freshly generated Rails application, this might produce something like: +use ActionDispatch::Static use Rack::Lock -use ActionController::Failsafe -use ActionController::Session::CookieStore, , {:secret=>"", :session_key=>"__session"} -use Rails::Rack::Metal -use ActionDispatch::RewindableInput -use ActionController::ParamsParser -use Rack::MethodOverride -use Rack::Head +use ActiveSupport::Cache::Strategy::LocalCache +use Rack::Runtime +use Rails::Rack::Logger +use ActionDispatch::ShowExceptions +use ActionDispatch::RemoteIp +use Rack::Sendfile +use ActionDispatch::Callbacks +use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache -run ActionController::Dispatcher.new +use ActionDispatch::Cookies +use ActionDispatch::Session::CookieStore +use ActionDispatch::Flash +use ActionDispatch::ParamsParser +use Rack::MethodOverride +use ActionDispatch::Head +use ActionDispatch::BestStandardsSupport +run Blog::Application.routes Purpose of each of this middlewares is explained in the "Internal Middlewares":#internal-middleware-stack section. h4. Configuring Middleware Stack -Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +environment.rb+ or the environment specific configuration file environments/<environment>.rb. +Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +application.rb+ or the environment specific configuration file environments/<environment>.rb. h5. Adding a Middleware @@ -118,7 +127,7 @@ You can add a new middleware to the middleware stack using any of the following * config.middleware.insert_after(existing_middleware, new_middleware, args) - Adds the new middleware after the specified existing middleware in the middleware stack. -# config/environment.rb +# config/application.rb # Push Rack::BounceFavicon at the bottom config.middleware.use Rack::BounceFavicon @@ -133,7 +142,7 @@ h5. Swapping a Middleware You can swap an existing middleware in the middleware stack using +config.middleware.swap+. -# config/environment.rb +# config/application.rb # Replace ActionController::Failsafe with Lifo::Failsafe config.middleware.swap ActionController::Failsafe, Lifo::Failsafe @@ -198,7 +207,7 @@ The following shows how to replace use +Rack::Builder+ instead of the Rails supp Clear the existing Rails middleware stack -# environment.rb +# application.rb config.middleware.clear -- cgit v1.2.3 From 635c1ca007a4e86f277508ec5b116ebcbe71a7f2 Mon Sep 17 00:00:00 2001 From: "Mr. Wolfe" Date: Wed, 10 Aug 2011 23:27:00 +0200 Subject: Revert "update rails on rack guide, section 2 needs to be changed or maybe deleted" This reverts commit 7a4e545eccf834cb620df0f909ef3f4bec4e6608. --- railties/guides/source/rails_on_rack.textile | 33 ++++++++++------------------ 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile index ea26334ba0..8d5985dba8 100644 --- a/railties/guides/source/rails_on_rack.textile +++ b/railties/guides/source/rails_on_rack.textile @@ -89,32 +89,23 @@ $ rake middleware For a freshly generated Rails application, this might produce something like: -use ActionDispatch::Static use Rack::Lock -use ActiveSupport::Cache::Strategy::LocalCache -use Rack::Runtime -use Rails::Rack::Logger -use ActionDispatch::ShowExceptions -use ActionDispatch::RemoteIp -use Rack::Sendfile -use ActionDispatch::Callbacks -use ActiveRecord::ConnectionAdapters::ConnectionManagement -use ActiveRecord::QueryCache -use ActionDispatch::Cookies -use ActionDispatch::Session::CookieStore -use ActionDispatch::Flash -use ActionDispatch::ParamsParser +use ActionController::Failsafe +use ActionController::Session::CookieStore, , {:secret=>"", :session_key=>"__session"} +use Rails::Rack::Metal +use ActionDispatch::RewindableInput +use ActionController::ParamsParser use Rack::MethodOverride -use ActionDispatch::Head -use ActionDispatch::BestStandardsSupport -run Blog::Application.routes +use Rack::Head +use ActiveRecord::QueryCache +run ActionController::Dispatcher.new Purpose of each of this middlewares is explained in the "Internal Middlewares":#internal-middleware-stack section. h4. Configuring Middleware Stack -Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +application.rb+ or the environment specific configuration file environments/<environment>.rb. +Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +environment.rb+ or the environment specific configuration file environments/<environment>.rb. h5. Adding a Middleware @@ -127,7 +118,7 @@ You can add a new middleware to the middleware stack using any of the following * config.middleware.insert_after(existing_middleware, new_middleware, args) - Adds the new middleware after the specified existing middleware in the middleware stack. -# config/application.rb +# config/environment.rb # Push Rack::BounceFavicon at the bottom config.middleware.use Rack::BounceFavicon @@ -142,7 +133,7 @@ h5. Swapping a Middleware You can swap an existing middleware in the middleware stack using +config.middleware.swap+. -# config/application.rb +# config/environment.rb # Replace ActionController::Failsafe with Lifo::Failsafe config.middleware.swap ActionController::Failsafe, Lifo::Failsafe @@ -207,7 +198,7 @@ The following shows how to replace use +Rack::Builder+ instead of the Rails supp Clear the existing Rails middleware stack -# application.rb +# environment.rb config.middleware.clear -- cgit v1.2.3 From 1b0d03b5db04f19d9428959844624a47f6ba1a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emili=20Parre=C3=B1o?= Date: Wed, 10 Aug 2011 23:32:11 +0200 Subject: update rails on rack guide, section 2 needs to be changed or maybe deleted --- railties/guides/source/rails_on_rack.textile | 33 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile index 8d5985dba8..818df0ffaf 100644 --- a/railties/guides/source/rails_on_rack.textile +++ b/railties/guides/source/rails_on_rack.textile @@ -89,23 +89,32 @@ $ rake middleware For a freshly generated Rails application, this might produce something like: +use ActionDispatch::Static use Rack::Lock -use ActionController::Failsafe -use ActionController::Session::CookieStore, , {:secret=>"", :session_key=>"__session"} -use Rails::Rack::Metal -use ActionDispatch::RewindableInput -use ActionController::ParamsParser -use Rack::MethodOverride -use Rack::Head +use ActiveSupport::Cache::Strategy::LocalCache +use Rack::Runtime +use Rails::Rack::Logger +use ActionDispatch::ShowExceptions +use ActionDispatch::RemoteIp +use Rack::Sendfile +use ActionDispatch::Callbacks +use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache -run ActionController::Dispatcher.new +use ActionDispatch::Cookies +use ActionDispatch::Session::CookieStore +use ActionDispatch::Flash +use ActionDispatch::ParamsParser +use Rack::MethodOverride +use ActionDispatch::Head +use ActionDispatch::BestStandardsSupport +run Blog::Application.routes Purpose of each of this middlewares is explained in the "Internal Middlewares":#internal-middleware-stack section. h4. Configuring Middleware Stack -Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +environment.rb+ or the environment specific configuration file environments/<environment>.rb. +Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +application.rb+ or the environment specific configuration file environments/<environment>.rb. h5. Adding a Middleware @@ -118,7 +127,7 @@ You can add a new middleware to the middleware stack using any of the following * config.middleware.insert_after(existing_middleware, new_middleware, args) - Adds the new middleware after the specified existing middleware in the middleware stack. -# config/environment.rb +# config/application.rb # Push Rack::BounceFavicon at the bottom config.middleware.use Rack::BounceFavicon @@ -133,7 +142,7 @@ h5. Swapping a Middleware You can swap an existing middleware in the middleware stack using +config.middleware.swap+. -# config/environment.rb +# config/application.rb # Replace ActionController::Failsafe with Lifo::Failsafe config.middleware.swap ActionController::Failsafe, Lifo::Failsafe @@ -198,7 +207,7 @@ The following shows how to replace use +Rack::Builder+ instead of the Rails supp Clear the existing Rails middleware stack -# environment.rb +# config/application.rb config.middleware.clear -- cgit v1.2.3 From 54cd73e20d5fe2c4168e04f9525b8793e9e3c64c Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 5 Aug 2011 20:15:48 +0530 Subject: ActiveModel::Validations basic guide --- railties/guides/source/active_model_basics.textile | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index 404cc71c50..f3a2b2edbc 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -176,6 +176,30 @@ person.first_name_change #=> ["First Name", "First Name 1"] person.last_name_change #=> nil +h4. Validations + +Validations module adds the ability to class objects to validate them in Active Record style. + + +class Person + include ActiveModel::Validations + + attr_accessor :name, :email + + validates :name, :presence => true + validates_format_of :email, :with => /^([^\s]+)((?:[-a-z0-9]\.)[a-z]{2,})$/i + +end + +person = Person.new +person.valid? #=> false +person.name = 'vishnu' +person.email = 'me' +person.valid? #=> false +person.email = 'me@vishnuatrai.com' +person.valid? #=> true + + h3. Changelog * August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw -- cgit v1.2.3 From 0196f0feb12d6a093f7ffa95de9f878be17adea7 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Thu, 11 Aug 2011 21:28:57 -0300 Subject: Some fixes on the 3_1_release_notes guide. --- railties/guides/source/3_1_release_notes.textile | 44 ++++++++++++------------ 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index 5f09d8fd2b..c1585c707e 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -13,7 +13,7 @@ endprologue. h3. Upgrading to Rails 3.1 -If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 3 and make sure your application still runs as expected before attempting to update to Rails 3.1. Then take heed of the following changes: +If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 3 in case you haven't and make sure your application still runs as expected before attempting to update to Rails 3.1. Then take heed of the following changes: h4. Rails 3.1 requires at least Ruby 1.8.7 @@ -31,13 +31,13 @@ $ cd myapp h4. Vendoring Gems -Rails now uses a +Gemfile+ in the application root to determine the gems you require for your application to start. This +Gemfile+ is processed by the "Bundler":https://github.com/carlhuda/bundler, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems. +Rails now uses a +Gemfile+ in the application root to determine the gems you require for your application to start. This +Gemfile+ is processed by the "Bundler":https://github.com/carlhuda/bundler gem, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems. More information: - "bundler homepage":http://gembundler.com h4. Living on the Edge -+Bundler+ and +Gemfile+ makes freezing your Rails application easy as pie with the new dedicated bundle command. If you want to bundle straight from the Git repository, you can pass the +--edge+ flag: ++Bundler+ and +Gemfile+ makes freezing your Rails application easy as pie with the new dedicated +bundle+ command. If you want to bundle straight from the Git repository, you can pass the +--edge+ flag: $ rails new myapp --edge @@ -79,11 +79,11 @@ h3. Railties * jQuery is the new default JavaScript library. -* jQuery and prototype are no longer vendored and is provided from now on by the jquery-rails and prototype-rails gems. +* jQuery and Prototype are no longer vendored and is provided from now on by the jquery-rails and prototype-rails gems. * The application generator accepts an option -j which can be an arbitrary string. If passed "foo", the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest requires "foo" and "foo_ujs". Currently only "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline. -* Generating an application or a plugin runs bundle install unless --skip-gemfile or --skip-bundle is specified. +* Generating an application or a plugin runs +bundle install+ unless --skip-gemfile or --skip-bundle is specified. * The controller and resource generators will now automatically produce asset stubs (this can be turned off with --skip-assets). These stubs will use CoffeeScript and Sass, if those libraries are available. @@ -115,7 +115,7 @@ h4. Action Controller * URL parameters which return nil for +to_param+ are now removed from the query string. -* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. +* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. * Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller). @@ -184,7 +184,7 @@ h4. Action Dispatch * Moved etag responsibility from ActionDispatch::Response to the middleware stack. -* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy. +* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy. * Template lookup now searches further up in the inheritance chain. @@ -209,7 +209,7 @@ tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)}) Keys are dasherized. Values are JSON-encoded, except for strings and symbols. -* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases csrf_meta_tag for backwards compatibility. +* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases +csrf_meta_tag+ for backwards compatibility. * The old template handler API is deprecated and the new API simply requires a template handler to respond to call. @@ -219,13 +219,13 @@ Keys are dasherized. Values are JSON-encoded, except for strings and symbols. * The submit form helper does not generate an id "object_name_id" anymore. -* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete }) +* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete }). -* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper. +* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper. * Allows AM/PM format in datetime selectors. -* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink +* +auto_link+ has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink h3. Active Record @@ -261,7 +261,7 @@ end Post.new(params[:post], :as => :admin) -* +default_scope+ can now take a block, lambda, or any other object which responds to call for lazy evaluation: +* +default_scope+ can now take a block, lambda, or any other object which responds to call for lazy evaluation. * Default scopes are now evaluated at the latest possible moment, to avoid problems where scopes would be created which would implicitly contain the default scope, which would then be impossible to get rid of via Model.unscoped. @@ -282,19 +282,19 @@ People.offset(1).count # => 'SELECT COUNT(*) FROM people' People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET 1' -* ActiveRecord::Associations::AssociationProxy has been split. There is now an +Association+ class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper +called+ CollectionProxy, which proxies collection associations. This prevents namespace pollution, separates concerns, and will allow further refactorings. +* ActiveRecord::Associations::AssociationProxy has been split. There is now an +Association+ class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper called +CollectionProxy+, which proxies collection associations. This prevents namespace pollution, separates concerns, and will allow further refactorings. * Singular associations (has_one, belongs_to) no longer have a proxy and simply returns the associated record or nil. This means that you should not use undocumented methods such as bob.mother.create - use bob.create_mother instead. -* Support the :dependent option on has_many :through associations. For historical and practical reasons, :delete_all is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is :nullify for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association. +* Support the :dependent option on has_many :through associations. For historical and practical reasons, +:delete_all+ is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is +:nullify+ for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association. -* The behavior of association.destroy for +has_and_belongs_to_many+ and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'. +* The behavior of +association.destroy+ for +has_and_belongs_to_many+ and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'. -* Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It would not delete any records in the join table. Now, it deletes the records in the join table. +* Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It would not delete any records in the join table. Now, it deletes the records in the join table. -* Previously, has_many_through.destroy(*records) would destroy the records themselves, and the records in the join table. [Note: This has not always been the case; previous version of Rails only deleted the records themselves.] Now, it destroys only the records in the join table. +* Previously, has_many_through.destroy(*records) would destroy the records themselves, and the records in the join table. [Note: This has not always been the case; previous version of Rails only deleted the records themselves.] Now, it destroys only the records in the join table. -* Note that this change is backwards-incompatible to an extent, but there is unfortunately no way to 'deprecate' it before changing it. The change is being made in order to have consistency as to the meaning of 'destroy' or 'delete' across the different types of associations. If you wish to destroy the records themselves, you can do records.association.each(&:destroy) +* Note that this change is backwards-incompatible to an extent, but there is unfortunately no way to 'deprecate' it before changing it. The change is being made in order to have consistency as to the meaning of 'destroy' or 'delete' across the different types of associations. If you wish to destroy the records themselves, you can do records.association.each(&:destroy). * Add :bulk => true option to +change_table+ to make all the schema changes defined in a block using a single ALTER statement. @@ -321,7 +321,7 @@ class MyMigration < ActiveRecord::Migration end -* Some things cannot be automatically reversed for you. If you know how to reverse those things, you should define 'up' and 'down' in your migration. If you define something in change that cannot be reversed, an +IrreversibleMigration+ exception will be raised when going down. +* Some things cannot be automatically reversed for you. If you know how to reverse those things, you should define +up+ and +down+ in your migration. If you define something in change that cannot be reversed, an +IrreversibleMigration+ exception will be raised when going down. * Migrations now use instance methods rather than class methods: @@ -392,7 +392,7 @@ end h3. Active Support -* ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant. +* ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in +load_missing_constant+. * Added a new reporting method Kernel#quietly which silences both +STDOUT+ and +STDERR+. @@ -404,13 +404,13 @@ h3. Active Support * ActiveSupport::Dependencies::ClassCache class has been introduced for holding references to reloadable classes. -* ActiveSupport::Dependencies::Reference has been refactored to take direct advantage of the new ClassCache. +* ActiveSupport::Dependencies::Reference has been refactored to take direct advantage of the new +ClassCache+. * Backports Range#cover? as an alias for Range#include? in Ruby 1.8. * Added +weeks_ago+ and +prev_week+ to Date/DateTime/Time. -* Added +before_remove_const+ callback to ActiveSupport::Dependencies.remove_unloadable_constants! +* Added +before_remove_const+ callback to ActiveSupport::Dependencies.remove_unloadable_constants!. Deprecations: -- cgit v1.2.3 From 4d525b8c032b23a21a4c494755ce70b187e102ce Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Sun, 14 Aug 2011 13:05:25 +0800 Subject: Fix tt tag appearing on 3_1_release_notes guide. --- railties/guides/source/3_1_release_notes.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index c1585c707e..4da3aaaf7a 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -219,7 +219,7 @@ Keys are dasherized. Values are JSON-encoded, except for strings and symbols. * The submit form helper does not generate an id "object_name_id" anymore. -* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete }). +* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(==@==post, remote: true, method: :delete) instead of form_for(==@==post, remote: true, html: { method: :delete }). * Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper. -- cgit v1.2.3 From e10b288bc64b8b8160bf880ca2343469558803f9 Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Sun, 14 Aug 2011 12:30:37 +0800 Subject: Use fixed-width font where necessary. --- railties/guides/source/3_1_release_notes.textile | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index 4da3aaaf7a..4db6b2e8e0 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -81,13 +81,13 @@ h3. Railties * jQuery and Prototype are no longer vendored and is provided from now on by the jquery-rails and prototype-rails gems. -* The application generator accepts an option -j which can be an arbitrary string. If passed "foo", the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest requires "foo" and "foo_ujs". Currently only "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline. +* The application generator accepts an option +-j+ which can be an arbitrary string. If passed "foo", the gem "foo-rails" is added to the +Gemfile+, and the application JavaScript manifest requires "foo" and "foo_ujs". Currently only "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline. -* Generating an application or a plugin runs +bundle install+ unless --skip-gemfile or --skip-bundle is specified. +* Generating an application or a plugin runs +bundle install+ unless +--skip-gemfile+ or +--skip-bundle+ is specified. -* The controller and resource generators will now automatically produce asset stubs (this can be turned off with --skip-assets). These stubs will use CoffeeScript and Sass, if those libraries are available. +* The controller and resource generators will now automatically produce asset stubs (this can be turned off with +--skip-assets+). These stubs will use CoffeeScript and Sass, if those libraries are available. -* Scaffold and app generators use the Ruby 1.9 style hash when running on Ruby 1.9. To generate old style hash, --old-style-hash can be passed. +* Scaffold and app generators use the Ruby 1.9 style hash when running on Ruby 1.9. To generate old style hash, +--old-style-hash+ can be passed. * Scaffold controller generator creates format block for JSON instead of XML. @@ -109,15 +109,15 @@ h4. Action Controller * A warning is given out if the CSRF token authenticity cannot be verified. -* Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, :only or :except can be used. +* Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, +:only+ or +:except+ can be used. * Sensitive query string parameters specified in config.filter_parameters will now be filtered out from the request paths in the log. -* URL parameters which return nil for +to_param+ are now removed from the query string. +* URL parameters which return +nil+ for +to_param+ are now removed from the query string. * Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. -* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller). +* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to +false+ will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller). * +url_for+ and named url helpers now accept +:subdomain+ and +:domain+ as options. @@ -200,7 +200,7 @@ h4. Action View * +file_field+ automatically adds :multipart => true to the enclosing form. -* Added a convenience idiom to generate HTML5 data-* attributes in tag helpers from a :data hash of options: +* Added a convenience idiom to generate HTML5 data-* attributes in tag helpers from a +:data+ hash of options: tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)}) @@ -219,7 +219,7 @@ Keys are dasherized. Values are JSON-encoded, except for strings and symbols. * The submit form helper does not generate an id "object_name_id" anymore. -* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(==@==post, remote: true, method: :delete) instead of form_for(==@==post, remote: true, html: { method: :delete }). +* Allows FormHelper#form_for to specify the +:method+ as a direct option instead of through the +:html+ hash. form_for(==@==post, remote: true, method: :delete) instead of form_for(==@==post, remote: true, html: { method: :delete }). * Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper. @@ -284,7 +284,7 @@ People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET * ActiveRecord::Associations::AssociationProxy has been split. There is now an +Association+ class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper called +CollectionProxy+, which proxies collection associations. This prevents namespace pollution, separates concerns, and will allow further refactorings. -* Singular associations (has_one, belongs_to) no longer have a proxy and simply returns the associated record or nil. This means that you should not use undocumented methods such as bob.mother.create - use bob.create_mother instead. +* Singular associations (+has_one+, +belongs_to+) no longer have a proxy and simply returns the associated record or +nil+. This means that you should not use undocumented methods such as +bob.mother.create+ - use +bob.create_mother+ instead. * Support the :dependent option on has_many :through associations. For historical and practical reasons, +:delete_all+ is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is +:nullify+ for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association. @@ -341,7 +341,7 @@ has_many :things, :conditions => 'foo = #{bar}' # before has_many :things, :conditions => proc { "foo = #{bar}" } # after -Inside the proc, 'self' is the object which is the owner of the association, unless you are eager loading the association, in which case 'self' is the class which the association is within. +Inside the proc, +self+ is the object which is the owner of the association, unless you are eager loading the association, in which case +self+ is the class which the association is within. You can have any "normal" conditions inside the proc, so the following will work too: @@ -366,7 +366,7 @@ end * Calling ActiveRecord::Base#clone will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called. -* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable. +* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return +true+ for new_record?, have a +nil+ id field, and is saveable. h3. Active Model -- cgit v1.2.3 From 33be1b0e4bfe6b1dd2acf34d6f214f1b6c776bcc Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Sun, 14 Aug 2011 13:11:36 +0800 Subject: Active Model instead of ActiveModel. --- railties/guides/source/3_1_release_notes.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index 4db6b2e8e0..77dff26280 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -250,7 +250,7 @@ user.build_account{ |a| a.credit_limit => 100.0 } * CSV Fixtures are deprecated and support will be removed in Rails 3.2.0. -* ActiveRecord#new, ActiveRecord#create and ActiveRecord#update_attributes all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of ActiveModel's new mass assignment capabilities: +* ActiveRecord#new, ActiveRecord#create and ActiveRecord#update_attributes all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of Active Model's new mass assignment capabilities: class Post < ActiveRecord::Base -- cgit v1.2.3 From 9f76e47c9b897d3a2595129c61fe0e9737253347 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 14 Aug 2011 19:52:22 +0530 Subject: added a few more items in the release notes --- railties/guides/source/3_1_release_notes.textile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index 77dff26280..ba36735a0b 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -166,16 +166,18 @@ end class PostsController < ActionController::Base - stream :only => :index + stream end -Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information. +You can restrict it to some actions by using +:only+ or +:except+. Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information. * The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused. h4. Action Dispatch +* config.action_dispatch.x_sendfile_header now defaults to +nil+ and config/environments/production.rb doesn't set any particular value for it. This allows servers to set it through X-Sendfile-Type. + * ActionDispatch::MiddlewareStack now uses composition over inheritance and is no longer an array. * Added ActionDispatch::Request.ignore_accept_header to ignore accept headers. @@ -368,6 +370,8 @@ end * Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return +true+ for new_record?, have a +nil+ id field, and is saveable. +* The query cache now works with prepared statements. No changes in the applications are required. + h3. Active Model * +attr_accessible+ accepts an option +:as+ to specify a role. @@ -380,6 +384,8 @@ h3. Active Model * Added support for selectively enabling and disabling observers. +* Alternate I18n namespace lookup is no longer supported. + h3. Active Resource * The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. For example, -- cgit v1.2.3 From 3c5715575d85e0df69f84357769fc4696fdec3da Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 14 Aug 2011 20:15:22 +0530 Subject: document alias for rails runner --- railties/guides/source/initialization.textile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 154df51cdc..49d7513448 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -190,7 +190,8 @@ aliases = { "g" => "generate", "c" => "console", "s" => "server", - "db" => "dbconsole" + "db" => "dbconsole", + "r" => "runner" } command = ARGV.shift -- cgit v1.2.3 From ac4dc5e240242ed53885e4cac7b48dd93773a329 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 14 Aug 2011 20:15:51 +0530 Subject: rephrase how the verbose methods in a migration work --- railties/guides/source/migrations.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index 4476e067a6..9da12e2e18 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -471,8 +471,8 @@ By default migrations tell you exactly what they're doing and how long it took. Several methods are provided that allow you to control all this: -* +suppress_messages+ suppresses any output generated by its block -* +say+ outputs text (the second argument controls whether it is indented or not) +* +suppress_messages+ takes a block as an argument and suppresses any output generated by the block. +* +say+ takes a message argument and outputs it as is. A second boolean argument can be passed to specify whether to indent or not. * +say_with_time+ outputs text along with how long it took to run its block. If the block returns an integer it assumes it is the number of rows affected. For example, this migration @@ -510,7 +510,7 @@ generates the following output 20080906170109 CreateProducts: migrated (10.0097s) -If you just want Active Record to shut up then running +rake db:migrate VERBOSE=false+ will suppress any output. +If you just want Active Record to shut up then running +rake db:migrate VERBOSE=false+ will suppress all output. h3. Using Models in Your Migrations -- cgit v1.2.3 From 169a50930f330f94c189b5fcd665a3d209ccbcfa Mon Sep 17 00:00:00 2001 From: Raul Murciano Date: Sun, 14 Aug 2011 10:13:23 -0700 Subject: Action Mailer guide update: the :to parameter now supports both String and Array values to indicate recipients. --- railties/guides/source/action_mailer_basics.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile index 5b2212d9cb..4bf9161425 100644 --- a/railties/guides/source/action_mailer_basics.textile +++ b/railties/guides/source/action_mailer_basics.textile @@ -242,11 +242,11 @@ end h5. Sending Email To Multiple Recipients -It is possible to send email to one or more recipients in one email (for e.g. informing all admins of a new signup) by setting the list of emails to the :to key. The to: key however expects a string so you have join the list of recipients using a comma. +It is possible to send email to one or more recipients in one email (for e.g. informing all admins of a new signup) by setting the list of emails to the :to key. The list of emails can be an array of email addresses or a single string with the addresses separated with commas. class AdminMailer < ActionMailer::Base - default :to => Admin.all.map(&:email).join(", "), + default :to => Admin.all.map(&:email), :from => "notification@example.com" def new_registration(user) -- cgit v1.2.3 From 51b2502c5e059bb31ecb5881ec1b19279a49cadf Mon Sep 17 00:00:00 2001 From: Raul Murciano Date: Sun, 14 Aug 2011 10:14:28 -0700 Subject: Action Mailer guide: mention how to use :cc and :bcc parameters. --- railties/guides/source/action_mailer_basics.textile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile index 4bf9161425..517a47d233 100644 --- a/railties/guides/source/action_mailer_basics.textile +++ b/railties/guides/source/action_mailer_basics.textile @@ -256,6 +256,8 @@ It is possible to send email to one or more recipients in one email (for e.g. in end +The same format can be used to set carbon copy (Cc:) and blind carbon copy (Bcc:) recipients, by using the :cc and :bcc keys respectively. + h5. Sending Email With Name Sometimes you wish to show the name of the person instead of just their email address when they receive the email. The trick to doing that is -- cgit v1.2.3 From 7712db4c82975403913e0395f860242ead322570 Mon Sep 17 00:00:00 2001 From: Raul Murciano Date: Sun, 14 Aug 2011 10:24:48 -0700 Subject: Typo --- railties/guides/source/action_mailer_basics.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile index 517a47d233..0941b06cfe 100644 --- a/railties/guides/source/action_mailer_basics.textile +++ b/railties/guides/source/action_mailer_basics.textile @@ -242,7 +242,7 @@ end h5. Sending Email To Multiple Recipients -It is possible to send email to one or more recipients in one email (for e.g. informing all admins of a new signup) by setting the list of emails to the :to key. The list of emails can be an array of email addresses or a single string with the addresses separated with commas. +It is possible to send email to one or more recipients in one email (for e.g. informing all admins of a new signup) by setting the list of emails to the :to key. The list of emails can be an array of email addresses or a single string with the addresses separated by commas. class AdminMailer < ActionMailer::Base -- cgit v1.2.3 From c026cc254cd1afd2f4f3dbaa6b537ed4c8c5a4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Mon, 15 Aug 2011 03:13:07 +0300 Subject: Fix a typo in 'Configuring Rails Applications' guide - The initializer is called `set_autoload_paths`, not `set_autoload_path`. See https://github.com/rails/rails/blob/master/railties/lib/rails/engine.rb#L506 --- railties/guides/source/configuring.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index 2ff5de2334..110c04f66e 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -557,7 +557,7 @@ The error occurred while evaluating nil.each *+set_load_path+* This initializer runs before +bootstrap_hook+. Adds the +vendor+, +lib+, all directories of +app+ and any paths specified by +config.load_paths+ to +$LOAD_PATH+. -*+set_autoload_path+* This initializer runs before +bootstrap_hook+. Adds all sub-directories of +app+ and paths specified by +config.autoload_paths+ to +ActiveSupport::Dependencies.autoload_paths+. +*+set_autoload_paths+* This initializer runs before +bootstrap_hook+. Adds all sub-directories of +app+ and paths specified by +config.autoload_paths+ to +ActiveSupport::Dependencies.autoload_paths+. *+add_routing_paths+* Loads (by default) all +config/routes.rb+ files (in the application and railties, including engines) and sets up the routes for the application. -- cgit v1.2.3 From b8363f84da3356d66a7b30b8d180ad01eb7e0eb3 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 15 Aug 2011 20:36:32 +0530 Subject: minor changes in app templates guide --- railties/guides/source/rails_application_templates.textile | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/rails_application_templates.textile b/railties/guides/source/rails_application_templates.textile index 90fc763349..566f8a0bdd 100644 --- a/railties/guides/source/rails_application_templates.textile +++ b/railties/guides/source/rails_application_templates.textile @@ -148,7 +148,7 @@ The above creates +lib/tasks/bootstrap.rake+ with a +boot:strap+ rake task. h4. generate(what, args) -Runs the supplied rails generator with given arguments. For example, I love to scaffold some whenever I’m playing with Rails: +Runs the supplied rails generator with given arguments. generate(:scaffold, "person", "name:string", "address:text", "age:number") @@ -176,12 +176,6 @@ You can also run rake tasks with a different Rails environment: rake "db:migrate", :env => 'production' -Or even use sudo: - - -rake "gems:install", :sudo => true - - h4. route(routing_code) This adds a routing entry to the +config/routes.rb+ file. In above steps, we generated a person scaffold and also removed +public/index.html+. Now to make +PeopleController#index+ as the default page for the application: -- cgit v1.2.3 From c80876f77880a97f94d2255ff9405bb080a6faa4 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Mon, 15 Aug 2011 16:26:37 +0100 Subject: Document Object#public_send --- .../source/active_support_core_extensions.textile | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 781d3d08cd..8716e94bd9 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -452,6 +452,30 @@ Examples of +in?+: NOTE: Defined in +active_support/core_ext/object/inclusion.rb+. +h4. +public_send+ + +This method is available by default in Ruby 1.9, and is backported to Ruby 1.8 by Active Support. Like the regular +send+ method, +public_send+ allows you to call a method when the name is not known until runtime. However, if the method is not public then a +NoMethodError+ exception will be raised. + + +class Greeter + def hello(who) + "Hello " + who + end + + private + + def secret + "sauce" + end +end + +greeter = Greeter.new +greeter.public_send(:hello, 'Jim') # => "Hello Jim" +greeter.public_send(:secret) # => NoMethodError + + +NOTE: Defined in +active_support/core_ext/object/public_send.rb+. + h3. Extensions to +Module+ h4. +alias_method_chain+ -- cgit v1.2.3 From c0c5d5fd2e40f89fa56bf1c6785a392077f4263a Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 15 Aug 2011 21:46:21 +0530 Subject: assets guide - add info about require_directory, minor rephrasings --- railties/guides/source/asset_pipeline.textile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 8a4d61dc3a..a83226aa21 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -166,7 +166,7 @@ The more generic form can also be used but the asset path and class must both be h4. Manifest Files and Directives -Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ - instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets will load the files specified, process them if necessary, concatenate them into one single file and then compress them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, a page's load time is greatly reduced as there is not as many requests to make for each file. +Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ - instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets will load the files specified, process them if necessary, concatenate them into one single file and then compress them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, the load time of pages are greatly reduced as there are not as many requests to make. For example, in the default Rails application there's a +app/assets/javascripts/application.js+ file which contains the following lines: @@ -176,9 +176,11 @@ For example, in the default Rails application there's a +app/assets/javascripts/ //= require_tree . -In JavaScript files, directives begin with +//=+. In this case, the following file is using the +require+ directive and the +require_tree+ directive. The +require+ directive tells Sprockets that we would like to require a file called +jquery.js+ that is available somewhere in the search path for Sprockets. By default, this is located inside the +vendor/assets/javascripts+ directory contained within the +jquery-rails+ gem. An identical event takes place for the +jquery_ujs+ require +In JavaScript files, the directives begin with +//=+. In this case, the file is using the +require+ and the +require_tree+ directives. The +require+ directive is used to tell Sprockets what are the files that we would like to require. Here, we are requiring the files +jquery.js+ and +jquery_ujs.js+ that are available somewhere in the search path for Sprockets. We need not supply the extensions explicitly. Sprockets will assume we are requiring a +.js+ file when done from within a +.js+ file. -The +require_tree .+ directive tells Sprockets to include _all_ JavaScript files in this directory into the output. Only a path relative to the file can be specified. +NOTE. In Rails 3.1, the +jquery.js+ and +jquery_ujs.js+ files are located inside the +vendor/assets/javascripts+ directory contained within the +jquery-rails+ gem. + +The +require_tree .+ directive tells Sprockets to include _all_ JavaScript files in this directory into the output. Only a path relative to the file can be specified. There is also a +require_directory+ directive which includes all JavaScript files only in the directory specified (no nesting). There's also a default +app/assets/stylesheets/application.css+ file which contains these lines: @@ -344,10 +346,10 @@ Possible options for JavaScript compression are +:closure+, +:uglifier+ and +:yu The default Gemfile includes "uglifier":https://github.com/lautis/uglifier. This gem wraps "UglifierJS":https://github.com/mishoo/UglifyJS (written for NodeJS) in Ruby. It compress your code by removing white spaces and other magical things like changing your +if+ and +else+ statements to ternary operators where possible. -The following line will invoke uglifier for JavaScript compression. +The following line will invoke +uglifier+ for JavaScript compression. -config.assets.js_compressor = :uglifier +config.assets.js_compressor = :uglifier The +config.assets.compress+ must be set to +true+ to enable JavaScript compression -- cgit v1.2.3 From 4ca605b71b0482c34c735b63b94ed001786c7125 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 15 Aug 2011 15:31:47 -0300 Subject: rake assets:precompile executes in production environment as default if RAILS_ENV was not provided --- railties/test/application/assets_test.rb | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 38dd3f5a3f..ccc03f8d9c 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -46,28 +46,40 @@ module ApplicationTests assert defined?(Uglifier) end - test "precompile creates the file and gives it the original asset's content" do + test "precompile creates the filem, gives it the original asset's content and run in production as default" do app_file "app/assets/javascripts/application.js", "alert();" app_file "app/assets/javascripts/foo/application.js", "alert();" + ENV["RAILS_ENV"] = nil capture(:stdout) do Dir.chdir(app_path){ `bundle exec rake assets:precompile` } end - files = Dir["#{app_path}/public/assets/application-*.js"] - files << Dir["#{app_path}/public/assets/foo/application-*.js"].first + files = Dir["#{app_path}/public/assets/application-b29a188b3d9c74ef7cbb7ddf9e99f953.js"] + files << Dir["#{app_path}/public/assets/foo/application-b29a188b3d9c74ef7cbb7ddf9e99f953.js"].first files.each do |file| assert_not_nil file, "Expected application.js asset to be generated, but none found" - assert_equal "alert();\n", File.read(file) + assert_equal "alert()", File.read(file) end end - test "precompile appends the md5 hash to files referenced with asset_path" do + test "precompile appends the md5 hash to files referenced with asset_path and run in the provided RAILS_ENV" do app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" + # capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile RAILS_ENV=test` } + # end + file = Dir["#{app_path}/public/assets/application-4bd8b7059c5336ec7ad515c9dbd59974.css"].first + assert_match /\/assets\/rails-([0-z]+)\.png/, File.read(file) + end + + test "precompile appends the md5 hash to files referenced with asset_path and run in production as default even using RAILS_GROUPS=assets" do + app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" + + ENV["RAILS_ENV"] = nil capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + Dir.chdir(app_path){ `bundle exec rake assets:precompile RAILS_GROUPS=assets` } end - file = Dir["#{app_path}/public/assets/application-*.css"].first + file = Dir["#{app_path}/public/assets/application-8d301a938f1abfd789bbec87ed1ef770.css"].first assert_match /\/assets\/rails-([0-z]+)\.png/, File.read(file) end -- cgit v1.2.3 From fd29b4e47f498ac259c8d3c3fcfaa61c99f2972a Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 15 Aug 2011 15:35:47 -0300 Subject: Fix typo --- railties/test/application/assets_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index ccc03f8d9c..7e68de5674 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -46,7 +46,7 @@ module ApplicationTests assert defined?(Uglifier) end - test "precompile creates the filem, gives it the original asset's content and run in production as default" do + test "precompile creates the file, gives it the original asset's content and run in production as default" do app_file "app/assets/javascripts/application.js", "alert();" app_file "app/assets/javascripts/foo/application.js", "alert();" -- cgit v1.2.3 From 83eec4ca4c8312e27678c15f87ba2e17532f7f07 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Tue, 16 Aug 2011 01:36:21 +0530 Subject: Requiring delegate. --- railties/lib/rails/railtie.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties') diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 8c88b25617..e8fb1f3d98 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -2,6 +2,7 @@ require 'rails/initializable' require 'rails/configuration' require 'active_support/inflector' require 'active_support/core_ext/module/introspection' +require 'active_support/core_ext/module/delegation' module Rails # Railtie is the core of the Rails framework and provides several hooks to extend -- cgit v1.2.3 From f7626ea38ebf1a6efdd8b059204aa2d22e096f39 Mon Sep 17 00:00:00 2001 From: JESii Date: Mon, 15 Aug 2011 15:17:13 -0700 Subject: Updates to Asset Pipeline Guide Grammar/syntax/style changes: 1. Changed all 'we' to 'you' 2. Corrected typos 3. Make consistent styline (e.g., dashes & double-dash usage) 4. Change use of future tense (will...) to present tense (easier to read). --- railties/guides/source/asset_pipeline.textile | 90 +++++++++++++-------------- 1 file changed, 45 insertions(+), 45 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index a83226aa21..74a9e497f2 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -1,6 +1,6 @@ h2. Asset Pipeline -This guide will cover the ideology of the asset pipeline introduced in Rails 3.1. +This guide covers the ideology of the asset pipeline introduced in Rails 3.1. By referring to this guide you will be able to: * Understand what the asset pipeline is and what it does @@ -19,7 +19,7 @@ Prior to Rails 3.1 these features were added through third-party Ruby libraries By having this as a core feature of Rails, all developers can benefit from the power of having their assets pre-processed, compressed and minified by one central library, Sprockets. This is part of Rails' "Fast by default" strategy as outlined by DHH in his 2011 keynote at Railsconf. -In new Rails 3.1 application the asset pipeline is enable by default. It can be disabled in +application.rb+ by putting this line inside the +Application+ class definition: +In new Rails 3.1 application the asset pipeline is enabled by default. It can be disabled in +application.rb+ by putting this line inside the +Application+ class definition: config.assets.enabled = false @@ -30,17 +30,17 @@ It is recommended that you use the defaults for all new apps. h4. Main Features -The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser needs to make to render a web page. While Rails already has a feature to concatenate these types of asset--by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+--, many people do not use it. +The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser must make to render a web page. While Rails already has a feature to concatenate these types of assetsi -- by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+ -- many people do not use it. -The default behavior in Rails 3.1 and onward is to concatenate all files into one master file each for JS and CSS. However, you can separate files or groups of files if required (see below). In production an MD5 fingerprint is inserted into each filename so that the file is cached by the web browser but can be invalidated if the fingerprint is altered. +The default behavior in Rails 3.1 and onward is to concatenate all files into one master file each for JS and CSS. However, you can separate files or groups of files if required (see below). In production, an MD5 fingerprint is inserted into each filename so that the file is cached by the web browser but can be invalidated if the fingerprint is altered. -The second feature is to minify or compress. For CSS, this usually involves removing whitespace and comments. For JavaScript, more complex processes can be applied. You can choose from a set of built in options or specify your own. +The second feature is to minify or compress assets. For CSS, this usually involves removing whitespace and comments. For JavaScript, more complex processes can be applied. You can choose from a set of built in options or specify your own. The third feature is the ability to code these assets using another language, or language extension. These include SCSS or Sass for CSS, CoffeeScript for JavaScript, and ERB for both. h4. What is Fingerprinting and Why Should I Care? -Fingerprinting is a technique where the filenames of content that is static or infrequently updated is altered to be unique to the content contained in the file. +Fingerprinting is a technique whereby the filenames of content that is static or infrequently updated is altered to be unique to the content contained in the file. When a filename is unique and based on its content, HTTP headers can be set to encourage caches everywhere (at ISPs, in browsers) to keep their own copy of the content. When the content is updated, the fingerprint will change and the remote clients will request the new file. This is generally known as _cachebusting_. @@ -52,7 +52,7 @@ global.css => global-908e25f4bf641868d8683022a5b62f54.css This is the strategy adopted by the Rails asset pipeline. -Rails old strategy was to append a query string to every asset linked with a built-in helper. In the source the generated code looked like this: +Rails' old strategy was to append a query string to every asset linked with a built-in helper. In the source the generated code looked like this: /stylesheets/global.css?1309495796 @@ -73,7 +73,7 @@ This has several disadvantages: The other problem is that when static assets are deployed with each new release of code, the mtime of *all* these files changes, forcing all remote clients to fetch them again, even when the content of those assets has not changed. -Fingerprinting avoids all these problems by ensuring filenames are consistent based on the content. +Fingerprinting avoids all these problems by ensuring filenames are consistent based on their content. More reading: @@ -83,11 +83,11 @@ More reading: h3. How to Use the Asset Pipeline -In previous versions of Rails, all assets were located in subdirectories of +public+ such as +images+, +javascripts+ and +stylesheets+. With the asset pipeline, the preferred location for these assets is now the +app/assets+ directory. Files in this directory will be served by the Sprockets middleware included in the sprockets gem. +In previous versions of Rails, all assets were located in subdirectories of +public+ such as +images+, +javascripts+ and +stylesheets+. With the asset pipeline, the preferred location for these assets is now the +app/assets+ directory. Files in this directory are served by the Sprockets middleware included in the sprockets gem. This is not to say that assets can (or should) no longer be placed in +public+; they still can be and will be served as static files by the application or web server. You would only use +app/assets+ if you wish your files to undergo some pre-processing before they are served. -When a scaffold or controller is generated for the application, Rails will also generate a JavaScript file (or CoffeeScript if the +coffee-script+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS if +sass-rails+ is in the +Gemfile+) file for that controller. +When a scaffold or controller is generated for the application, Rails also generates a JavaScript file (or CoffeeScript file if the +coffee-script+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS file if +sass-rails+ is in the +Gemfile+) for that controller. For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as +<%= javascript_include_tag params[:controller] %>+ or +<%= stylesheet_link_tag params[:controller] %>+. @@ -101,13 +101,13 @@ Assets can be placed inside an application in one of three locations: +app/asset +vendor/assets+ is for assets that are owned by outside entities, such as code for JavaScript plugins. -All subdirectories that exist within these three locations will be added to the search path for Sprockets (visible by calling +Rails.application.config.assets.paths+ in a console). When an asset is requested, these paths will be looked through to see if they contain an asset matching the name specified. Once an asset has been found, it's processed by Sprockets and served. +All subdirectories that exist within these three locations are added to the search path for Sprockets (visible by calling +Rails.application.config.assets.paths+ in a console). When an asset is requested, these paths are looked through to see if they contain an asset matching the name specified. Once an asset has been found, it's processed by Sprockets and served. h4. Coding Links to Assets -To access assets, we can use the same tags that we are generally familiar with: +To access assets, you use the same tags that you are generally familiar with: -Sprockets does not add any new methods to require your assets, we still use the familiar +javascript_include_tag+ and +stylesheet_link_tag+. +Sprockets does not add any new methods to require your assets, you still use the familiar +javascript_include_tag+ and +stylesheet_link_tag+. <%= stylesheet_link_tag "application" %> @@ -126,29 +126,29 @@ Images can be organized into directories if required, and they can be accessed b <%= image_tag "icons/rails.png" %> -Providing that assets are enabled within our application (+config.assets.enabled+ in the current environment's file is not set to +false+), this file will be served by Sprockets unless a file at +public/assets/rails.png+ exists, in which case that file will be served. +Providing that assets are enabled within your application (+config.assets.enabled+ in the current environment's file is not set to +false+), this file is served by Sprockets unless a file at +public/assets/rails.png+ exists, in which case that file is served. -Alternatively, a file with an MD5 hash after its name such as +public/assets/rails-af27b6a414e6da00003503148be9b409.png+ will also be picked up by Sprockets. How these hashes are generated is covered in the "Production Assets":#production_assets section later on in this guide. +Alternatively, a file with an MD5 hash after its name such as +public/assets/rails-af27b6a414e6da00003503148be9b409.png+ is also picked up by Sprockets. How these hashes are generated is covered in the "Production Assets":#production_assets section later on in this guide. -Otherwise, Sprockets will look through the available paths until it finds a file that matches the name and then will serve it, first looking in the application's assets directories and then falling back to the various engines of the application. +Otherwise, Sprockets looks through the available paths until it finds a file that matches the name and then serves it, first looking in the application's assets directories and then falling back to the various engines of the application. -If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme - a method of embedding the image data directly into the CSS file - you can use the +asset_data_uri+ helper. +If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme -- a method of embedding the image data directly into the CSS file -- you can use the +asset_data_uri+ helper. #logo { background: url(<%= asset_data_uri 'logo.png' %>) -This will insert a correctly formatted data URI into the CSS source. +This inserts a correctly-formatted data URI into the CSS source. h5. CSS and ERB -If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+ then you can use the +asset_path+ helper in your CSS rules: +If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then you can use the +asset_path+ helper in your CSS rules: .class{background-image:<%= asset_path 'image.png' %>} -This will write the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file then that path will be referenced. +This writes the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file, then that path is referenced. Note that the closing tag cannot be of the style +-%>+. @@ -166,7 +166,7 @@ The more generic form can also be used but the asset path and class must both be h4. Manifest Files and Directives -Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ - instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets will load the files specified, process them if necessary, concatenate them into one single file and then compress them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, the load time of pages are greatly reduced as there are not as many requests to make. +Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ -- instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets loads the files specified, processes them if necessary, concatenates them into one single file and then compresses them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, the load time of pages are greatly reduced as there are fewer requests to make. For example, in the default Rails application there's a +app/assets/javascripts/application.js+ file which contains the following lines: @@ -176,7 +176,7 @@ For example, in the default Rails application there's a +app/assets/javascripts/ //= require_tree . -In JavaScript files, the directives begin with +//=+. In this case, the file is using the +require+ and the +require_tree+ directives. The +require+ directive is used to tell Sprockets what are the files that we would like to require. Here, we are requiring the files +jquery.js+ and +jquery_ujs.js+ that are available somewhere in the search path for Sprockets. We need not supply the extensions explicitly. Sprockets will assume we are requiring a +.js+ file when done from within a +.js+ file. +In JavaScript files, the directives begin with +//=+. In this case, the file is using the +require+ and the +require_tree+ directives. The +require+ directive is used to tell Sprockets the files that you wish to require. Here, you are requiring the files +jquery.js+ and +jquery_ujs.js+ that are available somewhere in the search path for Sprockets. You need not supply the extensions explicitly. Sprockets assumes you are requiring a +.js+ file when done from within a +.js+ file. NOTE. In Rails 3.1, the +jquery.js+ and +jquery_ujs.js+ files are located inside the +vendor/assets/javascripts+ directory contained within the +jquery-rails+ gem. @@ -191,13 +191,13 @@ There's also a default +app/assets/stylesheets/application.css+ file which conta */ -The directives that work in the JavaScript files will also work in stylesheets, obviously including stylesheets rather than JavaScript files. The +require_tree+ directive here works the same way as the JavaScript one, requiring all stylesheets from the current directory. +The directives that work in the JavaScript files also work in stylesheets, obviously including stylesheets rather than JavaScript files. The +require_tree+ directive here works the same way as the JavaScript one, requiring all stylesheets from the current directory. -In this example +require_self+ is used. This will put the CSS contained within the file (if any) at the top of any other CSS in this file unless +require_self+ is specified after another +require+ directive. +In this example +require_self+ is used. This puts the CSS contained within the file (if any) at the top of any other CSS in this file unless +require_self+ is specified after another +require+ directive. You can have as many manifest files as you need. For example the +admin.css+ and +admin.js+ manifest could contain the JS and CSS files that are used for the admin section of an application. -For some assets (like CSS) the compiled order is important. You can specify individual files and they will be compiled in the order specified: +For some assets (like CSS) the compiled order is important. You can specify individual files and they are compiled in the order specified: /* ... @@ -210,36 +210,36 @@ For some assets (like CSS) the compiled order is important. You can specify indi h4. Preprocessing -The file extensions used on an asset will determine what preprocessing will be applied. When a controller or a scaffold is generated with the default Rails gemset, a CoffeeScript file and a SCSS file will be generated in place of a regular JavaScript and CSS file. The example used before was a controller called "projects", which generated an +app/assets/javascripts/projects.js.coffee+ and a +app/assets/stylesheets/projects.css.scss+ file. +The file extensions used on an asset determine what preprocessing is applied. When a controller or a scaffold is generated with the default Rails gemset, a CoffeeScript file and a SCSS file are generated in place of a regular JavaScript and CSS file. The example used before was a controller called "projects", which generated an +app/assets/javascripts/projects.js.coffee+ and a +app/assets/stylesheets/projects.css.scss+ file. -When these files are requested, they will be processed by the processors provided by the +coffee-script+ and +sass-rails+ gems and then sent back to the browser as JavaScript and CSS respectively. +When these files are requested, they are processed by the processors provided by the +coffee-script+ and +sass-rails+ gems and then sent back to the browser as JavaScript and CSS respectively. -Additional layers of pre-processing can be requested by adding other extensions, where each extension will be processed in a right-to-left manner. These should be used in the order the processing should be applied. For example, a stylesheet called +app/assets/stylesheets/projects.css.scss.erb+ would first be processed as ERB, then SCSS and finally served as CSS. The same applies to a JavaScript file - +app/assets/javascripts/projects.js.coffee.erb+ would be process as ERB, CoffeeScript and served as JavaScript. +Additional layers of pre-processing can be requested by adding other extensions, where each extension is processed in a right-to-left manner. These should be used in the order the processing should be applied. For example, a stylesheet called +app/assets/stylesheets/projects.css.scss.erb+ is first processed as ERB, then SCSS and finally served as CSS. The same applies to a JavaScript file -- +app/assets/javascripts/projects.js.coffee.erb+ is processed as ERB, CoffeeScript and served as JavaScript. -Keep in mind that the order of these pre-processors is important. For example, if we called our JavaScript file +app/assets/javascripts/projects.js.erb.coffee+ then it would be processed with the CoffeeScript interpreter first, which wouldn't understand ERB and therefore we would run into problems. +Keep in mind that the order of these pre-processors is important. For example, if you called your JavaScript file +app/assets/javascripts/projects.js.erb.coffee+ then it is processed with the CoffeeScript interpreter first, which wouldn't understand ERB and therefore you would run into problems. h3. In Development In the development environment assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-validate+ Cache-Control HTTP header to reduce request overhead on subsequent requests - on these the browser gets a 304 (not-modified) response. -If any of the files in the manifest have changed between requests, the server will respond with a new compiled file. +If any of the files in the manifest have changed between requests, the server responds with a new compiled file. h4. Debugging Assets -You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL and Sprockets will expand the lines which load the assets. For example, if we had an +app/assets/javascripts/application.js+ file containing these lines: +You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL and Sprockets expands the lines which load the assets. For example, if you had an +app/assets/javascripts/application.js+ file containing these lines: //= require "projects" //= require "tickets" -By default, this would only render this line when used with +<%= javascript_include_tag "application" %>+ in a view or layout: +By default, this only renders this line when used with +<%= javascript_include_tag "application" %>+ in a view or layout: -When the +debug_assets+ parameter is set, this line will be expanded out into three separate lines, separating out the combined file into their parts. +When the +debug_assets+ parameter is set, this line is expanded out into three separate lines, separating out the combined file into their parts. @@ -253,7 +253,7 @@ h3. In Production In the production environment, assets are served slightly differently. -On the first request the assets are compiled and cached as described above, however the manifest names are altered to include an MD5 hash. Files names typically will look like these: +On the first request the assets are compiled and cached as described above, however the manifest names are altered to include an MD5 hash. Files names typically look like these: /assets/application-908e25f4bf641868d8683022a5b62f54.js @@ -270,7 +270,7 @@ h4. Precompiling Assets Even though assets are served by Rack::Cache with far-future headers, in high traffic sites this may not be fast enough. -Rails comes bundled with a rake task to compile the manifests to files on disc. These are located in the +public/assets+ directory where they will be served by your web server instead of the Rails application. +Rails comes bundled with a rake task to compile the manifests to files on disc. These are located in the +public/assets+ directory where they are served by your web server instead of the Rails application. The rake task is: @@ -278,7 +278,7 @@ The rake task is: rake assets:precompile -Capistrano (v2.8.0+) has a recipe to to handle this in deployment. Add the following line to +Capfile+: +Capistrano (v2.8.0+) has a recipe to handle this in deployment. Add the following line to +Capfile+: load 'deploy/assets' @@ -286,9 +286,9 @@ load 'deploy/assets' This links the folder specified in +config.assets.prefix+ to +shared/assets+. If you already use this folder you'll need to write your own deployment task. -It is important for this folder is shared between deployments so that remotely cached pages that reference the old compiled assets still work for the life of the cached page. +It is important that this folder is shared between deployments so that remotely cached pages that reference the old compiled assets still work for the life of the cached page. -The default matcher for compiling files will include +application.js+, +application.css+ and all files that do not end in +js+ or +css+: +The default matcher for compiling files includes +application.js+, +application.css+ and all files that do not end in +js+ or +css+: [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ] @@ -320,7 +320,7 @@ For Apache: TODO: NGINX instructions -When files are precompiled Sprockets also creates "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disc. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the public/assets folder. The following configuration options can be used: +When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disc. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the public/assets folder. The following configuration options can be used: TODO: Apache instructions @@ -332,7 +332,7 @@ h4. CSS Compression There is currently one option for compressing CSS - YUI. This Gem extends the CSS syntax and offers minification. -The following line will enable YUI compression, and requires the +yui-compressor+ gem. +The following line enables YUI compression, and requires the +yui-compressor+ gem. config.assets.css_compressor = :yui @@ -344,9 +344,9 @@ h4. JavaScript Possible options for JavaScript compression are +:closure+, +:uglifier+ and +:yui+. These require the use of the +closure-compiler+, +uglifier+ or +yui-compressor+ gems respectively. -The default Gemfile includes "uglifier":https://github.com/lautis/uglifier. This gem wraps "UglifierJS":https://github.com/mishoo/UglifyJS (written for NodeJS) in Ruby. It compress your code by removing white spaces and other magical things like changing your +if+ and +else+ statements to ternary operators where possible. +The default Gemfile includes "uglifier":https://github.com/lautis/uglifier. This gem wraps "UglifierJS":https://github.com/mishoo/UglifyJS (written for NodeJS) in Ruby. It compresses your code by removing white space and other magical things like changing your +if+ and +else+ statements to ternary operators where possible. -The following line will invoke +uglifier+ for JavaScript compression. +The following line invokes +uglifier+ for JavaScript compression. config.assets.js_compressor = :uglifier @@ -356,7 +356,7 @@ The +config.assets.compress+ must be set to +true+ to enable JavaScript compress h4. Using Your Own Compressor -The compressor config settings for CSS and JavaScript will also take any Object. This object must have a +compress+ method that takes a string as the sole argument and it must return a string. +The compressor config settings for CSS and JavaScript also take any Object. This object must have a +compress+ method that takes a string as the sole argument and it must return a string. class Transformer @@ -366,7 +366,7 @@ class Transformer end -To enable this pass a +new+ Object to the config option in +application.rb+: +To enable this, pass a +new+ Object to the config option in +application.rb+: config.assets.css_compressor = Transformer.new @@ -387,7 +387,7 @@ This is a handy option if you have any existing project (pre Rails 3.1) that alr h4. X-Sendfile Headers -The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. This option is off be default, but can be enabled if your server supports it. When enabled, this passes responsibility for serving the file to the web server, which is faster. +The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. This option is off by default, but can be enabled if your server supports it. When enabled, this passes responsibility for serving the file to the web server, which is faster. Apache and nginx support this option which is enabled in config/environments/production.rb. -- cgit v1.2.3 From 583d7c15c301f15f1e997a06e15b55a2e7bf794f Mon Sep 17 00:00:00 2001 From: Jacob Mattingley Date: Mon, 15 Aug 2011 16:00:53 -0700 Subject: Fixed mistakes in layouts/rendering guide about yield yield(:unspecified_block) actually returns true even if :unspecified_block never exists. This means you can't use the form yield(:unspecified_block) or yield. --- railties/guides/source/layouts_and_rendering.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index 57485e8986..87ba8ab82d 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -1179,14 +1179,14 @@ On pages generated by +NewsController+, you want to hide the top menu and add a <% end %> <% content_for :content do %>
Right menu items here
- <%= yield(:news_content) or yield %> + <%= content_for?(:news_content) ? yield(:news_content) : yield %> <% end %> <%= render :template => 'layouts/application' %>
That's it. The News views will use the new layout, hiding the top menu and adding a new right menu inside the "content" div. -There are several ways of getting similar results with different sub-templating schemes using this technique. Note that there is no limit in nesting levels. One can use the +ActionView::render+ method via +render :template => 'layouts/news'+ to base a new layout on the News layout. If you are sure you will not subtemplate the +News+ layout, you can replace the +yield(:news_content) or yield+ with simply +yield+. +There are several ways of getting similar results with different sub-templating schemes using this technique. Note that there is no limit in nesting levels. One can use the +ActionView::render+ method via +render :template => 'layouts/news'+ to base a new layout on the News layout. If you are sure you will not subtemplate the +News+ layout, you can replace the +content_for?(:news_content) ? yield(:news_content) : yield+ with simply +yield+. h3. Changelog -- cgit v1.2.3 From 308595739c32609ac5b167ecdc6cb6cb4ec6c81f Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Mon, 15 Aug 2011 20:20:28 -0300 Subject: Document Hash#extract!. --- .../guides/source/active_support_core_extensions.textile | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 781d3d08cd..a672b17e4a 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -2696,6 +2696,18 @@ hash # => {:a => 1} NOTE: Defined in +active_support/core_ext/hash/slice.rb+. +h4. Extracting + +The method +extract!+ removes and returns the key/value pairs matching the given keys. + + +hash = {:a => 1, :b => 2} +rest = hash.extract!(:a) # => {:a => 1} +hash # => {:b => 2} + + +NOTE: Defined in +active_support/core_ext/hash/slice.rb+. + h4. Indifferent Access The method +with_indifferent_access+ returns an +ActiveSupport::HashWithIndifferentAccess+ out of its receiver: -- cgit v1.2.3 From 6c5f67cac15c43bafcd917c346cccfcf3fa5fb95 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 16 Aug 2011 00:59:59 +0100 Subject: Don't refer to ActionController::Base in the wrap_parameters initializer - use config object instead. Cuts about 15% off the load time. (#734) --- .../rails/app/templates/config/initializers/wrap_parameters.rb.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt index fa1548db8b..45c7e531ba 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt @@ -4,7 +4,7 @@ # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. -ActionController::Base.wrap_parameters <%= key_value :format, "[:json]" %> +<%= app_const %>.config.wrap_parameters <%= key_value :format, "[:json]" %> # Disable root element in JSON by default. if defined?(ActiveRecord) -- cgit v1.2.3 From f76842f57e3f4e9292867a456abd90c034230916 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 16 Aug 2011 02:28:13 +0100 Subject: Fix wrap_parameters initializer template --- .../rails/app/templates/config/initializers/wrap_parameters.rb.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt index 45c7e531ba..a52917351d 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt @@ -4,7 +4,7 @@ # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. -<%= app_const %>.config.wrap_parameters <%= key_value :format, "[:json]" %> +<%= app_const %>.config.wrap_parameters = { <%= key_value :format, "[:json]" %> } # Disable root element in JSON by default. if defined?(ActiveRecord) -- cgit v1.2.3 From bd4800d614eb7060354a6f9fd8a749a7e7f046a8 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 16 Aug 2011 14:57:36 +0530 Subject: document Array#append and Array#prepend methods in AS guide --- .../source/active_support_core_extensions.textile | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index a672b17e4a..e1fa374aca 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -2069,6 +2069,30 @@ shape_types = [Circle, Square, Triangle].sample(2) NOTE: Defined in +active_support/core_ext/array/random_access.rb+. +h4. Adding Elements + +h5. +prepend+ + +This method is an alias of Array#unshift. + + +%w(a b c d).prepend('e') # => %w(e a b c d) +[].prepend(10) # => [10] + + +NOTE: Defined in +active_support/core_ext/array/prepend_and_append.rb+. + +h5. +append+ + +This method is an alias of Array#<<. + + +%w(a b c d).append('e') # => %w(a b c d e) +[].append([1,2]) # => [[1,2]] + + +NOTE: Defined in +active_support/core_ext/array/prepend_and_append.rb+. + h4. Options Extraction When the last argument in a method call is a hash, except perhaps for a +&block+ argument, Ruby allows you to omit the brackets: -- cgit v1.2.3 From 4dd985ae9514fdb9688eab780d881decff8358fa Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 16 Aug 2011 15:13:57 +0100 Subject: Don't reference ActiveRecord::Base in initializers/wrap_parameters.rb. Use config.active_record instead. This yields about a 20% decrease in startup time because it means that the connection is not created immediately on startup. Of course, this is only useful if you are not going to immediately use the database after startup. --- .../app/templates/config/initializers/wrap_parameters.rb.tt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt index a52917351d..b7b344a62d 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt @@ -3,10 +3,12 @@ # 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. -<%= app_const %>.config.wrap_parameters = { <%= key_value :format, "[:json]" %> } +<%= app_const %>.configure do + # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. + config.action_controller.wrap_parameters = { <%= key_value :format, "[:json]" %> } -# Disable root element in JSON by default. -if defined?(ActiveRecord) - ActiveRecord::Base.include_root_in_json = false + <%- unless options.skip_active_record? -%> + # Disable root element in JSON by default. + config.active_record.include_root_in_json = false + <%- end -%> end -- cgit v1.2.3 From 590239156714c03ad525b2248a11a3f34da3aa6a Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 16 Aug 2011 16:37:56 +0100 Subject: Fix assets tests in railties --- railties/test/application/assets_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 7e68de5674..a8d1382e94 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -54,8 +54,8 @@ module ApplicationTests capture(:stdout) do Dir.chdir(app_path){ `bundle exec rake assets:precompile` } end - files = Dir["#{app_path}/public/assets/application-b29a188b3d9c74ef7cbb7ddf9e99f953.js"] - files << Dir["#{app_path}/public/assets/foo/application-b29a188b3d9c74ef7cbb7ddf9e99f953.js"].first + files = Dir["#{app_path}/public/assets/application-*.js"] + files << Dir["#{app_path}/public/assets/foo/application-*.js"].first files.each do |file| assert_not_nil file, "Expected application.js asset to be generated, but none found" assert_equal "alert()", File.read(file) @@ -68,7 +68,7 @@ module ApplicationTests # capture(:stdout) do Dir.chdir(app_path){ `bundle exec rake assets:precompile RAILS_ENV=test` } # end - file = Dir["#{app_path}/public/assets/application-4bd8b7059c5336ec7ad515c9dbd59974.css"].first + file = Dir["#{app_path}/public/assets/application-*.css"].first assert_match /\/assets\/rails-([0-z]+)\.png/, File.read(file) end @@ -79,7 +79,7 @@ module ApplicationTests capture(:stdout) do Dir.chdir(app_path){ `bundle exec rake assets:precompile RAILS_GROUPS=assets` } end - file = Dir["#{app_path}/public/assets/application-8d301a938f1abfd789bbec87ed1ef770.css"].first + file = Dir["#{app_path}/public/assets/application-*.css"].first assert_match /\/assets\/rails-([0-z]+)\.png/, File.read(file) end -- cgit v1.2.3 From c5f97b5063d1d60341f9e984f29a3b9812fb4c7e Mon Sep 17 00:00:00 2001 From: Jeff Dutil Date: Tue, 16 Aug 2011 13:12:07 -0400 Subject: Fix formatting of active_record_validations_callbacks.textile so guide will render properly at http://edgeguides.rubyonrails.org/active_record_validations_callbacks.html#displaying-validation-errors-in-the-view --- railties/guides/source/active_record_validations_callbacks.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 977e736d25..aba3224ba7 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -751,8 +751,6 @@ class Person < ActiveRecord::Base end
- - h4. +errors.clear+ The +clear+ method is used when you intentionally want to clear all the messages in the +errors+ collection. Of course, calling +errors.clear+ upon an invalid object won't actually make it valid: the +errors+ collection will now be empty, but the next time you call +valid?+ or any method that tries to save this object to the database, the validations will run again. If any of the validations fail, the +errors+ collection will be filled again. @@ -799,6 +797,7 @@ h3. Displaying Validation Errors in the View Rails maintains an official plugin that provides helpers to display the error messages of your models in your view templates. You can install it as a plugin or as a Gem. h4. Installing as a plugin + $ rails plugin install git://github.com/joelmoss/dynamic_form.git @@ -806,6 +805,7 @@ $ rails plugin install git://github.com/joelmoss/dynamic_form.git h4. Installing as a Gem Add this line in your Gemfile: + gem "dynamic_form" -- cgit v1.2.3 From 53a13083ecc7f99ff04d3fe54f8cb1d68e486aac Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 16 Aug 2011 10:34:18 -0700 Subject: AS guide: document in Module#delegate that the method must be public in the target --- railties/guides/source/active_support_core_extensions.textile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 8716e94bd9..38920c2edb 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -888,7 +888,9 @@ end It is shorter, and the intention more obvious. -The macro accepts several methods: +The method must be public in the target. + +The +delegate+ macro accepts several methods: delegate :name, :age, :address, :twitter, :to => :profile -- cgit v1.2.3 From 8e236152457ed48bb436e9bffb4c5d6d4b6a26d4 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 16 Aug 2011 19:14:06 +0100 Subject: Use lazy load hooks to set parameter wrapping configuration. This means that it doesn't force Action Controller / Active Record to load, but it doesn't fail if they have already loaded. Thanks @josevalim for the hint. --- .../templates/config/initializers/wrap_parameters.rb.tt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt index b7b344a62d..d640f578da 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt @@ -3,12 +3,14 @@ # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. -<%= app_const %>.configure do - # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. - config.action_controller.wrap_parameters = { <%= key_value :format, "[:json]" %> } +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters <%= key_value :format, "[:json]" %> +end - <%- unless options.skip_active_record? -%> - # Disable root element in JSON by default. - config.active_record.include_root_in_json = false - <%- end -%> +<%- unless options.skip_active_record? -%> +# Disable root element in JSON by default. +ActiveSupport.on_load(:active_record) do + self.include_root_in_json = false end +<%- end -%> -- cgit v1.2.3 From 3ebb322f2180e8b9dada05706172f75d185923d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20Garc=C3=ADa?= Date: Wed, 17 Aug 2011 04:01:07 +0200 Subject: Cleanup application.css --- .../rails/app/templates/app/assets/stylesheets/application.css | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css b/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css index 9e07c7d9a9..3b5cc6648e 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +++ b/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css @@ -4,10 +4,10 @@ * * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. - * + * * 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 . -*/ \ No newline at end of file + *= require_tree . +*/ -- cgit v1.2.3 From 7ff894dcc75b46274e20a20c26b679e204e6c82b Mon Sep 17 00:00:00 2001 From: Jeff Dutil Date: Tue, 16 Aug 2011 22:48:01 -0400 Subject: Fix spacing in plugins.textile to fix html rendering and remove extra whitespace from security.textile --- railties/guides/source/plugins.textile | 2 ++ railties/guides/source/security.textile | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile index 188423861d..d3f9783fa6 100644 --- a/railties/guides/source/plugins.textile +++ b/railties/guides/source/plugins.textile @@ -386,6 +386,7 @@ ActiveRecord::Base.send :include, Yaffle::ActsAsYaffle Run +rake+ one final time and you should see: + 7 tests, 7 assertions, 0 failures, 0 errors, 0 skips @@ -426,6 +427,7 @@ require 'yaffle' You can test this by changing to the Rails application that you added the plugin to and starting a rails console. Once in the console we can check to see if the String has an instance method of to_squawk. + $ cd my_app $ rails console diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile index 1f6ff88c1f..04d1d0bda8 100644 --- a/railties/guides/source/security.textile +++ b/railties/guides/source/security.textile @@ -80,7 +80,6 @@ This will also be a good idea, if you modify the structure of an object and old * _(highlight)Critical data should not be stored in session_. If the user clears his cookies or closes the browser, they will be lost. And with a client-side session storage, the user can read the data. - h4. Session Storage -- _Rails provides several storage mechanisms for the session hashes. The most important are ActiveRecordStore and CookieStore._ -- cgit v1.2.3 From f302370c0527cd5f24889e7068134e59b65b40f1 Mon Sep 17 00:00:00 2001 From: Jeff Dutil Date: Tue, 16 Aug 2011 22:59:36 -0400 Subject: Fix ruby typo to correctly render code block in initializer.textile --- railties/guides/source/initialization.textile | 3 +-- railties/guides/source/migrations.textile | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 49d7513448..b93c4f35ac 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -761,7 +761,6 @@ def subclasses end
- The +config+ method used at the top of +I18n::Railtie+ is defined on +Rails::Railtie+ and is defined like this: @@ -848,7 +847,7 @@ The +Collection+ class in +railties/lib/rails/initializable.rb+ inherits from +A The +initializers_chain+ method referenced in the +initializers_for+ method is defined like this: - + def initializers_chain initializers = Collection.new ancestors.reverse_each do | klass | diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index 9da12e2e18..6fcc3cf4a2 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -300,6 +300,7 @@ change_table :products do |t| t.rename :upccode, :upc_code end + removes the +description+ and +name+ columns, creates a +part_number+ column and adds an index on it. Finally it renames the +upccode+ column. This is the same as doing -- cgit v1.2.3 From 6eadf5d192f208d21f876603a0a1607fa80bb68a Mon Sep 17 00:00:00 2001 From: Jeff Dutil Date: Tue, 16 Aug 2011 23:04:16 -0400 Subject: Fix typo in i18n.textile header and remove extra whitespace. --- railties/guides/source/i18n.textile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index 0c8e4e974d..4b6b08bcec 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -1,4 +1,4 @@ -lh2. Rails Internationalization (I18n) API +h2. Rails Internationalization (I18n) API The Ruby I18n (shorthand for _internationalization_) gem which is shipped with Ruby on Rails (starting from Rails 2.2) provides an easy-to-use and extensible framework for *translating your application to a single custom language* other than English or for *providing multi-language support* in your application. @@ -796,7 +796,6 @@ h5. Active Support Methods * +Array#to_sentence+ uses format settings as given in the "support.array":https://github.com/rails/rails/blob/master/activesupport/lib/active_support/locale/en.yml#L30 scope. - h3. Customize your I18n Setup h4. Using Different Backends -- cgit v1.2.3 From 6783ce0de4511e2568765f2e4919758d70690391 Mon Sep 17 00:00:00 2001 From: Jeff Dutil Date: Tue, 16 Aug 2011 23:35:40 -0400 Subject: Updates to remove extra whitespaces and notably fix a whitespace issue with ajax_on_rails causing a code block not to render the entire block properly. --- railties/guides/source/action_view_overview.textile | 1 - railties/guides/source/active_model_basics.textile | 1 - railties/guides/source/active_record_basics.textile | 1 - railties/guides/source/ajax_on_rails.textile | 8 +------- railties/guides/source/api_documentation_guidelines.textile | 2 -- railties/guides/source/asset_pipeline.textile | 4 ---- railties/guides/source/caching_with_rails.textile | 2 -- railties/guides/source/contributing_to_ruby_on_rails.textile | 1 - railties/guides/source/form_helpers.textile | 1 - railties/guides/source/getting_started.textile | 2 -- 10 files changed, 1 insertion(+), 22 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile index d40e0840ce..5a1e8b1247 100644 --- a/railties/guides/source/action_view_overview.textile +++ b/railties/guides/source/action_view_overview.textile @@ -478,7 +478,6 @@ javascript_include_tag :monkey # => - h5. register_stylesheet_expansion Register one or more stylesheet files to be included when symbol is passed to +stylesheet_link_tag+. This method is typically intended to be called from plugin initialization to register stylesheet files that the plugin installed in +public/stylesheets+. diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index f3a2b2edbc..3c19fb5177 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -168,7 +168,6 @@ Track what was the previous value of the attribute. person.first_name_was #=> "First Name" - Track both previous and current value of the changed attribute. Returns an array if changed else returns nil #attr_name_change diff --git a/railties/guides/source/active_record_basics.textile b/railties/guides/source/active_record_basics.textile index 3e46e7df9f..cab8c80866 100644 --- a/railties/guides/source/active_record_basics.textile +++ b/railties/guides/source/active_record_basics.textile @@ -204,7 +204,6 @@ Likewise, once retrieved an Active Record object can be destroyed which removes user.destroy - h3. Validations Active Record allows you to validate the state of a model before it gets written into the database. There are several methods that you can use to check your models and validate that an attribute value is not empty, is unique and not already in the database, follows a specific format and many more. You can learn more about validations in the "Active Record Validations and Callbacks guide":active_record_validations_callbacks.html#validations-overview. diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile index 8b72e20c33..77f7661deb 100644 --- a/railties/guides/source/ajax_on_rails.textile +++ b/railties/guides/source/ajax_on_rails.textile @@ -24,16 +24,12 @@ h4. Standard HTML communication vs AJAX How do 'standard' and AJAX requests differ, why does this matter for understanding AJAX on Rails (tie in for *_remote helpers, the next section) - - - - - h3. Built-in Rails Helpers Rails' JavaScript framework of choice is "Prototype":http://www.prototypejs.org. Prototype is a generic-purpose JavaScript framework that aims to ease the development of dynamic web applications by offering DOM manipulation, AJAX and other JavaScript functionality ranging from utility functions to object oriented constructs. It is not specifically written for any language, so Rails provides a set of helpers to enable seamless integration of Prototype with your Rails views. To get access to these helpers, all you have to do is to include the prototype framework in your pages - typically in your master layout, application.html.erb - like so: + javascript_include_tag 'prototype' @@ -59,7 +55,6 @@ link_to_remote "Add to cart", * The very first parameter, a string, is the text of the link which appears on the page. - * The second parameter, the +options+ hash is the most interesting part as it has the AJAX specific stuff: ** *:url* This is the only parameter that is always required to generate the simplest remote link (technically speaking, it is not required, you can pass an empty +options+ hash to +link_to_remote+ - but in this case the URL used for the POST request will be equal to your current URL which is probably not your intention). This URL points to your AJAX action handler. The URL is typically specified by Rails REST view helpers, but you can use the +url_for+ format too. ** *:update* Specifying a DOM id of the element we would like to update. The above example demonstrates the simplest way of accomplishing this - however, we are in trouble if the server responds with an error message because that will be injected into the page too! However, Rails has a solution for this situation: @@ -193,7 +188,6 @@ end What happens here is that by specifying the Content-Type header variable, we instruct the browser to evaluate the text we are sending over (rather than displaying it as plain text, which is the default behavior). - h3. Testing JavaScript JavaScript testing reminds me the definition of the world 'classic' by Mark Twain: "A classic is something that everybody wants to have read and nobody wants to read." It's similar with JavaScript testing: everyone would like to have it, yet it's not done by too much developers as it is tedious, complicated, there is a proliferation of tools and no consensus/accepted best practices, but we will nevertheless take a stab at it: diff --git a/railties/guides/source/api_documentation_guidelines.textile b/railties/guides/source/api_documentation_guidelines.textile index 9c4df2d6b8..3ebf0e10f1 100644 --- a/railties/guides/source/api_documentation_guidelines.textile +++ b/railties/guides/source/api_documentation_guidelines.textile @@ -106,7 +106,6 @@ routes.rb # NO RAILS_ROOT/config/routes.rb # NO - h3. Fonts h4. Fixed-width Font @@ -188,4 +187,3 @@ self.class_eval %{ h3. Changelog * July 17, 2010: ported from the docrails wiki and revised by "Xavier Noria":credits.html#fxn - diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 74a9e497f2..8094ba18f2 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -27,7 +27,6 @@ config.assets.enabled = false It is recommended that you use the defaults for all new apps. - h4. Main Features The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser must make to render a web page. While Rails already has a feature to concatenate these types of assetsi -- by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+ -- many people do not use it. @@ -80,7 +79,6 @@ More reading: * "Optimize caching":http://code.google.com/speed/page-speed/docs/caching.html * "Revving Filenames: don’t use querystring":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/ - h3. How to Use the Asset Pipeline In previous versions of Rails, all assets were located in subdirectories of +public+ such as +images+, +javascripts+ and +stylesheets+. With the asset pipeline, the preferred location for these assets is now the +app/assets+ directory. Files in this directory are served by the Sprockets middleware included in the sprockets gem. @@ -324,7 +322,6 @@ When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia. TODO: Apache instructions - h3. Customizing the Pipeline @@ -372,7 +369,6 @@ To enable this, pass a +new+ Object to the config option in +application.rb+: config.assets.css_compressor = Transformer.new - h4. Changing the _assets_ Path The public path that Sprockets uses by default is +/assets+. diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile index ae56911441..693303950d 100644 --- a/railties/guides/source/caching_with_rails.textile +++ b/railties/guides/source/caching_with_rails.textile @@ -404,7 +404,6 @@ h3. Further reading * "Scaling Rails Screencasts":http://railslab.newrelic.com/scaling-rails - h3. Changelog * Feb 17, 2011: Document 3.0.0 changes to ActiveSupport::Cache @@ -415,4 +414,3 @@ h3. Changelog * December 27, 2008: Typo fixes * November 23, 2008: Incremental updates with various suggested changes and formatting cleanup * September 15, 2008: Initial version by Aditya Chadha - diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index e6ec061c9a..4706725bb6 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -104,7 +104,6 @@ $ cd railties $ TEST_DIR=generators rake test - h4. Warnings The test suite runs with warnings enabled. Ideally Ruby on Rails should issue no warning, but there may be a few, and also some from third-party libraries. Please ignore (or fix!) them if any, and submit patches that do not issue new warnings. diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index bf2a7369a7..c277f5723a 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -342,7 +342,6 @@ output: When parsing POSTed data, Rails will take into account the special +_method+ parameter and acts as if the HTTP method was the one specified inside it ("PUT" in this example). - h3. Making Select Boxes with Ease Select boxes in HTML require a significant amount of markup (one +OPTION+ element for each option to choose from), therefore it makes the most sense for them to be dynamically generated. diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 3cca383616..092ca90a30 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -116,7 +116,6 @@ need to know anything about them to continue with this guide. * Active Support * Railties - h5. Action Pack Action Pack is a single gem that contains Action Controller, Action View and @@ -1633,7 +1632,6 @@ Authentication challenge !images/challenge.png(Basic HTTP Authentication Challenge)! - h3. Building a Multi-Model Form Another feature of your average blog is the ability to tag posts. To implement -- cgit v1.2.3 From 3b5eb11664b8257d35dced58f1d65e34fa4a6c1f Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 17 Aug 2011 14:37:27 -0700 Subject: fixes generation of the AR querying guide --- railties/guides/source/active_record_querying.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 8ea06d28aa..4e77a6e803 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -560,6 +560,7 @@ Client.where("orders_count > 10").order(:name).reverse_order The SQL that would be executed: + SELECT * FROM clients WHERE orders_count > 10 ORDER BY name DESC @@ -571,6 +572,7 @@ Client.where("orders_count > 10").reverse_order The SQL that would be executed: + SELECT * FROM clients WHERE orders_count > 10 ORDER BY clients.id DESC @@ -621,8 +623,6 @@ You're then responsible for dealing with the conflict by rescuing the exception NOTE: You must ensure that your database schema defaults the +lock_version+ column to +0+. -
- This behavior can be turned off by setting ActiveRecord::Base.lock_optimistically = false. To override the name of the +lock_version+ column, +ActiveRecord::Base+ provides a class method called +set_locking_column+: -- cgit v1.2.3 From 129ad7226d32b19fac1aca2ebccd570b3382d6d5 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 20 Aug 2011 00:17:37 +0530 Subject: mailer guide: fixes indentation, and use fixed width fonts wherever necessary --- .../guides/source/action_mailer_basics.textile | 57 ++++++++++------------ 1 file changed, 26 insertions(+), 31 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile index 0941b06cfe..142b9dba7e 100644 --- a/railties/guides/source/action_mailer_basics.textile +++ b/railties/guides/source/action_mailer_basics.textile @@ -8,7 +8,7 @@ WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not h3. Introduction -Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from +ActionMailer::Base+ and live in +app/mailers+. Those mailers have associated views that appear alongside controller views in +app/views+. +Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from +ActionMailer::Base+ and live in +app/mailers+. Those mailers have associated views that appear alongside controller views in +app/views+. h3. Sending Emails @@ -48,10 +48,8 @@ class UserMailer < ActionMailer::Base def welcome_email(user) @user = user @url = "http://example.com/login" - mail(:to => user.email, - :subject => "Welcome to My Awesome Site") + mail(:to => user.email, :subject => "Welcome to My Awesome Site") end - end @@ -142,17 +140,17 @@ end This provides a much simpler implementation that does not require the registering of observers and the like. -The method +welcome_email+ returns a Mail::Message object which can then just be told +deliver+ to send itself out. +The method +welcome_email+ returns a Mail::Message object which can then just be told +deliver+ to send itself out. NOTE: In previous versions of Rails, you would call +deliver_welcome_email+ or +create_welcome_email+. This has been deprecated in Rails 3.0 in favour of just calling the method name itself. -WARNING: Sending out one email should only take a fraction of a second, if you are planning on sending out many emails, or you have a slow domain resolution service, you might want to investigate using a background process like delayed job. +WARNING: Sending out an email should only take a fraction of a second, but if you are planning on sending out many emails, or you have a slow domain resolution service, you might want to investigate using a background process like Delayed Job. h4. Auto encoding header values Action Mailer now handles the auto encoding of multibyte characters inside of headers and bodies. -If you are using UTF-8 as your character set, you do not have to do anything special, just go ahead and send in UTF-8 data to the address fields, subject, keywords, filenames or body of the email and ActionMailer will auto encode it into quoted printable for you in the case of a header field or Base64 encode any body parts that are non US-ASCII. +If you are using UTF-8 as your character set, you do not have to do anything special, just go ahead and send in UTF-8 data to the address fields, subject, keywords, filenames or body of the email and Action Mailer will auto encode it into quoted printable for you in the case of a header field or Base64 encode any body parts that are non US-ASCII. For more complex examples such as defining alternate character sets or self encoding text first, please refer to the Mail library. @@ -213,7 +211,7 @@ NOTE: If you specify an encoding, Mail will assume that your content is already h5. Making Inline Attachments -ActionMailer 3.0 makes inline attachments, which involved a lot of hacking in pre 3.0 versions, much simpler and trivial as they should be. +Action Mailer 3.0 makes inline attachments, which involved a lot of hacking in pre 3.0 versions, much simpler and trivial as they should be. * Firstly, to tell Mail to turn an attachment into an inline attachment, you just call #inline on the attachments method within your Mailer: @@ -245,15 +243,15 @@ h5. Sending Email To Multiple Recipients It is possible to send email to one or more recipients in one email (for e.g. informing all admins of a new signup) by setting the list of emails to the :to key. The list of emails can be an array of email addresses or a single string with the addresses separated by commas. - class AdminMailer < ActionMailer::Base - default :to => Admin.all.map(&:email), - :from => "notification@example.com" +class AdminMailer < ActionMailer::Base + default :to => Admin.all.map(&:email), + :from => "notification@example.com" - def new_registration(user) - @user = user - mail(:subject => "New User Signup: #{@user.email}") - end + def new_registration(user) + @user = user + mail(:subject => "New User Signup: #{@user.email}") end +end The same format can be used to set carbon copy (Cc:) and blind carbon copy (Bcc:) recipients, by using the :cc and :bcc keys respectively. @@ -264,12 +262,11 @@ Sometimes you wish to show the name of the person instead of just their email ad to format the email address in the format "Name <email>". - def welcome_email(user) - @user = user - email_with_name = "#{@user.name} <#{@user.email}>" - mail(:to => email_with_name, - :subject => "Welcome to My Awesome Site") - end +def welcome_email(user) + @user = user + email_with_name = "#{@user.name} <#{@user.email}>" + mail(:to => email_with_name, :subject => "Welcome to My Awesome Site") +end h4. Mailer Views @@ -289,9 +286,7 @@ class UserMailer < ActionMailer::Base :subject => "Welcome to My Awesome Site", :template_path => 'notifications', :template_name => 'another') - end end - end @@ -461,14 +456,14 @@ h3. Action Mailer Configuration The following configuration options are best made in one of the environment files (environment.rb, production.rb, etc...) -|template_root|Determines the base from which template references will be made.| -|logger|Generates information on the mailing run if available. Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.| -|smtp_settings|Allows detailed configuration for :smtp delivery method:
  • :address - Allows you to use a remote mail server. Just change it from its default "localhost" setting.
  • :port - On the off chance that your mail server doesn't run on port 25, you can change it.
  • :domain - If you need to specify a HELO domain, you can do it here.
  • :user_name - If your mail server requires authentication, set the username in this setting.
  • :password - If your mail server requires authentication, set the password in this setting.
  • :authentication - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of :plain, :login, :cram_md5.
| -|sendmail_settings|Allows you to override options for the :sendmail delivery method.
  • :location - The location of the sendmail executable. Defaults to /usr/sbin/sendmail.
  • :arguments - The command line arguments to be passed to sendmail. Defaults to -i -t.
| -|raise_delivery_errors|Whether or not errors should be raised if the email fails to be delivered.| -|delivery_method|Defines a delivery method. Possible values are :smtp (default), :sendmail, :file and :test.| -|perform_deliveries|Determines whether deliveries are actually carried out when the +deliver+ method is invoked on the Mail message. By default they are, but this can be turned off to help functional testing.| -|deliveries|Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful for unit and functional testing.| +|+template_root+|Determines the base from which template references will be made.| +|+logger+|Generates information on the mailing run if available. Can be set to +nil+ for no logging. Compatible with both Ruby's own +Logger+ and +Log4r+ loggers.| +|+smtp_settings+|Allows detailed configuration for :smtp delivery method:
  • :address - Allows you to use a remote mail server. Just change it from its default "localhost" setting.
  • :port - On the off chance that your mail server doesn't run on port 25, you can change it.
  • :domain - If you need to specify a HELO domain, you can do it here.
  • :user_name - If your mail server requires authentication, set the username in this setting.
  • :password - If your mail server requires authentication, set the password in this setting.
  • :authentication - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of :plain, :login, :cram_md5.
| +|+sendmail_settings+|Allows you to override options for the :sendmail delivery method.
  • :location - The location of the sendmail executable. Defaults to /usr/sbin/sendmail.
  • :arguments - The command line arguments to be passed to sendmail. Defaults to -i -t.
| +|+raise_delivery_errors+|Whether or not errors should be raised if the email fails to be delivered.| +|+delivery_method+|Defines a delivery method. Possible values are :smtp (default), :sendmail, :file and :test.| +|+perform_deliveries+|Determines whether deliveries are actually carried out when the +deliver+ method is invoked on the Mail message. By default they are, but this can be turned off to help functional testing.| +|+deliveries+|Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful for unit and functional testing.| h4. Example Action Mailer Configuration -- cgit v1.2.3 From 0b3b91cdcdfd54fc4a9e9bcb6be95ff487724e25 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 19 Aug 2011 19:45:55 -0300 Subject: Document debugging assets set by default for dev and test envs in the asset_pipeline guide. --- railties/guides/source/asset_pipeline.textile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 8094ba18f2..34ab00e80d 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -247,6 +247,8 @@ When the +debug_assets+ parameter is set, this line is expanded out into three s This allows the individual parts of an asset to be rendered and debugged separately. +NOTE. Assets debugging is turned on by default in development and test environments. + h3. In Production In the production environment, assets are served slightly differently. -- cgit v1.2.3 From 7444c620cfa88d4ffade121bbbad0d4699c36f8a Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 20 Aug 2011 23:27:31 +0530 Subject: minor change in the 3.1 release notes --- railties/guides/source/3_1_release_notes.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index ba36735a0b..087926f98d 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -115,7 +115,7 @@ h4. Action Controller * URL parameters which return +nil+ for +to_param+ are now removed from the query string. -* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. +* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized in config/initializers/wrap_parameters.rb. * Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to +false+ will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller). -- cgit v1.2.3 From 95bece9155c46a2273a3febc3a2e176b8c15df8f Mon Sep 17 00:00:00 2001 From: Joost Baaij Date: Mon, 22 Aug 2011 00:10:01 +0300 Subject: Removed my name from the changelog as the amount of blogspam became ridiculous. When will docrails be back? :-p --- railties/guides/source/getting_started.textile | 1 - 1 file changed, 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 092ca90a30..755f59f8f9 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1890,7 +1890,6 @@ h3. Changelog * April 26, 2011: Change migration code from +up+, +down+ pair to +change+ method by "Prem Sichanugrist":http://sikachu.com * April 11, 2011: Change scaffold_controller generator to create format block for JSON instead of XML by "Sebastian Martinez":http://www.wyeworks.com -* August 30, 2010: Minor editing after Rails 3 release by "Joost Baaij":http://www.spacebabies.nl * July 12, 2010: Fixes, editing and updating of code samples by "Jaime Iniesta":http://jaimeiniesta.com * May 16, 2010: Added a section on configuration gotchas to address common encoding problems that people might have by "Yehuda Katz":http://www.yehudakatz.com * April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com -- cgit v1.2.3 From 18b2223b3290c4b3daa310edfc06b4d51161c312 Mon Sep 17 00:00:00 2001 From: "Andrey A.I. Sitnik" Date: Mon, 22 Aug 2011 09:36:36 +1100 Subject: Allow to debug assets by config.assets.debug --- railties/guides/source/asset_pipeline.textile | 2 +- railties/lib/rails/application/configuration.rb | 1 + .../rails/app/templates/config/environments/development.rb.tt | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 34ab00e80d..012149c40e 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -224,7 +224,7 @@ If any of the files in the manifest have changed between requests, the server re h4. Debugging Assets -You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL and Sprockets expands the lines which load the assets. For example, if you had an +app/assets/javascripts/application.js+ file containing these lines: +You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL or set +config.assets.debug+ and Sprockets expands the lines which load the assets. For example, if you had an +app/assets/javascripts/application.js+ file containing these lines: //= require "projects" diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index cd850b6a75..f1add68890 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -38,6 +38,7 @@ module Rails @assets.precompile = [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ] @assets.prefix = "/assets" @assets.version = '' + @assets.debug = false @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] @assets.js_compressor = nil diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index 3e0c29a587..47078e3af9 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -29,4 +29,7 @@ # Do not compress assets config.assets.compress = false + + # Expands the lines which load the assets + config.assets.debug = true end -- cgit v1.2.3 From 35c8a896fc75c222834e1324fe4710c1ba2645c4 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 21 Aug 2011 15:55:15 -0700 Subject: Merge pull request #2620 from cesario/3-1-0 Fix CI and rename 1 misleading test case. --- railties/test/generators/app_generator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index fb7ebaa1fa..2415195a17 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -189,7 +189,7 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "test/performance/browsing_test.rb" end - def test_generator_if_skip_active_record_is_given + def test_generator_if_skip_sprockets_is_given run_generator [destination_root, "--skip-sprockets"] assert_file "config/application.rb" do |content| assert_match(/#\s+require\s+["']sprockets\/railtie["']/, content) -- cgit v1.2.3 From 44f0d94469fb6c5d400776c3307b16fb8e4d1eb1 Mon Sep 17 00:00:00 2001 From: Andrey Ognevsky Date: Sun, 21 Aug 2011 01:25:11 +0300 Subject: Add Destroy Alias * Added destroy alias to rails generator * add alias info for destroy command * Updated command line guides --- railties/guides/source/command_line.textile | 2 ++ railties/lib/rails/commands.rb | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 6d5132a1bf..f6b33d283c 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -325,6 +325,8 @@ h4. +rails destroy+ Think of +destroy+ as the opposite of +generate+. It'll figure out what generate did, and undo it. +You can also use the alias "d" to invoke the destroy command: rails d. + $ rails generate model Oops exists app/models/ diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index a21484e5cb..ada150ceec 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -4,6 +4,7 @@ ARGV << '--help' if ARGV.empty? aliases = { "g" => "generate", + "d" => "destroy", "c" => "console", "s" => "server", "db" => "dbconsole", @@ -87,7 +88,7 @@ The most common rails commands are: In addition to those, there are: application Generate the Rails application code - destroy Undo code generated with "generate" + destroy Undo code generated with "generate" (short-cut alias: "d") benchmarker See how fast a piece of code runs profiler Get profile information from a piece of code plugin Install a plugin -- cgit v1.2.3 From d17954c7d826b64ae7d04aac4db6f919d5e22589 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Mon, 22 Aug 2011 23:39:17 -0500 Subject: Add destroy alias to engines --- railties/lib/rails/engine/commands.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/engine/commands.rb b/railties/lib/rails/engine/commands.rb index 3b0920e213..b71119af77 100644 --- a/railties/lib/rails/engine/commands.rb +++ b/railties/lib/rails/engine/commands.rb @@ -3,7 +3,8 @@ require 'active_support/core_ext/object/inclusion' ARGV << '--help' if ARGV.empty? aliases = { - "g" => "generate" + "g" => "generate", + "d" => "destroy" } command = ARGV.shift @@ -30,7 +31,7 @@ Usage: rails COMMAND [ARGS] The common rails commands available for engines are: generate Generate new code (short-cut alias: "g") - destroy Undo code generated with "generate" + destroy Undo code generated with "generate" (short-cut alias: "d") All commands can be run with -h for more information. EOT -- cgit v1.2.3 From c46befbce300722650e324047a9342f628acc36d Mon Sep 17 00:00:00 2001 From: Joost Baaij Date: Tue, 23 Aug 2011 14:17:29 +0200 Subject: Revert "Removed my name from the changelog as the amount of blogspam became ridiculous. " This reverts commit 95bece9155c46a2273a3febc3a2e176b8c15df8f. --- railties/guides/source/getting_started.textile | 1 + 1 file changed, 1 insertion(+) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 755f59f8f9..092ca90a30 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1890,6 +1890,7 @@ h3. Changelog * April 26, 2011: Change migration code from +up+, +down+ pair to +change+ method by "Prem Sichanugrist":http://sikachu.com * April 11, 2011: Change scaffold_controller generator to create format block for JSON instead of XML by "Sebastian Martinez":http://www.wyeworks.com +* August 30, 2010: Minor editing after Rails 3 release by "Joost Baaij":http://www.spacebabies.nl * July 12, 2010: Fixes, editing and updating of code samples by "Jaime Iniesta":http://jaimeiniesta.com * May 16, 2010: Added a section on configuration gotchas to address common encoding problems that people might have by "Yehuda Katz":http://www.yehudakatz.com * April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com -- cgit v1.2.3 From 707378c4892a4666c8b7ed73bef577338bca3c38 Mon Sep 17 00:00:00 2001 From: Joost Baaij Date: Tue, 23 Aug 2011 14:18:06 +0200 Subject: removed the link to my blog to help stop endless comments --- railties/guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 092ca90a30..d2bfcfdbb4 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1890,7 +1890,7 @@ h3. Changelog * April 26, 2011: Change migration code from +up+, +down+ pair to +change+ method by "Prem Sichanugrist":http://sikachu.com * April 11, 2011: Change scaffold_controller generator to create format block for JSON instead of XML by "Sebastian Martinez":http://www.wyeworks.com -* August 30, 2010: Minor editing after Rails 3 release by "Joost Baaij":http://www.spacebabies.nl +* August 30, 2010: Minor editing after Rails 3 release by Joost Baaij * July 12, 2010: Fixes, editing and updating of code samples by "Jaime Iniesta":http://jaimeiniesta.com * May 16, 2010: Added a section on configuration gotchas to address common encoding problems that people might have by "Yehuda Katz":http://www.yehudakatz.com * April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com -- cgit v1.2.3 From 11146f1485ac83950c1079a458bd5fbae6ab405b Mon Sep 17 00:00:00 2001 From: Brian Morearty Date: Tue, 23 Aug 2011 21:34:43 -0700 Subject: Remove extra word from sentence in initialization guide. --- railties/guides/source/initialization.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index b93c4f35ac..9cc4dd5f04 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -1,6 +1,6 @@ h2. The Rails Initialization Process -This guide explains the internals of the initialization process in Rails works as of Rails 3.1. It is an extremely in-depth guide and recommended for advanced Rails developers. +This guide explains the internals of the initialization process in Rails as of Rails 3.1. It is an extremely in-depth guide and recommended for advanced Rails developers. * Using +rails server+ * Using Passenger -- cgit v1.2.3 From a5e925c1d35ff10a22a98841f6a02925d4263947 Mon Sep 17 00:00:00 2001 From: Bogdan Gusiev Date: Wed, 24 Aug 2011 10:25:29 +0300 Subject: Add strict validation example to guides --- railties/guides/source/active_model_basics.textile | 7 +++++-- railties/guides/source/active_record_validations_callbacks.textile | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index f3a2b2edbc..7d435456bd 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -184,20 +184,23 @@ Validations module adds the ability to class objects to validate them in Active class Person include ActiveModel::Validations - attr_accessor :name, :email + attr_accessor :name, :email, :token validates :name, :presence => true validates_format_of :email, :with => /^([^\s]+)((?:[-a-z0-9]\.)[a-z]{2,})$/i + validates! :token, :presence => true end -person = Person.new +person = Person.new(:token => "2b1f325") person.valid? #=> false person.name = 'vishnu' person.email = 'me' person.valid? #=> false person.email = 'me@vishnuatrai.com' person.valid? #=> true +person.token = nil +person.valid? #=> raises ActiveModel::StrictValidationFailed h3. Changelog diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index aba3224ba7..18fc77c660 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -1270,6 +1270,7 @@ The +after_commit+ and +after_rollback+ callbacks are guaranteed to be called fo h3. Changelog +* August 24, 2011: Add strict validation usage example. "Bogdan Gusiev":http://gusiev.com * February 17, 2011: Add description of transaction callbacks. * July 20, 2010: Fixed typos and rephrased some paragraphs for clarity. "Jaime Iniesta":http://jaimeiniesta.com * May 24, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com -- cgit v1.2.3 From 827cdae6fb5e21056b68ab8a89047ae82738871f Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Mon, 22 Aug 2011 23:19:25 -0500 Subject: Add config.allow_debugging option to determine if the debug_assets query param can be passed by user --- railties/lib/rails/application/configuration.rb | 13 +++---- .../config/environments/development.rb.tt | 3 ++ .../app/templates/config/environments/test.rb.tt | 3 ++ railties/test/application/assets_test.rb | 42 ++++++++++++++++++++++ 4 files changed, 55 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index f1add68890..c4a02ba5c0 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -33,12 +33,13 @@ module Rails @cache_store = [ :file_store, "#{root}/tmp/cache/" ] @assets = ActiveSupport::OrderedOptions.new - @assets.enabled = false - @assets.paths = [] - @assets.precompile = [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ] - @assets.prefix = "/assets" - @assets.version = '' - @assets.debug = false + @assets.enabled = false + @assets.paths = [] + @assets.precompile = [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ] + @assets.prefix = "/assets" + @assets.version = '' + @assets.debug = false + @assets.allow_debugging = false @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] @assets.js_compressor = nil diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index 47078e3af9..33f9939ffe 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -30,6 +30,9 @@ # Do not compress assets config.assets.compress = false + # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets + config.assets.allow_debugging = true + # Expands the lines which load the assets config.assets.debug = true end diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index 80198cc21e..8e33a65b2d 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -41,4 +41,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/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index a8d1382e94..1e6a93dbdf 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -135,5 +135,47 @@ module ApplicationTests assert_match "alert();", last_response.body assert_equal 200, last_response.status end + + test "assets are concatenated when debug is off and allow_debugging is off either if debug_assets param is provided" do + app_with_assets_in_view + + # config.assets.debug and config.assets.allow_debugging are false for production environment + ENV["RAILS_ENV"] = "production" + require "#{app_path}/config/environment" + + class ::PostsController < ActionController::Base ; end + + # the debug_assets params isn't used if allow_debugging is off + get '/posts?debug_assets=true' + assert_match /}, last_response.body + assert_not_match %r{}, last_response.body + end + + test "assets aren't concatened when allow_debugging is on and debug_assets params is true" do + app_file "config/initializers/allow_debugging.rb", "Rails.application.config.assets.allow_debugging = true" + + require "#{app_path}/config/environment" + + get '/posts?debug_assets=true' + assert_match %r{}, last_response.body + assert_match %r{}, last_response.body + end + end +end diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 1e6a93dbdf..a8d1382e94 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -135,47 +135,5 @@ module ApplicationTests assert_match "alert();", last_response.body assert_equal 200, last_response.status end - - test "assets are concatenated when debug is off and allow_debugging is off either if debug_assets param is provided" do - app_with_assets_in_view - - # config.assets.debug and config.assets.allow_debugging are false for production environment - ENV["RAILS_ENV"] = "production" - require "#{app_path}/config/environment" - - class ::PostsController < ActionController::Base ; end - - # the debug_assets params isn't used if allow_debugging is off - get '/posts?debug_assets=true' - assert_match /}, last_response.body - assert_not_match %r{}, last_response.body + assert_no_match %r{}, last_response.body end test "assets aren't concatened when allow_debugging is on and debug_assets params is true" do -- cgit v1.2.3 From 6bdf4a3829acd089adddfb2b534ed66d974b902a Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Wed, 24 Aug 2011 23:00:43 -0700 Subject: incorporate feedback from vijaydev and dasch to rephrase this to sound more natural, and some grammar fixes. --- railties/README.rdoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/README.rdoc b/railties/README.rdoc index eb7ed961e3..501541eb06 100644 --- a/railties/README.rdoc +++ b/railties/README.rdoc @@ -1,12 +1,12 @@ = Railties -- Gluing the Engine to the Rails -Railties is responsible to glue all frameworks together. Overall, it: +Railties is responsible for gluing all frameworks together. Overall, it: -* handles all the bootstrapping process for a Rails application; +* handles the bootstrapping process for a Rails application; -* manages rails command line interface; +* manages the +rails+ command line interface; -* provides Rails generators core; +* and provides Rails generators core. == Download -- cgit v1.2.3 From 1606b6c7e4af5ebc0bc705f3c4e4ea63b038ef14 Mon Sep 17 00:00:00 2001 From: Jared Tame Date: Tue, 23 Aug 2011 02:26:55 -0700 Subject: fixed 500 error message which is misleading by suggesting all rails apps have exception notifications by default --- railties/lib/rails/generators/rails/app/templates/public/500.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/public/500.html b/railties/lib/rails/generators/rails/app/templates/public/500.html index b80307fc16..b8e4d7c721 100644 --- a/railties/lib/rails/generators/rails/app/templates/public/500.html +++ b/railties/lib/rails/generators/rails/app/templates/public/500.html @@ -20,7 +20,7 @@

We're sorry, but something went wrong.

-

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

+

If you believe you've seen this page in error, please notify the site owner.

-- cgit v1.2.3 From 5acbc19f30b6d27ea9b131aa75bb23643d216088 Mon Sep 17 00:00:00 2001 From: Teng Siong Ong Date: Sat, 27 Aug 2011 14:31:24 -0500 Subject: remove misleading line on 500 error page. --- railties/lib/rails/generators/rails/app/templates/public/500.html | 1 - 1 file changed, 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/public/500.html b/railties/lib/rails/generators/rails/app/templates/public/500.html index b8e4d7c721..f3648a0dbc 100644 --- a/railties/lib/rails/generators/rails/app/templates/public/500.html +++ b/railties/lib/rails/generators/rails/app/templates/public/500.html @@ -20,7 +20,6 @@

We're sorry, but something went wrong.

-

If you believe you've seen this page in error, please notify the site owner.

-- cgit v1.2.3 From b5f68cc6fe70490367c5c144e933a87feb5df966 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov Date: Fri, 26 Aug 2011 18:34:57 +0300 Subject: Fixed typos and made minor changes in the Plugins guide. --- railties/guides/source/plugins.textile | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile index d3f9783fa6..e8bdfa7f1c 100644 --- a/railties/guides/source/plugins.textile +++ b/railties/guides/source/plugins.textile @@ -290,7 +290,7 @@ You can then return to the root directory (+cd ../..+) of your plugin and rerun
-Getting closer...now we will implement the code of the acts_as_yaffle method to make the tests pass. +Getting closer... Now we will implement the code of the acts_as_yaffle method to make the tests pass. # yaffle/lib/yaffle/acts_as_yaffle.rb @@ -322,7 +322,7 @@ When you run +rake+ you should see the tests all pass: h4. Add an Instance Method -This plugin will add a method named 'squawk' to any Active Record objects that call 'acts_as_yaffle'. The 'squawk' +This plugin will add a method named 'squawk' to any Active Record object that calls 'acts_as_yaffle'. The 'squawk' method will simply set the value of one of the fields in the database. To start out, write a failing test that shows the behavior you'd like: @@ -347,7 +347,7 @@ class ActsAsYaffleTest < Test::Unit::TestCase assert_equal "squawk! Hello World", hickwall.last_squawk end - def test_wickwalls_squawk_should_populate_last_tweeted_at + def test_wickwalls_squawk_should_populate_last_tweet wickwall = Wickwall.new wickwall.squawk("Hello World") assert_equal "squawk! Hello World", wickwall.last_tweet @@ -355,7 +355,7 @@ class ActsAsYaffleTest < Test::Unit::TestCase end -Run the test to make sure the last two tests fail the an error that contains "NoMethodError: undefined method `squawk'", +Run the test to make sure the last two tests fail with an error that contains "NoMethodError: undefined method `squawk'", then update 'acts_as_yaffle.rb' to look like this: @@ -400,11 +400,11 @@ the creation of generators can be found in the "Generators Guide":generators.htm h3. Publishing your Gem -Gem plugins in progress can be easily be shared from any Git repository. To share the Yaffle gem with others, simply -commit the code to a Git repository (like Github) and add a line to the Gemfile of the any application: +Gem plugins currently in development can easily be shared from any Git repository. To share the Yaffle gem with others, simply +commit the code to a Git repository (like Github) and add a line to the Gemfile of the application in question: -gem 'yaffle', :git => 'git://github.com/yaffle_watcher/yaffle.git' +gem 'yaffle', :git => 'git://github.com/yaffle_watcher/yaffle.git' After running +bundle install+, your gem functionality will be available to the application. @@ -426,12 +426,12 @@ require 'yaffle' You can test this by changing to the Rails application that you added the plugin to and starting a rails console. Once in the -console we can check to see if the String has an instance method of to_squawk. +console we can check to see if the String has an instance method to_squawk: $ cd my_app $ rails console -$ String.instance_methods.sort +$ "Rails plugins are easy!".to_squawk You can also remove the .gemspec, Gemfile and Gemfile.lock files as they will no longer be needed. @@ -445,9 +445,9 @@ The first step is to update the README file with detailed information about how * Your name * How to install * How to add the functionality to the app (several examples of common use cases) -* Warning, gotchas or tips that might help save users time +* Warnings, gotchas or tips that might help users and save them time -Once your README is solid, go through and add rdoc comments to all of the methods that developers will use. It's also customary to add '#:nodoc:' comments to those parts of the code that are not part of the public api. +Once your README is solid, go through and add rdoc comments to all of the methods that developers will use. It's also customary to add '#:nodoc:' comments to those parts of the code that are not included in the public api. Once your comments are good to go, navigate to your plugin directory and run: -- cgit v1.2.3 From 871696a01af853f10a33c4ff53f6d6ed795144b7 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Sun, 28 Aug 2011 23:08:06 +0300 Subject: Documentation fixes --- railties/guides/source/asset_pipeline.textile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 4fbdda4c07..554246acb3 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -29,7 +29,7 @@ It is recommended that you use the defaults for all new apps. h4. Main Features -The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser must make to render a web page. While Rails already has a feature to concatenate these types of assetsi -- by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+ -- many people do not use it. +The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser must make to render a web page. While Rails already has a feature to concatenate these types of assets -- by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+ -- many people do not use it. The default behavior in Rails 3.1 and onward is to concatenate all files into one master file each for JS and CSS. However, you can separate files or groups of files if required (see below). In production, an MD5 fingerprint is inserted into each filename so that the file is cached by the web browser but can be invalidated if the fingerprint is altered. @@ -133,7 +133,7 @@ Otherwise, Sprockets looks through the available paths until it finds a file tha If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme -- a method of embedding the image data directly into the CSS file -- you can use the +asset_data_uri+ helper. -#logo { background: url(<%= asset_data_uri 'logo.png' %>) +#logo { background: url(<%= asset_data_uri 'logo.png' %>) } This inserts a correctly-formatted data URI into the CSS source. @@ -143,7 +143,7 @@ h5. CSS and ERB If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then you can use the +asset_path+ helper in your CSS rules: -.class{background-image:<%= asset_path 'image.png' %>} +.class { background-image: <%= asset_path 'image.png' %> } This writes the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file, then that path is referenced. @@ -282,7 +282,7 @@ Rails comes bundled with a rake task to compile the manifests to files on disc. The rake task is: -rake assets:precompile +bundle exec rake assets:precompile Capistrano (v2.8.0+) has a recipe to handle this in deployment. Add the following line to +Capfile+: -- cgit v1.2.3 From 734792aaaab07cd7b4340b76ae66be3533088b11 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 28 Aug 2011 16:41:15 -0700 Subject: Merge pull request #2723 from guilleiguaran/3-1-0-changelogs Update changelogs for Rails 3.1.0 --- railties/CHANGELOG | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 76453f4e9a..6ed76974b4 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -12,6 +12,19 @@ *Rails 3.1.0 (unreleased)* +* The default database schema file is written as UTF-8. [Aaron Patterson] + +* Generated apps with --dev or --edge flags depend on git versions of +sass-rails and coffee-rails. [Santiago Pastorino] + +* Rack::Sendfile middleware is used only if x_sendfile_header is present. [Santiago Pastorino] + +* Add JavaScript Runtime name to the Rails Info properties. [DHH] + +* Make pp enabled by default in Rails console. [Akira Matsuda] + +* Add alias `r` for rails runner. [Jordi Romero] + * Make sprockets/railtie require explicit and add --skip-sprockets to app generator [José Valim] * Added Rails.groups that automatically handles Rails.env and ENV["RAILS_GROUPS"] [José Valim] -- cgit v1.2.3 From 2350fecd2251584d770afc4bd1764b3fe526ff70 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 30 Aug 2011 13:48:16 -0700 Subject: adds the asset pipeline guide to the index --- railties/guides/source/asset_pipeline.textile | 2 +- railties/guides/source/index.html.erb | 4 ++++ railties/guides/source/layout.html.erb | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 554246acb3..2695ba9ec1 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -1,6 +1,6 @@ h2. Asset Pipeline -This guide covers the ideology of the asset pipeline introduced in Rails 3.1. +This guide covers the asset pipeline introduced in Rails 3.1. By referring to this guide you will be able to: * Understand what the asset pipeline is and what it does diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb index 684251962c..b7813086d7 100644 --- a/railties/guides/source/index.html.erb +++ b/railties/guides/source/index.html.erb @@ -131,6 +131,10 @@ Ruby on Rails Guides <%= guide("Caching with Rails", 'caching_with_rails.html', :work_in_progress => true) do %>

Various caching techniques provided by Rails.

<% end %> + +<%= guide('Asset Pipeline', 'asset_pipeline.html') do %> +

This guide documents the asset pipeline.

+<% end %>

Extending Rails

diff --git a/railties/guides/source/layout.html.erb b/railties/guides/source/layout.html.erb index 5dcac8e74c..5f8ee57517 100644 --- a/railties/guides/source/layout.html.erb +++ b/railties/guides/source/layout.html.erb @@ -5,7 +5,7 @@ -<%= yield(:page_title) || 'Ruby on Rails guides' %> +<%= yield(:page_title) || 'Ruby on Rails Guides' %> @@ -71,6 +71,7 @@
Configuring Rails Applications
Rails Command Line Tools and Rake Tasks
Caching with Rails
+
Asset Pipeline
Extending Rails
The Basics of Creating Rails Plugins
-- cgit v1.2.3 From 84dad446c6a23a15f67b9d558e8039891a008bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Mej=C3=ADa?= Date: Sat, 27 Aug 2011 23:10:25 -0500 Subject: Adding first_or_create, first_or_create!, first_or_new and first_or_build to Active Record. This let's you write things like: User.where(:first_name => "Scarlett").first_or_create!(:last_name => "Johansson", :hot => true) Related to #2420. --- .../guides/source/active_record_querying.textile | 75 ++++++++++++++++++++-- 1 file changed, 68 insertions(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 4e77a6e803..37874c2ea1 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -1018,23 +1018,84 @@ If you want to find both by name and locked, you can chain these finders togethe WARNING: Up to and including Rails 3.1, when the number of arguments passed to a dynamic finder method is lesser than the number of fields, say Client.find_by_name_and_locked("Ryan"), the behavior is to pass +nil+ as the missing argument. This is *unintentional* and this behavior will be changed in Rails 3.2 to throw an +ArgumentError+. -There's another set of dynamic finders that let you find or create/initialize objects if they aren't found. These work in a similar fashion to the other finders and can be used like +find_or_create_by_first_name(params[:first_name])+. Using this will first perform a find and then create if the find returns +nil+. The SQL looks like this for +Client.find_or_create_by_first_name("Ryan")+: +h3. Find or build a new object + +It's common that you need to find a record or create it if it doesn't exist. You can do that with the +first_or_create+ and +first_or_create!+ methods. + +h4. +first_or_create+ + +The +first_or_create+ method checks whether +first+ returns +nil+ or not. If it does return +nil+, then +create+ is called. This is very powerful when coupled with the +where+ method. Let's see an example. + +Suppose you want to find a client named 'Andy', and if there's none, create one and additionally set his +locked+ attribute to false. You can do so by running: + + +Client.where(:first_name => 'Andy').first_or_create(:locked => false) +# => + + +The SQL generated by this method looks like this: -SELECT * FROM clients WHERE (clients.first_name = 'Ryan') LIMIT 1 +SELECT * FROM clients WHERE (clients.first_name = 'Andy') LIMIT 1 BEGIN -INSERT INTO clients (first_name, updated_at, created_at, orders_count, locked) - VALUES('Ryan', '2008-09-28 15:39:12', '2008-09-28 15:39:12', 0, '0') +INSERT INTO clients (created_at, first_name, locked, orders_count, updated_at) VALUES ('2011-08-30 05:22:57', 'Andy', 0, NULL, '2011-08-30 05:22:57') COMMIT -+find_or_create+'s sibling, +find_or_initialize+, will find an object and if it does not exist will act similarly to calling +new+ with the arguments you passed in. For example: ++first_or_create+ returns either the record that already existed or the new record. In our case, we didn't already have a client named Andy so the record was created an returned. + +The new record might not be saved to the database; that depends on whether validations passed or not (just like +create+). + +It's also worth noting that +first_or_create+ takes into account the arguments of the +where+ method. In the example above we didn't explicitly pass a +:first_name => 'Andy'+ argument to +first_or_create+. However, that was used when creating the new record because it was already passed before to the +where+ method. + +NOTE: On previous versions of Rails you could do a similar thing with the +find_or_create_by+ method. Following our example, you could also run something like +Client.find_or_create_by_first_name(:first_name => "Andy", :locked => false)+. This method still works, but it's encouraged to use +first_or_create+ because it's more explicit on what arguments are used to _find_ the record and what arguments are used to _create_ it, resulting in less confusion overall. + +h4. +first_or_create!+ + +You can also use +first_or_create!+ to raise an exception if the new record is invalid. Validations are not covered on this guide, but let's assume for a moment that you temporarily add + + + validates :orders_count, :presence => true + + +to your +Client+ model. If you try to create a new +Client+ without passing an +orders_count+, the record will be invalid and an exception will be raised: + + +Client.where(:first_name => 'Andy').first_or_create!(:locked => false) +# => ActiveRecord::RecordInvalid: Validation failed: Orders count can't be blank + + +NOTE: Be sure to check the extensive *Active Record Validations and Callbacks Guide* for more information about validations. + +h4. +first_or_new+ + +The +first_or_new+ method will work just like +first_or_create+ but it will not call +create+ but the +new+. This means that a new model instance will be created in memory but won't be saved to the database. Continuing with the +first_or_create+ example, we now want the client named 'Nick': + + +nick = Client.where(:first_name => 'Nick').first_or_new(:locked => false) +# => + +nick.persisted? +# => false + +nick.new_record? +# => true + + +Because the object is not yet stored in the database, the SQL generated looks like this: + + +SELECT * FROM clients WHERE (clients.first_name = 'Nick') LIMIT 1 + + +When you want to save it to the database, just call +save+: -client = Client.find_or_initialize_by_first_name('Ryan') +nick.save +# => true -will either assign an existing client object with the name "Ryan" to the client local variable, or initialize a new object similar to calling +Client.new(:first_name => 'Ryan')+. From here, you can modify other fields in client by calling the attribute setters on it: +client.locked = true+ and when you want to write it to the database just call +save+ on it. +Just like you can use *+build+* instead of *+new+*, you can use *+first_or_build+* instead of *+first_or_new+*. h3. Finding by SQL -- cgit v1.2.3 From ee822f257e2f3f3b571772f30ae3a8edd69538c3 Mon Sep 17 00:00:00 2001 From: Nicolas Hock Isaza Date: Tue, 30 Aug 2011 15:40:09 -0500 Subject: Adding `first_or_new` documentation to the AR Querying guide. --- railties/guides/source/active_record_querying.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 37874c2ea1..54ce7a25ab 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -1069,7 +1069,7 @@ NOTE: Be sure to check the extensive *Active Record Validations and Callbacks Gu h4. +first_or_new+ -The +first_or_new+ method will work just like +first_or_create+ but it will not call +create+ but the +new+. This means that a new model instance will be created in memory but won't be saved to the database. Continuing with the +first_or_create+ example, we now want the client named 'Nick': +The +first_or_new+ method will work just like +first_or_create+ but it will not call +create+ but +new+. This means that a new model instance will be created in memory but won't be saved to the database. Continuing with the +first_or_create+ example, we now want the client named 'Nick': nick = Client.where(:first_name => 'Nick').first_or_new(:locked => false) -- cgit v1.2.3 From 331dad14bc0623a8b1f24be88f2933c20c346c74 Mon Sep 17 00:00:00 2001 From: Ray Baxter Date: Tue, 30 Aug 2011 22:32:09 -0700 Subject: don't need edgeapi now that we are on 3.1 --- railties/guides/source/3_1_release_notes.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index 087926f98d..156987efc4 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -170,7 +170,7 @@ class PostsController < ActionController::Base end -You can restrict it to some actions by using +:only+ or +:except+. Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information. +You can restrict it to some actions by using +:only+ or +:except+. Please read the docs at "ActionController::Streaming":http://api.rubyonrails.org/classes/ActionController/Streaming.html for more information. * The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused. -- cgit v1.2.3 From 73263f6c81936b199f7410991a23ea380a58e005 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 31 Aug 2011 01:44:59 -0700 Subject: adds the release notes of 3.1 to the index --- railties/guides/source/index.html.erb | 4 ++++ railties/guides/source/layout.html.erb | 1 + 2 files changed, 5 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb index b7813086d7..214155c088 100644 --- a/railties/guides/source/index.html.erb +++ b/railties/guides/source/index.html.erb @@ -174,6 +174,10 @@ Ruby on Rails Guides

Release Notes

+<%= guide("Ruby on Rails 3.1 Release Notes", '3_1_release_notes.html') do %> +

Release notes for Rails 3.1.

+<% end %> + <%= guide("Ruby on Rails 3.0 Release Notes", '3_0_release_notes.html') do %>

Release notes for Rails 3.0.

<% end %> diff --git a/railties/guides/source/layout.html.erb b/railties/guides/source/layout.html.erb index 5f8ee57517..3ccbc3a477 100644 --- a/railties/guides/source/layout.html.erb +++ b/railties/guides/source/layout.html.erb @@ -84,6 +84,7 @@
Ruby on Rails Guides Guidelines
Release Notes
+
Ruby on Rails 3.1 Release Notes
Ruby on Rails 3.0 Release Notes
Ruby on Rails 2.3 Release Notes
Ruby on Rails 2.2 Release Notes
-- cgit v1.2.3 From d7be97ec31f5d972e01fb11b05ca4b36f581c779 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 31 Aug 2011 01:52:43 -0700 Subject: release notes: adds a couple of blank lines to get the markup right --- railties/guides/source/3_1_release_notes.textile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index 087926f98d..9ca77d0657 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -346,6 +346,7 @@ has_many :things, :conditions => proc { "foo = #{bar}" } # after Inside the proc, +self+ is the object which is the owner of the association, unless you are eager loading the association, in which case +self+ is the class which the association is within. You can have any "normal" conditions inside the proc, so the following will work too: + has_many :things, :conditions => proc { ["foo = ?", bar] } @@ -353,6 +354,7 @@ has_many :things, :conditions => proc { ["foo = ?", bar] } * Previously +:insert_sql+ and +:delete_sql+ on +has_and_belongs_to_many+ association allowed you to call 'record' to get the record being inserted or deleted. This is now passed as an argument to the proc. * Added ActiveRecord::Base#has_secure_password (via ActiveModel::SecurePassword) to encapsulate dead-simple password usage with BCrypt encryption and salting. + # Schema: User(name:string, password_digest:string, password_salt:string) class User < ActiveRecord::Base -- cgit v1.2.3 From e746c4047cd34accd7f63aa5d09cbb35011c24e2 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 31 Aug 2011 02:04:36 -0700 Subject: syncs assets guide with what's in 3-1-stable --- railties/guides/source/asset_pipeline.textile | 38 +++++++++++++++++++-------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 2695ba9ec1..96b11dbf63 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -15,7 +15,7 @@ h3. What is the Asset Pipeline? The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, SCSS and ERB. -Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets. Rails 3.1 includes the +sprockets-rails+ gem, which depends on the +sprockets+ gem, by default. +Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets. Rails 3.1 is integrated with Sprockets throught ActionPack which depends on the +sprockets+ gem, by default. By having this as a core feature of Rails, all developers can benefit from the power of having their assets pre-processed, compressed and minified by one central library, Sprockets. This is part of Rails' "Fast by default" strategy as outlined by DHH in his 2011 keynote at Railsconf. @@ -27,6 +27,7 @@ config.assets.enabled = false It is recommended that you use the defaults for all new apps. + h4. Main Features The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser must make to render a web page. While Rails already has a feature to concatenate these types of assets -- by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+ -- many people do not use it. @@ -74,11 +75,14 @@ The other problem is that when static assets are deployed with each new release Fingerprinting avoids all these problems by ensuring filenames are consistent based on their content. +Fingerprinting is enabled by default for production and disabled for all the others environments. You can enable or disable it in your configuration through the +config.assets.digest+ option. + More reading: * "Optimize caching":http://code.google.com/speed/page-speed/docs/caching.html * "Revving Filenames: don’t use querystring":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/ + h3. How to Use the Asset Pipeline In previous versions of Rails, all assets were located in subdirectories of +public+ such as +images+, +javascripts+ and +stylesheets+. With the asset pipeline, the preferred location for these assets is now the +app/assets+ directory. Files in this directory are served by the Sprockets middleware included in the sprockets gem. @@ -247,14 +251,7 @@ When the +debug_assets+ parameter is set, this line is expanded out into three s This allows the individual parts of an asset to be rendered and debugged separately. -Additionally if the +config.assets.debug+ is set to true you can debug your assets passing the +:debug+ option to the assets tags: - - -<%= javascript_include_tag :application, :debug => true %> - - - -NOTE. Assets debugging is turned on by default in development and test environments. You can set +config.assets.allow_debugging+ to false to turn it off. +NOTE. Assets debugging is turned on by default in development and test environments. h3. In Production @@ -271,7 +268,7 @@ The MD5 is generated from the contents of the compiled files, and is included in Sprockets also sets the +Cache-Control+ HTTP header to +max-age=31536000+. This signals all caches between your server and the client browser that this content (the file served) can be cached for 1 year. The effect of this is to reduce the number of requests for this asset from your server; the asset has a good chance of being in the local browser cache or some intermediate cache. -This behavior is controlled by the setting of +config.action_controller.perform_caching+ setting in Rails (which is +true+ for production, +false+ for everything else). This value is propagated to Sprockets during initialization for use when action_controller is not available. +This behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else). h4. Precompiling Assets @@ -307,6 +304,20 @@ If you have other manifests or individual stylesheets and JavaScript files to in config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js'] +The rake task also generates a +manifest.yml+ that contains a list with all your assets and their fingerprints, using this manifest file the assets helpers avoid hitting to Sprockets to recalculate MD5 hashes for files. Manifest file typically look like this: + + +--- +rails.png: rails-bd9ad5a560b5a3a7be0808c5cd76a798.png +jquery-ui.min.js: jquery-ui-7e33882a28fc84ad0e0e47e46cbf901c.min.js +jquery.min.js: jquery-8a50feed8d29566738ad005e19fe1c2d.min.js +application.js: application-3fdab497b8fb70d20cfc5495239dfc29.js +application.css: application-8af74128f904600e41a6e39241464e03.css + + +The manifest file is generated by default in same folder of your precompiled assets, you can change the location of the file setting the +config.assets.manifest+ option with the full path of the folder where you want save it. + + Precompiled assets exist on the filesystem and are served directly by your webserver. They do not have far-future headers by default, so to get the benefit of fingerprinting you'll have to update your server configuration to add them. For Apache: @@ -325,12 +336,16 @@ For Apache: -TODO: NGINX instructions +TODO: nginx instructions When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disc. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the public/assets folder. The following configuration options can be used: TODO: Apache instructions +TODO: nginx instructions + +By default Rails assumes that you have your files precompiled in the production environment, if you want use live compiling (compile your assets during runtime) in production you must set the +config.assets.compile+ to true. You can use this option to fallback to Sprockets when you are using precompiled assets but there are any missing precompiled files. If +config.assets.compile+ option is set to false and there are missing precompiled files you will get an "AssetNoPrecompiledError" indicating the name of the missing file. + h3. Customizing the Pipeline @@ -378,6 +393,7 @@ To enable this, pass a +new+ Object to the config option in +application.rb+: config.assets.css_compressor = Transformer.new + h4. Changing the _assets_ Path The public path that Sprockets uses by default is +/assets+. -- cgit v1.2.3 From 6d772c0953b418da774b2c3bf5cc297508669da7 Mon Sep 17 00:00:00 2001 From: Semyon Perepelitsa Date: Wed, 31 Aug 2011 14:40:45 +0400 Subject: Fix typo: => instead of = --- railties/guides/source/3_1_release_notes.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index ba36735a0b..b9850daf15 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -245,7 +245,7 @@ class User < ActiveRecord::Base has_one :account end -user.build_account{ |a| a.credit_limit => 100.0 } +user.build_account{ |a| a.credit_limit = 100.0 } * Added ActiveRecord::Base.attribute_names to return a list of attribute names. This will return an empty array if the model is abstract or the table does not exist. -- cgit v1.2.3 From 30d65da17e5fb1cdd3f10a6d14f4295b57e26286 Mon Sep 17 00:00:00 2001 From: Rodrigo Rosenfeld Rosas Date: Wed, 31 Aug 2011 10:50:08 -0300 Subject: Fix logic in 3.1 release notes sentence --- railties/guides/source/3_1_release_notes.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index 4412d32cce..7de8866ff6 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -271,7 +271,7 @@ Post.new(params[:post], :as => :admin) * +ConnectionManagement+ middleware is changed to clean up the connection pool after the rack body has been flushed. -* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records. +* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is not recommended to use +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records. * Associations with a +:through+ option can now use any association as the through or source association, including other associations which have a +:through+ option and +has_and_belongs_to_many+ associations. -- cgit v1.2.3 From dffdd829930e664cef522f34730d5987be348596 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Mon, 29 Aug 2011 16:28:11 -0500 Subject: Read digests of assets from manifest.yml if config.assets.manifest is on --- railties/lib/rails/application/configuration.rb | 9 +-- .../rails/app/templates/config/application.rb | 4 ++ railties/test/application/assets_test.rb | 65 ++++++++++++++++++++++ 3 files changed, 74 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 5d7bd3282d..7f4db0a19f 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -42,10 +42,11 @@ module Rails @assets.version = '' @assets.debug = false @assets.allow_debugging = false - - @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] - @assets.js_compressor = nil - @assets.css_compressor = nil + @assets.manifest = true + @assets.precompile_only = false + @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] + @assets.js_compressor = nil + @assets.css_compressor = nil end def compiled_asset_path diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index 3891829150..30a75200cb 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -52,6 +52,10 @@ module <%= app_const_base %> <% unless options.skip_sprockets? -%> # Enable the asset pipeline config.assets.enabled = true + + # Create a manifest with the hashes of your assets when you run "rake assets:precompile". + # Use this if you don't have a JavaScript engine in your production servers + config.assets.manifest = true <% end -%> end end diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index a8d1382e94..9df10e84d8 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -62,6 +62,71 @@ module ApplicationTests end end + test "precompile don't create a manifest file when manifest option is off" do + app_file "app/assets/javascripts/application.js", "alert();" + app_file "config/initializers/manifest.rb", "Rails.application.config.assets.manifest = false" + + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + + assert !File.exist?("#{app_path}/public/assets/manifest.yml") + end + + test "precompile creates a manifest file with all the assets listed when manifest option is on" do + app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" + app_file "app/assets/javascripts/application.js", "alert();" + + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + + manifest = "#{app_path}/public/assets/manifest.yml" + + assets = YAML.load_file(manifest) + assert_match /application-([0-z]+)\.js/, assets["application.js"] + assert_match /application-([0-z]+)\.css/, assets["application.css"] + end + + test "assets do not require any assets group gem when manifest option is on and manifest file is present" do + app_file "app/assets/javascripts/application.js", "alert();" + + ENV["RAILS_ENV"] = "production" + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + manifest = "#{app_path}/public/assets/manifest.yml" + assets = YAML.load_file(manifest) + asset_path = assets["application.js"] + + require "#{app_path}/config/environment" + + # Checking if Uglifier is defined we can know if Sprockets was reached or not + assert !defined?(Uglifier) + get "/assets/#{asset_path}" + assert_match "alert()", last_response.body + assert !defined?(Uglifier) + end + + test "assets raise AssetNotPrecompiledError if config.assets.precompile_only is on and file isn't precompiled" do + app_file "app/assets/javascripts/app.js", "alert();" + app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'app' %>" + app_file "config/initializers/precompile_only.rb", "Rails.application.config.assets.precompile_only = true" + + app_file "config/routes.rb", <<-RUBY + AppTemplate::Application.routes.draw do + match '/posts', :to => "posts#index" + end + RUBY + + ENV["RAILS_ENV"] = "production" + require "#{app_path}/config/environment" + class ::PostsController < ActionController::Base ; end + + get '/posts' + assert_match /AssetNotPrecompiledError/, last_response.body + end + test "precompile appends the md5 hash to files referenced with asset_path and run in the provided RAILS_ENV" do app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" -- cgit v1.2.3 From fa04c37f45ca9299a5efb426913488b678c178ce Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Wed, 31 Aug 2011 12:42:54 -0500 Subject: Backport b0f30631662 to master --- .../lib/rails/generators/rails/app/templates/config/application.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index 30a75200cb..13fbe9e526 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -53,9 +53,8 @@ module <%= app_const_base %> # Enable the asset pipeline config.assets.enabled = true - # Create a manifest with the hashes of your assets when you run "rake assets:precompile". - # Use this if you don't have a JavaScript engine in your production servers - config.assets.manifest = true + # Version of your assets, change this if you want to expire all your assets + config.assets.version = '1.0' <% end -%> end end -- cgit v1.2.3 From f236e00189b5a6cf0cebac5c275f64d41d73428d Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Wed, 31 Aug 2011 12:47:33 -0500 Subject: Backport f443f9cb0c64 to master --- railties/lib/rails/application/configuration.rb | 5 ++-- .../config/environments/development.rb.tt | 3 -- .../templates/config/environments/production.rb.tt | 6 ++++ railties/test/application/assets_test.rb | 32 +++++++++++----------- 4 files changed, 24 insertions(+), 22 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 7f4db0a19f..85e0cd5061 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -41,9 +41,8 @@ module Rails @assets.prefix = "/assets" @assets.version = '' @assets.debug = false - @assets.allow_debugging = false - @assets.manifest = true - @assets.precompile_only = false + @assets.compile = true + @assets.digest = false @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] @assets.js_compressor = nil @assets.css_compressor = nil diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index 33f9939ffe..47078e3af9 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -30,9 +30,6 @@ # Do not compress assets config.assets.compress = false - # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets - config.assets.allow_debugging = true - # Expands the lines which load the assets config.assets.debug = true end diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index de56d47688..b4754cfc6d 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -14,6 +14,12 @@ # 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 + # 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 diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 9df10e84d8..a4d7fc92f5 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -37,6 +37,8 @@ module ApplicationTests test "assets do not require compressors until it is used" do app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();" + app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = true" + ENV["RAILS_ENV"] = "production" require "#{app_path}/config/environment" @@ -62,18 +64,7 @@ module ApplicationTests end end - test "precompile don't create a manifest file when manifest option is off" do - app_file "app/assets/javascripts/application.js", "alert();" - app_file "config/initializers/manifest.rb", "Rails.application.config.assets.manifest = false" - - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end - - assert !File.exist?("#{app_path}/public/assets/manifest.yml") - end - - test "precompile creates a manifest file with all the assets listed when manifest option is on" do + test "precompile creates a manifest file with all the assets listed" do app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" app_file "app/assets/javascripts/application.js", "alert();" @@ -88,7 +79,7 @@ module ApplicationTests assert_match /application-([0-z]+)\.css/, assets["application.css"] end - test "assets do not require any assets group gem when manifest option is on and manifest file is present" do + test "assets do not require any assets group gem when manifest file is present" do app_file "app/assets/javascripts/application.js", "alert();" ENV["RAILS_ENV"] = "production" @@ -108,10 +99,8 @@ module ApplicationTests assert !defined?(Uglifier) end - test "assets raise AssetNotPrecompiledError if config.assets.precompile_only is on and file isn't precompiled" do - app_file "app/assets/javascripts/app.js", "alert();" + test "assets raise AssetNotPrecompiledError when manifest file is present and requested file isn't precompiled" do app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'app' %>" - app_file "config/initializers/precompile_only.rb", "Rails.application.config.assets.precompile_only = true" app_file "config/routes.rb", <<-RUBY AppTemplate::Application.routes.draw do @@ -120,15 +109,25 @@ module ApplicationTests RUBY ENV["RAILS_ENV"] = "production" + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + + # Create file after of precompile + app_file "app/assets/javascripts/app.js", "alert();" + require "#{app_path}/config/environment" class ::PostsController < ActionController::Base ; end get '/posts' assert_match /AssetNotPrecompiledError/, last_response.body + assert_match /app.js isn't precompiled/, last_response.body end test "precompile appends the md5 hash to files referenced with asset_path and run in the provided RAILS_ENV" do app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" + # digest is default in false, we must enable it for test environment + app_file "config/initializers/compile.rb", "Rails.application.config.assets.digest = true" # capture(:stdout) do Dir.chdir(app_path){ `bundle exec rake assets:precompile RAILS_ENV=test` } @@ -139,6 +138,7 @@ module ApplicationTests test "precompile appends the md5 hash to files referenced with asset_path and run in production as default even using RAILS_GROUPS=assets" do app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" + app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = true" ENV["RAILS_ENV"] = nil capture(:stdout) do -- cgit v1.2.3 From d0b3937b8fe2cbc4385e843d47249af3e7181a83 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Tue, 30 Aug 2011 16:30:53 -0500 Subject: Set default location of manifest with config.assets.manifest --- railties/lib/rails/application/configuration.rb | 1 + .../app/templates/config/environments/production.rb.tt | 3 +++ railties/test/application/assets_test.rb | 17 +++++++++++++++++ 3 files changed, 21 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 85e0cd5061..fa7e3b820b 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -43,6 +43,7 @@ module Rails @assets.debug = false @assets.compile = true @assets.digest = false + @assets.manifest = "#{root}/public#{@assets.prefix}" @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] @assets.js_compressor = nil @assets.css_compressor = nil diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index b4754cfc6d..64e2c09467 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -20,6 +20,9 @@ # Generate digests for assets URLs config.assets.digest = true + # Defaults to Rails.root.join("public/assets") + # config.assets.manifest = YOUR_PATH + # 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 diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index a4d7fc92f5..ccadf0b2c0 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -79,6 +79,23 @@ module ApplicationTests assert_match /application-([0-z]+)\.css/, assets["application.css"] end + test "precompile creates a manifest file in a custom path with all the assets listed" do + app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" + app_file "app/assets/javascripts/application.js", "alert();" + FileUtils.mkdir "#{app_path}/shared" + app_file "config/initializers/manifest.rb", "Rails.application.config.assets.manifest = '#{app_path}/shared'" + + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + + manifest = "#{app_path}/shared/manifest.yml" + + assets = YAML.load_file(manifest) + assert_match /application-([0-z]+)\.js/, assets["application.js"] + assert_match /application-([0-z]+)\.css/, assets["application.css"] + end + test "assets do not require any assets group gem when manifest file is present" do app_file "app/assets/javascripts/application.js", "alert();" -- cgit v1.2.3 From 87074600d3f7909bce7884c4588aab83f1b3a2d1 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Wed, 31 Aug 2011 13:09:35 -0500 Subject: Fix asset debugging tests to reflect last changes in 3-1-stable --- railties/test/application/asset_debugging_test.rb | 27 +++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'railties') diff --git a/railties/test/application/asset_debugging_test.rb b/railties/test/application/asset_debugging_test.rb index 38e1e21d17..707abe7191 100644 --- a/railties/test/application/asset_debugging_test.rb +++ b/railties/test/application/asset_debugging_test.rb @@ -33,24 +33,33 @@ module ApplicationTests teardown_app end - test "assets are concatenated when debug is off and allow_debugging is off either if debug_assets param is provided" do - # config.assets.debug and config.assets.allow_debugging are false for production environment + test "assets are concatenated when debug is off and compile is off either if debug_assets param is provided" do + # config.assets.debug and config.assets.compile are false for production environment + ENV["RAILS_ENV"] = "production" + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end require "#{app_path}/config/environment" - # the debug_assets params isn't used if allow_debugging is off + class ::PostsController < ActionController::Base ; end + + # the debug_assets params isn't used if compile is off get '/posts?debug_assets=true' - assert_match %r{}, last_response.body - assert_no_match %r{}, last_response.body + assert_match /}, last_response.body - assert_match %r{}, last_response.body + assert_match / + + + -When the +debug_assets+ parameter is set, this line is expanded out into three separate lines, separating out the combined file into their parts. +h4. Turning Debugging off + +You can turn off debug mode by updating +development.rb+ to include: + + +config.assets.debug = false + + +When debug mode is off Sprockets will concatenate and run the necessary preprocessors on all files, generating the following HTML: - - -This allows the individual parts of an asset to be rendered and debugged separately. +Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-validate+ Cache-Control HTTP header to reduce request overhead on subsequent requests - on these the browser gets a 304 (not-modified) response. + +If any of the files in the manifest have changed between requests, the server responds with a new compiled file. + +You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL to enable debug mode on-demand, and this will render indivudual tags for each file. This is useful for tracking down exact line numbers when debugging. + +You could potentially also enable compression in development mode as a sanity check, and disable it on-demand as required for debugging. -NOTE. Assets debugging is turned on by default in development and test environments. h3. In Production -In the production environment, assets are served slightly differently. +In the production environment Rails uses the fingerprinting scheme outlined above. By default it is assumed that assets have been precompiled and will be served as static assets by your web server. -On the first request the assets are compiled and cached as described above, however the manifest names are altered to include an MD5 hash. Files names typically look like these: +During the precompilation phase an MD5 is generated from the contents of the compiled files, and inserted into the filenames as they are written to disc. These fingerprinted names are used by the Rails helpers in place of the manifest name. - -/assets/application-908e25f4bf641868d8683022a5b62f54.js -/assets/application-4dd5b109ee3439da54f5bdfd78a80473.css - +For example this: -The MD5 is generated from the contents of the compiled files, and is included in the HTTP +Content-MD5+ header. + +<%= javascript_include_tag "application" %> +<%= stylesheet_link_tag "application" %> + -Sprockets also sets the +Cache-Control+ HTTP header to +max-age=31536000+. This signals all caches between your server and the client browser that this content (the file served) can be cached for 1 year. The effect of this is to reduce the number of requests for this asset from your server; the asset has a good chance of being in the local browser cache or some intermediate cache. +generates something like this: + + + + + -This behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else). +The fingerprinting behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else). under normal circumstances the default options should not be changed. h4. Precompiling Assets -Even though assets are served by Rack::Cache with far-future headers, in high traffic sites this may not be fast enough. +Rails comes bundled with a rake task to compile the asset manifests and other files in the pipeline to disc. -Rails comes bundled with a rake task to compile the manifests to files on disc. These are located in the +public/assets+ directory where they are served by your web server instead of the Rails application. +Compiled assets are written to the location specified in +config.assets.prefix+. The default setting will use the +public/assets+ directory. + +You must use this task either during deployment or locally if you do not have write access to your production filesystem. The rake task is: @@ -288,7 +305,7 @@ Capistrano (v2.8.0+) has a recipe to handle this in deployment. Add the followin load 'deploy/assets' -This links the folder specified in +config.assets.prefix+ to +shared/assets+. If you already use this folder you'll need to write your own deployment task. +This links the folder specified in +config.assets.prefix+ to +shared/assets+. If you already use this shared folder you'll need to write your own deployment task. It is important that this folder is shared between deployments so that remotely cached pages that reference the old compiled assets still work for the life of the cached page. @@ -298,13 +315,13 @@ The default matcher for compiling files includes +application.js+, +application. [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ] -If you have other manifests or individual stylesheets and JavaScript files to include, you can append them to the +precompile+ array: +If you have other manifests or individual stylesheets and JavaScript files to include, you can add them to the +precompile+ array: config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js'] -The rake task also generates a +manifest.yml+ that contains a list with all your assets and their fingerprints, using this manifest file the assets helpers avoid hitting to Sprockets to recalculate MD5 hashes for files. Manifest file typically look like this: +The rake task also generates a +manifest.yml+ that contains a list with all your assets and their respective fingerprints. This is used by the Rails helper methods and avoids handing the mapping requests back to Sprockets. Manifest file typically look like this: --- @@ -315,8 +332,17 @@ application.js: application-3fdab497b8fb70d20cfc5495239dfc29.js application.css: application-8af74128f904600e41a6e39241464e03.css -The manifest file is generated by default in same folder of your precompiled assets, you can change the location of the file setting the +config.assets.manifest+ option with the full path of the folder where you want save it. +The default location for the manifest is the root of the location specified in +config.assets.prefix+ ('/assets' by default). + +This can be changed with the +config.assets.manifest+ option. A fully specified path is required: + +config.assets.manifest = '/path/to/some/other/location' + + +NOTE: If there are missing precompiled files in production you will get an "AssetNoPrecompiledError" exception indicating the name of the missing file. + +h5. Server Configuration Precompiled assets exist on the filesystem and are served directly by your webserver. They do not have far-future headers by default, so to get the benefit of fingerprinting you'll have to update your server configuration to add them. @@ -370,10 +396,23 @@ location ~ ^/(assets)/ { } -By default Rails assumes that you have your files precompiled in the production environment, if you want use live compiling (compile your assets during runtime) in production you must set the +config.assets.compile+ to true. You can use this option to fallback to Sprockets when you are using precompiled assets but there are any missing precompiled files. If +config.assets.compile+ option is set to false and there are missing precompiled files you will get an "AssetNoPrecompiledError" indicating the name of the missing file. +h4. Live Compilation -h3. Customizing the Pipeline +In some circumstances you may wish to use live compilation. In this mode all requests for assets in the Pipeline are handled by Sprockets directly. + +To enable this options set: + + +config.assets.compile = true + + +On the first request the assets are compiled and cached as outlined in development above, and the manifest names used in the helpers are altered to include the MD5 hash. + +Sprockets also sets the +Cache-Control+ HTTP header to +max-age=31536000+. This signals all caches between your server and the client browser that this content (the file served) can be cached for 1 year. The effect of this is to reduce the number of requests for this asset from your server; the asset has a good chance of being in the local browser cache or some intermediate cache. + +This mode uses more memory and is lower performance than the default. It is not recommended. +h3. Customizing the Pipeline h4. CSS Compression @@ -475,6 +514,10 @@ config.assets.enabled = true # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' + +# Change the path that assets are served from +# config.assets.prefix = "/assets" + In +development.rb+: @@ -493,6 +536,11 @@ And in +production.rb+: # Compress JavaScripts and CSS config.assets.compress = true +# Choose the compressors to use +# config.assets.js_compressor = :uglifier +# config.assets.css_compressor = :yui + + # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false @@ -507,3 +555,16 @@ config.assets.digest = true There are no changes to +test.rb+. + +The following should also be added to +Gemfile+: + + +# 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 + + -- cgit v1.2.3 From 3ce3b5b1f1f92d79ee015d246a9f62a725eca5ca Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 31 Aug 2011 18:50:38 -0700 Subject: Merge pull request #2780 from guilleiguaran/assets-pipeline-minor-changes Assets pipeline: fix in manifest location and remove unused code --- railties/lib/rails/application/configuration.rb | 2 +- railties/test/application/assets_test.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index fa7e3b820b..0ca664e4f0 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -43,7 +43,7 @@ module Rails @assets.debug = false @assets.compile = true @assets.digest = false - @assets.manifest = "#{root}/public#{@assets.prefix}" + @assets.manifest = nil @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] @assets.js_compressor = nil @assets.css_compressor = nil diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index ccadf0b2c0..721d082908 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -96,6 +96,19 @@ module ApplicationTests assert_match /application-([0-z]+)\.css/, assets["application.css"] end + test "the manifest file should be saved by default in the same assets folder" do + app_file "app/assets/javascripts/application.js", "alert();" + app_file "config/initializers/manifest.rb", "Rails.application.config.assets.prefix = '/x'" + + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + + manifest = "#{app_path}/public/x/manifest.yml" + assets = YAML.load_file(manifest) + assert_match /application-([0-z]+)\.js/, assets["application.js"] + end + test "assets do not require any assets group gem when manifest file is present" do app_file "app/assets/javascripts/application.js", "alert();" -- cgit v1.2.3 From 4ba35dd26b8f02ab851e9d8431a1fe78264e2d51 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Thu, 1 Sep 2011 00:35:01 -0500 Subject: Giving info about what are the defaults for test environment --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index f62b7e5c65..8bcddfbb4b 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -554,7 +554,7 @@ config.assets.digest = true # config.assets.precompile += %w( search.js ) -There are no changes to +test.rb+. +There are no changes to +test.rb+. For test environment by default +config.assets.compile+ is true and +config.assets.compress+, +config.assets.debug+ and +config.assets.digest+ are false The following should also be added to +Gemfile+: -- cgit v1.2.3 From 418e321b506645bc0fb69116f01de41546a8cacf Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Thu, 1 Sep 2011 01:01:31 -0500 Subject: Fixing sass-rails helpers methods examples --- railties/guides/source/asset_pipeline.textile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 8bcddfbb4b..9ff4f0d062 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -158,13 +158,13 @@ h5. CSS and SCSS When using the asset pipeline, paths to assets must be re-written and +sass-rails+ provides +_url+ and +_path+ helpers for the following asset classes: image, font, video, audio, javascript, stylesheet. -* +image_url("rails.png")+ becomes +url(/assets/rails.png)+ -* +image_path("rails.png")+ becomes +"/assets/rails.png"+. +* +image-url("rails.png")+ becomes +url(/assets/rails.png)+ +* +image-path("rails.png")+ becomes +"/assets/rails.png"+. The more generic form can also be used but the asset path and class must both be specified: -* +asset_url("rails.png", "image")+ becomes +url(/assets/rails.png)+ -* +asset_path("rails.png", "image")+ becomes +"/assets/rails.png"+ +* +asset-url("rails.png", image)+ becomes +url(/assets/rails.png)+ +* +asset-path("rails.png", image)+ becomes +"/assets/rails.png"+ h4. Manifest Files and Directives -- cgit v1.2.3 From fdf2f519bd948003b851a1eff8a6f157297a46ad Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Thu, 1 Sep 2011 01:15:19 -0500 Subject: Add reference to ExecJS in JavaScript Compression section --- railties/guides/source/asset_pipeline.textile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 9ff4f0d062..b06abc82cf 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -426,7 +426,7 @@ config.assets.css_compressor = :yui The +config.assets.compress+ must be set to +true+ to enable CSS compression -h4. JavaScript +h4. JavaScript Compression Possible options for JavaScript compression are +:closure+, +:uglifier+ and +:yui+. These require the use of the +closure-compiler+, +uglifier+ or +yui-compressor+ gems respectively. @@ -440,6 +440,8 @@ config.assets.js_compressor = :uglifier The +config.assets.compress+ must be set to +true+ to enable JavaScript compression +NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have a JavaScript engine in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes. + h4. Using Your Own Compressor The compressor config settings for CSS and JavaScript also take any Object. This object must have a +compress+ method that takes a string as the sole argument and it must return a string. -- cgit v1.2.3 From 72fea6d2ebd9a40d78f0d6ad0fdbdf80298458e9 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Thu, 1 Sep 2011 01:18:20 -0500 Subject: Adding reference about ExecJS for CoffeeScript --- railties/guides/source/asset_pipeline.textile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index b06abc82cf..e428684079 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -89,10 +89,12 @@ In previous versions of Rails, all assets were located in subdirectories of +pub This is not to say that assets can (or should) no longer be placed in +public+; they still can be and will be served as static files by the application or web server. You would only use +app/assets+ if you wish your files to undergo some pre-processing before they are served. -When a scaffold or controller is generated for the application, Rails also generates a JavaScript file (or CoffeeScript file if the +coffee-script+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS file if +sass-rails+ is in the +Gemfile+) for that controller. +When a scaffold or controller is generated for the application, Rails also generates a JavaScript file (or CoffeeScript file if the +coffee-rails+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS file if +sass-rails+ is in the +Gemfile+) for that controller. For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as +<%= javascript_include_tag params[:controller] %>+ or +<%= stylesheet_link_tag params[:controller] %>+. +NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use CoffeeScript. If you are using Mac OS X or Windows you have a JavaScript runtime installed in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes. + h4. Asset Organization Assets can be placed inside an application in one of three locations: +app/assets+, +lib/assets+ or +vendor/assets+. @@ -440,7 +442,7 @@ config.assets.js_compressor = :uglifier The +config.assets.compress+ must be set to +true+ to enable JavaScript compression -NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have a JavaScript engine in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes. +NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have installed a JavaScript runtime in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes. h4. Using Your Own Compressor -- cgit v1.2.3 From 5421d4d0161949e24f63bab30b82be694761a6d4 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Thu, 1 Sep 2011 18:25:24 +1200 Subject: pipeline docs - spelling and some whitespace --- railties/guides/source/asset_pipeline.textile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index e428684079..a0e51aa57c 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -282,7 +282,7 @@ generates something like this: - + The fingerprinting behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else). under normal circumstances the default options should not be changed. @@ -375,7 +375,7 @@ For Apache: # 2 lines to serve pre-gzipped version RewriteCond %{REQUEST_FILENAME}.gz -s RewriteRule ^(.+) $1.gz [L] - + # without it, Content-Type will be "application/x-gzip" ForceType text/css @@ -402,7 +402,7 @@ h4. Live Compilation In some circumstances you may wish to use live compilation. In this mode all requests for assets in the Pipeline are handled by Sprockets directly. -To enable this options set: +To enable this option set: config.assets.compile = true @@ -442,7 +442,7 @@ config.assets.js_compressor = :uglifier The +config.assets.compress+ must be set to +true+ to enable JavaScript compression -NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have installed a JavaScript runtime in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes. +NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have installed a JavaScript runtime in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes. h4. Using Your Own Compressor @@ -506,7 +506,7 @@ TODO: Registering gems on "Tilt":https://github.com/rtomayko/tilt enabling Sproc h3. Upgrading from Old Versions of Rails -There are two issues when upgrading. The first is moving the files to the new locations. See the section above for guidance on the correct locations for different file types. +There are two issues when upgrading. The first is moving the files to the new locations. See the section above for guidance on the correct locations for different file types. The second is updating the various environment files with the correct default options. The following changes reflect the defaults in version 3.1.0. -- cgit v1.2.3 From 58b0c9734777a4610e812a48ee64881b4f88b107 Mon Sep 17 00:00:00 2001 From: Sam Pohlenz Date: Thu, 1 Sep 2011 09:23:51 +0930 Subject: assets:precompile should not append asset digests when config.assets.digest is false --- railties/test/application/assets_test.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'railties') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 721d082908..a412b7d99b 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -67,6 +67,8 @@ module ApplicationTests test "precompile creates a manifest file with all the assets listed" do app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" app_file "app/assets/javascripts/application.js", "alert();" + # digest is default in false, we must enable it for test environment + app_file "config/initializers/compile.rb", "Rails.application.config.assets.digest = true" capture(:stdout) do Dir.chdir(app_path){ `bundle exec rake assets:precompile` } @@ -84,6 +86,8 @@ module ApplicationTests app_file "app/assets/javascripts/application.js", "alert();" FileUtils.mkdir "#{app_path}/shared" app_file "config/initializers/manifest.rb", "Rails.application.config.assets.manifest = '#{app_path}/shared'" + # digest is default in false, we must enable it for test environment + app_file "config/initializers/compile.rb", "Rails.application.config.assets.digest = true" capture(:stdout) do Dir.chdir(app_path){ `bundle exec rake assets:precompile` } @@ -96,9 +100,12 @@ module ApplicationTests assert_match /application-([0-z]+)\.css/, assets["application.css"] end + test "the manifest file should be saved by default in the same assets folder" do app_file "app/assets/javascripts/application.js", "alert();" app_file "config/initializers/manifest.rb", "Rails.application.config.assets.prefix = '/x'" + # digest is default in false, we must enable it for test environment + app_file "config/initializers/compile.rb", "Rails.application.config.assets.digest = true" capture(:stdout) do Dir.chdir(app_path){ `bundle exec rake assets:precompile` } @@ -109,6 +116,25 @@ module ApplicationTests assert_match /application-([0-z]+)\.js/, assets["application.js"] end + test "precompile does not append asset digests when config.assets.digest is false" do + app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" + app_file "app/assets/javascripts/application.js", "alert();" + app_file "config/initializers/compile.rb", "Rails.application.config.assets.digest = false" + + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + + assert File.exists?("#{app_path}/public/assets/application.js") + assert File.exists?("#{app_path}/public/assets/application.css") + + manifest = "#{app_path}/public/assets/manifest.yml" + + assets = YAML.load_file(manifest) + assert_equal "application.js", assets["application.js"] + assert_equal "application.css", assets["application.css"] + end + test "assets do not require any assets group gem when manifest file is present" do app_file "app/assets/javascripts/application.js", "alert();" -- cgit v1.2.3 From 1f998c7578d343310a4309bc0b06af224132648d Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Thu, 1 Sep 2011 21:15:06 +1200 Subject: pipeline docs improvement Some cleaning up of whitespace/punctuation and text refinements to clarify some things. --- railties/guides/source/asset_pipeline.textile | 45 +++++++++++++++------------ 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index a0e51aa57c..3ed75a28ef 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -105,13 +105,17 @@ Assets can be placed inside an application in one of three locations: +app/asset +vendor/assets+ is for assets that are owned by outside entities, such as code for JavaScript plugins. -All subdirectories that exist within these three locations are added to the search path for Sprockets (visible by calling +Rails.application.config.assets.paths+ in a console). When an asset is requested, these paths are looked through to see if they contain an asset matching the name specified. Once an asset has been found, it's processed by Sprockets and served. +All subdirectories that exist within these three locations are added to the search path for Sprockets (visible by calling +Rails.application.config.assets.paths+ in a console). When an asset is requested, these paths are traversed to see if they contain an asset matching the name specified. Once an asset has been found, it's processed by Sprockets and served. -h4. Coding Links to Assets +You can add additional (fully qualified) paths to the pipeline in +application.rb+. For example: + + +config.assets.paths << File.join(Rails.root, 'app', 'assets', 'flash') + -To access assets, you use the same tags that you are generally familiar with: +h4. Coding Links to Assets -Sprockets does not add any new methods to require your assets, you still use the familiar +javascript_include_tag+ and +stylesheet_link_tag+. +Sprockets does not add any new methods to access your assets - you still use the familiar +javascript_include_tag+ and +stylesheet_link_tag+. <%= stylesheet_link_tag "application" %> @@ -124,17 +128,17 @@ In regular views you can access images in the +assets/images+ directory like thi <%= image_tag "rails.png" %> -Images can be organized into directories if required, and they can be accessed by specifying the directory's name in the tag: +Provided that the pipeline is enabled within your application (and not disabled in the current environment context), this file is served by Sprockets. If a file exists at +public/assets/rails.png+ it is served by the webserver. - -<%= image_tag "icons/rails.png" %> - +Alternatively, a request for a file with an MD5 hash such as +public/assets/rails-af27b6a414e6da00003503148be9b409.png+ is treated the same way. How these hashes are generated is covered in the "Production Assets":#production_assets section later on in this guide. -Providing that assets are enabled within your application (+config.assets.enabled+ in the current environment's file is not set to +false+), this file is served by Sprockets unless a file at +public/assets/rails.png+ exists, in which case that file is served. +Sprockets will also look through the paths specified in +config.assets.paths+ which includes the standard application paths and any path added by Rails engines. -Alternatively, a file with an MD5 hash after its name such as +public/assets/rails-af27b6a414e6da00003503148be9b409.png+ is also picked up by Sprockets. How these hashes are generated is covered in the "Production Assets":#production_assets section later on in this guide. +Images can also be organized into subdirectories if required, and they can be accessed by specifying the directory's name in the tag: -Otherwise, Sprockets looks through the available paths until it finds a file that matches the name and then serves it, first looking in the application's assets directories and then falling back to the various engines of the application. + +<%= image_tag "icons/rails.png" %> + If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme -- a method of embedding the image data directly into the CSS file -- you can use the +asset_data_uri+ helper. @@ -256,7 +260,7 @@ When debug mode is off Sprockets will concatenate and run the necessary preproce -Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-validate+ Cache-Control HTTP header to reduce request overhead on subsequent requests - on these the browser gets a 304 (not-modified) response. +Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-validate+ Cache-Control HTTP header to reduce request overhead on subsequent requests -- on these the browser gets a 304 (not-modified) response. If any of the files in the manifest have changed between requests, the server responds with a new compiled file. @@ -285,7 +289,9 @@ generates something like this: -The fingerprinting behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else). under normal circumstances the default options should not be changed. +The fingerprinting behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else). + +NOTE: Under normal circumstances the default options should not be changed. If there are no digests in the filenames, and far-future headers are set, remote clients will never know to refetch the files when their content changes. h4. Precompiling Assets @@ -366,7 +372,7 @@ For Apache: TODO: nginx instructions -When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disc. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the public/assets folder. The following configuration options can be used: +When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disc. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the +public/assets+ folder. The following configuration options can be used: For Apache: @@ -418,7 +424,7 @@ h3. Customizing the Pipeline h4. CSS Compression -There is currently one option for compressing CSS - YUI. This Gem extends the CSS syntax and offers minification. +There is currently one option for compressing CSS, YUI. This Gem extends the CSS syntax and offers minification. The following line enables YUI compression, and requires the +yui-compressor+ gem. @@ -442,7 +448,7 @@ config.assets.js_compressor = :uglifier The +config.assets.compress+ must be set to +true+ to enable JavaScript compression -NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have installed a JavaScript runtime in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes. +NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme -- supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have installed a JavaScript runtime in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes. h4. Using Your Own Compressor @@ -490,7 +496,7 @@ WARNING: If you are upgrading an existing application and intend to use this opt h3. How Caching Works -Sprockets uses the default rails cache store to cache assets in dev and production. The only difference is file names are fingerprinted and get far-future headers in production. +Sprockets uses the default rails cache store to cache assets in development and production. TODO: Add more about changing the default store. @@ -544,11 +550,10 @@ config.assets.compress = true # config.assets.js_compressor = :uglifier # config.assets.css_compressor = :yui - # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false -# Generate digests for assets URLs +# Generate digests for assets URLs. config.assets.digest = true # Defaults to Rails.root.join("public/assets") @@ -558,7 +563,7 @@ config.assets.digest = true # config.assets.precompile += %w( search.js ) -There are no changes to +test.rb+. For test environment by default +config.assets.compile+ is true and +config.assets.compress+, +config.assets.debug+ and +config.assets.digest+ are false +There are no changes to +test.rb+. The defaults in the test environment are: +config.assets.compile+ is true and +config.assets.compress+, +config.assets.debug+ and +config.assets.digest+ are false. The following should also be added to +Gemfile+: -- cgit v1.2.3 From cfd785f910fc914c576133fee263875833ba0c92 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Thu, 1 Sep 2011 21:20:26 +1200 Subject: Move css data URI into css/erb section --- railties/guides/source/asset_pipeline.textile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 3ed75a28ef..cfed1b5bdf 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -140,14 +140,6 @@ Images can also be organized into subdirectories if required, and they can be ac <%= image_tag "icons/rails.png" %> -If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme -- a method of embedding the image data directly into the CSS file -- you can use the +asset_data_uri+ helper. - - -#logo { background: url(<%= asset_data_uri 'logo.png' %>) } - - -This inserts a correctly-formatted data URI into the CSS source. - h5. CSS and ERB If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then you can use the +asset_path+ helper in your CSS rules: @@ -158,6 +150,14 @@ If you add an +erb+ extension to a CSS asset, making it something such as +appli This writes the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file, then that path is referenced. +If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme -- a method of embedding the image data directly into the CSS file -- you can use the +asset_data_uri+ helper. + + +#logo { background: url(<%= asset_data_uri 'logo.png' %>) } + + +This inserts a correctly-formatted data URI into the CSS source. + Note that the closing tag cannot be of the style +-%>+. h5. CSS and SCSS -- cgit v1.2.3 From 3461a5d4368ab0e41f28d831170794f967286611 Mon Sep 17 00:00:00 2001 From: Roy Tomeij Date: Thu, 1 Sep 2011 17:24:26 +0200 Subject: Change "SCSS" to "Sass" in sentences where it's referred to as "language", because Sass is the language (SCSS is one possible syntax within the Sass language), as per documentation on sass-lang.com. --- railties/guides/source/asset_pipeline.textile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index cfed1b5bdf..550485d038 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -13,7 +13,7 @@ endprologue. h3. What is the Asset Pipeline? -The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, SCSS and ERB. +The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets. Rails 3.1 is integrated with Sprockets through ActionPack which depends on the +sprockets+ gem, by default. @@ -36,7 +36,7 @@ The default behavior in Rails 3.1 and onward is to concatenate all files into on The second feature is to minify or compress assets. For CSS, this usually involves removing whitespace and comments. For JavaScript, more complex processes can be applied. You can choose from a set of built in options or specify your own. -The third feature is the ability to code these assets using another language, or language extension. These include SCSS or Sass for CSS, CoffeeScript for JavaScript, and ERB for both. +The third feature is the ability to code these assets using another language, or language extension. These include Sass for CSS, CoffeeScript for JavaScript, and ERB for both. h4. What is Fingerprinting and Why Should I Care? @@ -108,7 +108,7 @@ Assets can be placed inside an application in one of three locations: +app/asset All subdirectories that exist within these three locations are added to the search path for Sprockets (visible by calling +Rails.application.config.assets.paths+ in a console). When an asset is requested, these paths are traversed to see if they contain an asset matching the name specified. Once an asset has been found, it's processed by Sprockets and served. You can add additional (fully qualified) paths to the pipeline in +application.rb+. For example: - + config.assets.paths << File.join(Rails.root, 'app', 'assets', 'flash') @@ -160,7 +160,7 @@ This inserts a correctly-formatted data URI into the CSS source. Note that the closing tag cannot be of the style +-%>+. -h5. CSS and SCSS +h5. CSS and Sass When using the asset pipeline, paths to assets must be re-written and +sass-rails+ provides +_url+ and +_path+ helpers for the following asset classes: image, font, video, audio, javascript, stylesheet. @@ -289,7 +289,7 @@ generates something like this: -The fingerprinting behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else). +The fingerprinting behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else). NOTE: Under normal circumstances the default options should not be changed. If there are no digests in the filenames, and far-future headers are set, remote clients will never know to refetch the files when their content changes. -- cgit v1.2.3 From 8e900f1e38166ea906967eb8ede9bd14e78eb417 Mon Sep 17 00:00:00 2001 From: Andy Leeper Date: Thu, 1 Sep 2011 10:42:28 -0700 Subject: Modified ActionMailer Basics doc with the following change: * Changed the lines that said config/environments/env.rb to config/environments/$RAILS_ENV.rb. People were mis-interpreting the filename to literally be env.rb. --- railties/guides/source/action_mailer_basics.textile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile index 142b9dba7e..351a4498b1 100644 --- a/railties/guides/source/action_mailer_basics.textile +++ b/railties/guides/source/action_mailer_basics.textile @@ -467,7 +467,7 @@ The following configuration options are best made in one of the environment file h4. Example Action Mailer Configuration -An example would be adding the following to your appropriate config/environments/env.rb file: +An example would be adding the following to your appropriate config/environments/$RAILS_ENV.rb file: config.action_mailer.delivery_method = :sendmail @@ -482,7 +482,7 @@ config.action_mailer.raise_delivery_errors = true h4. Action Mailer Configuration for GMail -As Action Mailer now uses the Mail gem, this becomes as simple as adding to your config/environments/env.rb file: +As Action Mailer now uses the Mail gem, this becomes as simple as adding to your config/environments/$RAILS_ENV.rb file: config.action_mailer.delivery_method = :smtp @@ -524,4 +524,5 @@ In the test we send the email and store the returned object in the +email+ varia h3. Changelog +* September 1, 2011: Changed the lines that said config/environments/env.rb to config/environments/$RAILS_ENV.rb. People were mis-interpreting the filename to literally be env.rb. "Andy Leeper":http://mochaleaf.com * September 30, 2010: Fixed typos and reformatted Action Mailer configuration table for better understanding. "Jaime Iniesta":http://jaimeiniesta.com -- cgit v1.2.3 From c96cb8897b4afb0fea7b5fed4ec41d1772d99644 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Thu, 1 Sep 2011 23:50:31 +0530 Subject: Revert "Fix logic in 3.1 release notes sentence" This reverts commit 30d65da17e5fb1cdd3f10a6d14f4295b57e26286. Reason: This commit is incorrect. It is indeed recommended to use update_attribute when you want callbacks to be invoked. --- railties/guides/source/3_1_release_notes.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index 7de8866ff6..4412d32cce 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -271,7 +271,7 @@ Post.new(params[:post], :as => :admin) * +ConnectionManagement+ middleware is changed to clean up the connection pool after the rack body has been flushed. -* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is not recommended to use +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records. +* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records. * Associations with a +:through+ option can now use any association as the through or source association, including other associations which have a +:through+ option and +has_and_belongs_to_many+ associations. -- cgit v1.2.3 From 2d92962701d545c29ebd38f51b787e48faabb504 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Thu, 1 Sep 2011 16:02:08 -0300 Subject: Add #update_attributes as another alternative to #update_column. --- railties/guides/source/3_1_release_notes.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index 4412d32cce..73a96388af 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -271,7 +271,7 @@ Post.new(params[:post], :as => :admin) * +ConnectionManagement+ middleware is changed to clean up the connection pool after the rack body has been flushed. -* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records. +* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use +update_attributes+ or +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records. * Associations with a +:through+ option can now use any association as the through or source association, including other associations which have a +:through+ option and +has_and_belongs_to_many+ associations. -- cgit v1.2.3 From ca7c37a660b66b6b3cdd7fe4ab850ea5a32cc2c0 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Fri, 2 Sep 2011 08:39:16 +1200 Subject: fix some minor omissions in pipeline docs --- railties/guides/source/asset_pipeline.textile | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 550485d038..e40310a9ec 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -89,6 +89,8 @@ In previous versions of Rails, all assets were located in subdirectories of +pub This is not to say that assets can (or should) no longer be placed in +public+; they still can be and will be served as static files by the application or web server. You would only use +app/assets+ if you wish your files to undergo some pre-processing before they are served. +In production, the default is to precompile these files to +public/assets+ so that they can be more efficiently delivered by the webserver. + When a scaffold or controller is generated for the application, Rails also generates a JavaScript file (or CoffeeScript file if the +coffee-rails+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS file if +sass-rails+ is in the +Gemfile+) for that controller. For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as +<%= javascript_include_tag params[:controller] %>+ or +<%= stylesheet_link_tag params[:controller] %>+. @@ -241,11 +243,13 @@ This manifest +application.js+: would generate this HTML: - - - + + + +The +body+ param is required by Sprockets. + h4. Turning Debugging off You can turn off debug mode by updating +development.rb+ to include: @@ -264,7 +268,16 @@ Assets are compiled and cached on the first request after the server is started. If any of the files in the manifest have changed between requests, the server responds with a new compiled file. -You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL to enable debug mode on-demand, and this will render indivudual tags for each file. This is useful for tracking down exact line numbers when debugging. +You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL to enable debug mode on-demand, and this will render individual tags for each file. This is useful for tracking down exact line numbers when debugging. + +Debug can also be set in the Rails helper methods: + + +<%= stylesheet_link_tag "application", :debug => true %> +<%= javascript_include_tag "application", :debug => true %> + + +Don't forget to remove this before deploying to production! You could potentially also enable compression in development mode as a sanity check, and disable it on-demand as required for debugging. @@ -291,7 +304,7 @@ generates something like this: The fingerprinting behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else). -NOTE: Under normal circumstances the default options should not be changed. If there are no digests in the filenames, and far-future headers are set, remote clients will never know to refetch the files when their content changes. +NOTE: Under normal circumstances the default option should not be changed. If there are no digests in the filenames, and far-future headers are set, remote clients will never know to refetch the files when their content changes. h4. Precompiling Assets -- cgit v1.2.3 From 16aa4330d7a07736ce59ea3a96e57d17fa628a2d Mon Sep 17 00:00:00 2001 From: "Stephen J. Butler" Date: Thu, 1 Sep 2011 19:55:38 -0500 Subject: Change the styling of 'initialize' to '+initialize+' (the former breaks the HTML generation). --- railties/guides/source/initialization.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 9cc4dd5f04..8aabc3ae91 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -454,7 +454,7 @@ app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app", TOPLEVEL_BINDING, config -The initialize method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run: +The +initialize+ method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run: require ::File.expand_path('../config/environment', __FILE__) -- cgit v1.2.3 From e61d6afbab24163d37a73b25262ef73119b99a78 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Fri, 2 Sep 2011 13:31:00 +0400 Subject: fix indent for generator environment method --- railties/lib/rails/generators/actions.rb | 2 +- railties/test/generators/actions_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index b8541c236e..a7462f39ba 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -97,7 +97,7 @@ module Rails in_root do if options[:env].nil? - inject_into_file 'config/application.rb', "\n #{data}", :after => sentinel, :verbose => false + inject_into_file 'config/application.rb', "\n #{data}", :after => sentinel, :verbose => false else Array.wrap(options[:env]).each do |env| inject_into_file "config/environments/#{env}.rb", "\n #{data}", :after => env_file_sentinel, :verbose => false diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index e4a8000425..56cb53c1ad 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -106,7 +106,7 @@ class ActionsTest < Rails::Generators::TestCase run_generator autoload_paths = 'config.autoload_paths += %w["#{Rails.root}/app/extras"]' action :environment, autoload_paths - assert_file 'config/application.rb', /#{Regexp.escape(autoload_paths)}/ + assert_file 'config/application.rb', / class Application < Rails::Application\n #{Regexp.escape(autoload_paths)}/ end def test_environment_should_include_data_in_environment_initializer_block_with_env_option -- cgit v1.2.3 From 3a7c16dbb9c1a4ea96c516c0a9f9ce5d34cee49a Mon Sep 17 00:00:00 2001 From: Matt Burke Date: Fri, 2 Sep 2011 10:20:23 -0400 Subject: When a collection is empty, render returns nil. --- railties/guides/source/layouts_and_rendering.textile | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index 310a70ca9b..3252f17c56 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -1093,6 +1093,13 @@ In Rails 3.0, there is also a shorthand for this. Assuming +@products+ is a coll Rails determines the name of the partial to use by looking at the model name in the collection. In fact, you can even create a heterogeneous collection and render it this way, and Rails will choose the proper partial for each member of the collection: +In the event that the collection is empty, +render+ will return nil, so it should be fairly simple to provide alternative content. + + +

Products

+<%= render(@products) || 'There are no products available.' %> +
+ * +index.html.erb+ -- cgit v1.2.3 From d20281add192e5afba66e555ce67cf73943b033b Mon Sep 17 00:00:00 2001 From: Andrew Olson Date: Fri, 2 Sep 2011 11:48:45 -0400 Subject: Fixing guides validation errors. --- railties/guides/source/action_view_overview.textile | 6 +++--- railties/guides/source/active_model_basics.textile | 2 ++ railties/guides/source/active_record_querying.textile | 4 ++-- railties/guides/source/active_support_core_extensions.textile | 4 ++-- railties/guides/source/ajax_on_rails.textile | 6 +++++- railties/guides/source/asset_pipeline.textile | 6 +++--- railties/guides/source/form_helpers.textile | 2 +- railties/guides/source/generators.textile | 2 +- railties/guides/source/initialization.textile | 6 +++--- railties/guides/source/performance_testing.textile | 4 ++-- 10 files changed, 24 insertions(+), 18 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile index 5a1e8b1247..c43fd8cc14 100644 --- a/railties/guides/source/action_view_overview.textile +++ b/railties/guides/source/action_view_overview.textile @@ -126,7 +126,7 @@ Rails supports multiple template systems and uses a file extension to distinguis h5. ERB -Within an ERB template Ruby code can be included using both +<% %>+ and +<%= %>+ tags. The +<% %>+ are used to execute Ruby code that does not return anything, such as conditions, loops or blocks, and the +<%= %>+ tags are used when you want output. +Within an ERB template Ruby code can be included using both +<% %>+ and +<%= %>+ tags. The +<% %>+ are used to execute Ruby code that does not return anything, such as conditions, loops or blocks, and the +<%= %>+ tags are used when you want output. Consider the following loop for names: @@ -137,14 +137,14 @@ Consider the following loop for names: <% end %> -The loop is setup in regular embedding tags +<% %>+ and the name is written using the output embedding tag +<%= %>+. Note that this is not just a usage suggestion, for Regular output functions like print or puts won't work with ERB templates. So this would be wrong: +The loop is setup in regular embedding tags +<% %>+ and the name is written using the output embedding tag +<%= %>+. Note that this is not just a usage suggestion, for Regular output functions like print or puts won't work with ERB templates. So this would be wrong: <%# WRONG %> Hi, Mr. <% puts "Frodo" %> -To suppress leading and trailing whitespaces, you can use +<%-+ +-%>+ interchangeably with +<%+ and +%>+. +To suppress leading and trailing whitespaces, you can use +<%-+ +-%>+ interchangeably with +<%+ and +%>+. h5. Builder diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index 0672669dc5..73df567579 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -163,12 +163,14 @@ person.first_name_changed? #=> true
Track what was the previous value of the attribute. + #attr_name_was accessor person.first_name_was #=> "First Name" Track both previous and current value of the changed attribute. Returns an array if changed else returns nil + #attr_name_change person.first_name_change #=> ["First Name", "First Name 1"] diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 4e77a6e803..3a163fb943 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -132,7 +132,7 @@ SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1 Model.last returns +nil+ if no matching record is found. No exception will be raised. -h5. +first!+ +h5(#first-1). +first!+ Model.first! finds the first record. For example: @@ -149,7 +149,7 @@ SELECT * FROM clients LIMIT 1 Model.first! raises +RecordNotFound+ if no matching record is found. -h5. +last!+ +h5(#last-1). +last!+ Model.last! finds the last record. For example: diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index b2436a2e68..aab14dac8d 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -190,7 +190,7 @@ WARNING: Fixnums and symbols have no singleton classes, +singleton_class+ raises NOTE: Defined in +active_support/core_ext/kernel/singleton_class.rb+. -h4. +class_eval(*args, &block)+ +h4. +class_eval(*args, &block)+ You can evaluate code in the context of any object's singleton class using +class_eval+: @@ -2097,7 +2097,7 @@ NOTE: Defined in +active_support/core_ext/array/prepend_and_append.rb+. h4. Options Extraction -When the last argument in a method call is a hash, except perhaps for a +&block+ argument, Ruby allows you to omit the brackets: +When the last argument in a method call is a hash, except perhaps for a +&block+ argument, Ruby allows you to omit the brackets: User.exists?(:email => params[:email]) diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile index 77f7661deb..e189c49bcd 100644 --- a/railties/guides/source/ajax_on_rails.textile +++ b/railties/guides/source/ajax_on_rails.textile @@ -67,7 +67,7 @@ link_to_remote "Add to cart", If the server returns 200, the output of the above example is equivalent to our first, simple one. However, in case of error, the element with the DOM id +error+ is updated rather than the +cart+ element. -** *position* By default (i.e. when not specifying this option, like in the examples before) the response is injected into the element with the specified DOM id, replacing the original content of the element (if there was any). You might want to alter this behavior by keeping the original content - the only question is where to place the new content? This can specified by the +position+ parameter, with four possibilities: +** *:position* By default (i.e. when not specifying this option, like in the examples before) the response is injected into the element with the specified DOM id, replacing the original content of the element (if there was any). You might want to alter this behavior by keeping the original content - the only question is where to place the new content? This can specified by the +position+ parameter, with four possibilities: *** +:before+ Inserts the response text just before the target element. More precisely, it creates a text node from the response and inserts it as the left sibling of the target element. *** +:after+ Similar behavior to +:before+, but in this case the response is inserted after the target element. *** +:top+ Inserts the text into the target element, before it's original content. If the target element was empty, this is equivalent with not specifying +:position+ at all. @@ -123,7 +123,9 @@ link_to_remote "Add new item", :update => "item_list", 404 => "alert('Item not found!')" + Let's see a typical example for the most frequent callbacks, +:success+, +:failure+ and +:complete+ in action: + link_to_remote "Add new item", :url => items_url, @@ -133,7 +135,9 @@ link_to_remote "Add new item", :success => "display_item_added(request)", :failure => "display_error(request)" + ** *:type* If you want to fire a synchronous request for some obscure reason (blocking the browser while the request is processed and doesn't return a status code), you can use the +:type+ option with the value of +:synchronous+. + * Finally, using the +html_options+ parameter you can add HTML attributes to the generated tag. It works like the same parameter of the +link_to+ helper. There are interesting side effects for the +href+ and +onclick+ parameters though: ** If you specify the +href+ parameter, the AJAX link will degrade gracefully, i.e. the link will point to the URL even if JavaScript is disabled in the client browser ** +link_to_remote+ gains it's AJAX behavior by specifying the remote call in the onclick handler of the link. If you supply +html_options[:onclick]+ you override the default behavior, so use this with care! diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index cfed1b5bdf..bbd2e24da5 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -62,11 +62,11 @@ This has several disadvantages:
  1. - Not all caches will cache content with a query string
    + Not all caches will cache content with a query string
    "Steve Souders recommends":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/, "...avoiding a querystring for cacheable resources". He found that in these case 5-20% of requests will not be cached.
  2. - The file name can change between nodes in multi-server environments.
    + The file name can change between nodes in multi-server environments.
    The query string in Rails is based on the modification time of the files. When assets are deployed to a cluster, there is no guarantee that the timestamps will be the same, resulting in different values being used depending on which server handles the request.
@@ -91,7 +91,7 @@ This is not to say that assets can (or should) no longer be placed in +public+; When a scaffold or controller is generated for the application, Rails also generates a JavaScript file (or CoffeeScript file if the +coffee-rails+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS file if +sass-rails+ is in the +Gemfile+) for that controller. -For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as +<%= javascript_include_tag params[:controller] %>+ or +<%= stylesheet_link_tag params[:controller] %>+. +For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as +<%= javascript_include_tag params[:controller] %>+ or +<%= stylesheet_link_tag params[:controller] %>+. NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use CoffeeScript. If you are using Mac OS X or Windows you have a JavaScript runtime installed in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes. diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index c277f5723a..9b35c409b3 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -98,7 +98,7 @@ form_tag({:controller => "people", :action => "search"}, :method => "get", :clas h4. Helpers for Generating Form Elements -Rails provides a series of helpers for generating form elements such as checkboxes, text fields, and radio buttons. These basic helpers, with names ending in "_tag" (such as +text_field_tag+ and +check_box_tag+), generate just a single +<input>+ element. The first parameter to these is always the name of the input. When the form is submitted, the name will be passed along with the form data, and will make its way to the +params+ hash in the controller with the value entered by the user for that field. For example, if the form contains +<%= text_field_tag(:query) %>+, then you would be able to get the value of this field in the controller with +params[:query]+. +Rails provides a series of helpers for generating form elements such as checkboxes, text fields, and radio buttons. These basic helpers, with names ending in "_tag" (such as +text_field_tag+ and +check_box_tag+), generate just a single +<input>+ element. The first parameter to these is always the name of the input. When the form is submitted, the name will be passed along with the form data, and will make its way to the +params+ hash in the controller with the value entered by the user for that field. For example, if the form contains +<%= text_field_tag(:query) %>+, then you would be able to get the value of this field in the controller with +params[:query]+. When naming inputs, Rails uses certain conventions that make it possible to submit parameters with non-scalar values such as arrays or hashes, which will also be accessible in +params+. You can read more about them in "chapter 7 of this guide":#understanding-parameter-naming-conventions. For details on the precise usage of these helpers, please refer to the "API documentation":http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html. diff --git a/railties/guides/source/generators.textile b/railties/guides/source/generators.textile index 2fa1d6e21d..24f100187a 100644 --- a/railties/guides/source/generators.textile +++ b/railties/guides/source/generators.textile @@ -1,4 +1,4 @@ -h2. Creating and Customizing Rails Generators & Templates +h2. Creating and Customizing Rails Generators & Templates Rails generators are an essential tool if you plan to improve your workflow. With this guide you will learn how to create generators and customize existing ones. diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 9cc4dd5f04..3804f5e81f 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -454,7 +454,7 @@ app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app", TOPLEVEL_BINDING, config
-The initialize method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run: +The +initialize+ method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run: require ::File.expand_path('../config/environment', __FILE__) @@ -676,11 +676,11 @@ h4. Back to +railties/lib/rails/railtie.rb+ Once the inflector files have been loaded, the +Rails::Railtie+ class is defined. This class includes a module called +Initializable+, which is actually +Rails::Initializable+. This module includes the +initializer+ method which is used later on for setting up initializers, amongst other methods. -h4. +railties/lib/rails/initializable.rb+ +h4(#railties-lib-rails-initializable-rb-1). +railties/lib/rails/initializable.rb+ When the module from this file (+Rails::Initializable+) is included, it extends the class it's included into with the +ClassMethods+ module inside of it. This module defines the +initializer+ method which is used to define initializers throughout all of the railties. This file completes the loading of +railties/lib/rails/railtie.rb+. Now we go back to +rails/engine.rb+. -h4. +railties/lib/rails/engine.rb+ +h4(#railties-lib-rails-engine-rb-1). +railties/lib/rails/engine.rb+ The next file required in +rails/engine.rb+ is +active_support/core_ext/module/delegation+ which is documented in the "Active Support Core Extensions Guide":http://guides.rubyonrails.org/active_support_core_extensions.html#method-delegation. diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile index 75f81cf13d..0ea88d8385 100644 --- a/railties/guides/source/performance_testing.textile +++ b/railties/guides/source/performance_testing.textile @@ -207,7 +207,7 @@ GC Time measures the amount of time spent in GC for the performance test case. h5. Metric Availability -h6. Benchmarking +h6(#benchmarking-1). Benchmarking |_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time| |_.MRI | yes | yes | yes | no | yes | yes | yes | yes | @@ -215,7 +215,7 @@ h6. Benchmarking |_.Rubinius | yes | no | no | no | yes | yes | yes | yes | |_.JRuby | yes | no | no | yes | yes | yes | yes | yes | -h6. Profiling +h6(#profiling-1). Profiling |_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time| |_.MRI | yes | yes | no | no | yes | yes | yes | yes | -- cgit v1.2.3 From 220c77dd68430cc150c61119a14c86dee659911c Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 2 Sep 2011 22:42:23 +0530 Subject: debug option to js, stylesheet tags are ignored when debug mode is off --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 73f77ac05e..86ae23ab11 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -277,7 +277,7 @@ Debug can also be set in the Rails helper methods: <%= javascript_include_tag "application", :debug => true %> -Don't forget to remove this before deploying to production! +The +:debug+ option is ignored if the debug mode is off. You could potentially also enable compression in development mode as a sanity check, and disable it on-demand as required for debugging. -- cgit v1.2.3 From 44284a613b3efe2319db3f84090c0004505942c1 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 2 Sep 2011 22:57:03 +0530 Subject: Revert "Fixing guides validation errors." This reverts commit d20281add192e5afba66e555ce67cf73943b033b. Reason: This needs more investigation. Will apply when this is verified. --- railties/guides/source/action_view_overview.textile | 6 +++--- railties/guides/source/active_model_basics.textile | 2 -- railties/guides/source/active_record_querying.textile | 4 ++-- railties/guides/source/active_support_core_extensions.textile | 4 ++-- railties/guides/source/ajax_on_rails.textile | 6 +----- railties/guides/source/asset_pipeline.textile | 6 +++--- railties/guides/source/form_helpers.textile | 2 +- railties/guides/source/generators.textile | 2 +- railties/guides/source/initialization.textile | 6 +++--- railties/guides/source/performance_testing.textile | 4 ++-- 10 files changed, 18 insertions(+), 24 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile index c43fd8cc14..5a1e8b1247 100644 --- a/railties/guides/source/action_view_overview.textile +++ b/railties/guides/source/action_view_overview.textile @@ -126,7 +126,7 @@ Rails supports multiple template systems and uses a file extension to distinguis h5. ERB -Within an ERB template Ruby code can be included using both +<% %>+ and +<%= %>+ tags. The +<% %>+ are used to execute Ruby code that does not return anything, such as conditions, loops or blocks, and the +<%= %>+ tags are used when you want output. +Within an ERB template Ruby code can be included using both +<% %>+ and +<%= %>+ tags. The +<% %>+ are used to execute Ruby code that does not return anything, such as conditions, loops or blocks, and the +<%= %>+ tags are used when you want output. Consider the following loop for names: @@ -137,14 +137,14 @@ Consider the following loop for names: <% end %> -The loop is setup in regular embedding tags +<% %>+ and the name is written using the output embedding tag +<%= %>+. Note that this is not just a usage suggestion, for Regular output functions like print or puts won't work with ERB templates. So this would be wrong: +The loop is setup in regular embedding tags +<% %>+ and the name is written using the output embedding tag +<%= %>+. Note that this is not just a usage suggestion, for Regular output functions like print or puts won't work with ERB templates. So this would be wrong: <%# WRONG %> Hi, Mr. <% puts "Frodo" %> -To suppress leading and trailing whitespaces, you can use +<%-+ +-%>+ interchangeably with +<%+ and +%>+. +To suppress leading and trailing whitespaces, you can use +<%-+ +-%>+ interchangeably with +<%+ and +%>+. h5. Builder diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index 73df567579..0672669dc5 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -163,14 +163,12 @@ person.first_name_changed? #=> true Track what was the previous value of the attribute. - #attr_name_was accessor person.first_name_was #=> "First Name" Track both previous and current value of the changed attribute. Returns an array if changed else returns nil - #attr_name_change person.first_name_change #=> ["First Name", "First Name 1"] diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 3a163fb943..4e77a6e803 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -132,7 +132,7 @@ SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1 Model.last returns +nil+ if no matching record is found. No exception will be raised. -h5(#first-1). +first!+ +h5. +first!+ Model.first! finds the first record. For example: @@ -149,7 +149,7 @@ SELECT * FROM clients LIMIT 1 Model.first! raises +RecordNotFound+ if no matching record is found. -h5(#last-1). +last!+ +h5. +last!+ Model.last! finds the last record. For example: diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index aab14dac8d..b2436a2e68 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -190,7 +190,7 @@ WARNING: Fixnums and symbols have no singleton classes, +singleton_class+ raises NOTE: Defined in +active_support/core_ext/kernel/singleton_class.rb+. -h4. +class_eval(*args, &block)+ +h4. +class_eval(*args, &block)+ You can evaluate code in the context of any object's singleton class using +class_eval+: @@ -2097,7 +2097,7 @@ NOTE: Defined in +active_support/core_ext/array/prepend_and_append.rb+. h4. Options Extraction -When the last argument in a method call is a hash, except perhaps for a +&block+ argument, Ruby allows you to omit the brackets: +When the last argument in a method call is a hash, except perhaps for a +&block+ argument, Ruby allows you to omit the brackets: User.exists?(:email => params[:email]) diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile index e189c49bcd..77f7661deb 100644 --- a/railties/guides/source/ajax_on_rails.textile +++ b/railties/guides/source/ajax_on_rails.textile @@ -67,7 +67,7 @@ link_to_remote "Add to cart", If the server returns 200, the output of the above example is equivalent to our first, simple one. However, in case of error, the element with the DOM id +error+ is updated rather than the +cart+ element. -** *:position* By default (i.e. when not specifying this option, like in the examples before) the response is injected into the element with the specified DOM id, replacing the original content of the element (if there was any). You might want to alter this behavior by keeping the original content - the only question is where to place the new content? This can specified by the +position+ parameter, with four possibilities: +** *position* By default (i.e. when not specifying this option, like in the examples before) the response is injected into the element with the specified DOM id, replacing the original content of the element (if there was any). You might want to alter this behavior by keeping the original content - the only question is where to place the new content? This can specified by the +position+ parameter, with four possibilities: *** +:before+ Inserts the response text just before the target element. More precisely, it creates a text node from the response and inserts it as the left sibling of the target element. *** +:after+ Similar behavior to +:before+, but in this case the response is inserted after the target element. *** +:top+ Inserts the text into the target element, before it's original content. If the target element was empty, this is equivalent with not specifying +:position+ at all. @@ -123,9 +123,7 @@ link_to_remote "Add new item", :update => "item_list", 404 => "alert('Item not found!')" - Let's see a typical example for the most frequent callbacks, +:success+, +:failure+ and +:complete+ in action: - link_to_remote "Add new item", :url => items_url, @@ -135,9 +133,7 @@ link_to_remote "Add new item", :success => "display_item_added(request)", :failure => "display_error(request)" - ** *:type* If you want to fire a synchronous request for some obscure reason (blocking the browser while the request is processed and doesn't return a status code), you can use the +:type+ option with the value of +:synchronous+. - * Finally, using the +html_options+ parameter you can add HTML attributes to the generated tag. It works like the same parameter of the +link_to+ helper. There are interesting side effects for the +href+ and +onclick+ parameters though: ** If you specify the +href+ parameter, the AJAX link will degrade gracefully, i.e. the link will point to the URL even if JavaScript is disabled in the client browser ** +link_to_remote+ gains it's AJAX behavior by specifying the remote call in the onclick handler of the link. If you supply +html_options[:onclick]+ you override the default behavior, so use this with care! diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 86ae23ab11..192c393dca 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -62,11 +62,11 @@ This has several disadvantages:
  1. - Not all caches will cache content with a query string
    + Not all caches will cache content with a query string
    "Steve Souders recommends":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/, "...avoiding a querystring for cacheable resources". He found that in these case 5-20% of requests will not be cached.
  2. - The file name can change between nodes in multi-server environments.
    + The file name can change between nodes in multi-server environments.
    The query string in Rails is based on the modification time of the files. When assets are deployed to a cluster, there is no guarantee that the timestamps will be the same, resulting in different values being used depending on which server handles the request.
@@ -93,7 +93,7 @@ In production, the default is to precompile these files to +public/assets+ so th When a scaffold or controller is generated for the application, Rails also generates a JavaScript file (or CoffeeScript file if the +coffee-rails+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS file if +sass-rails+ is in the +Gemfile+) for that controller. -For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as +<%= javascript_include_tag params[:controller] %>+ or +<%= stylesheet_link_tag params[:controller] %>+. +For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as +<%= javascript_include_tag params[:controller] %>+ or +<%= stylesheet_link_tag params[:controller] %>+. NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use CoffeeScript. If you are using Mac OS X or Windows you have a JavaScript runtime installed in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes. diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index 9b35c409b3..c277f5723a 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -98,7 +98,7 @@ form_tag({:controller => "people", :action => "search"}, :method => "get", :clas h4. Helpers for Generating Form Elements -Rails provides a series of helpers for generating form elements such as checkboxes, text fields, and radio buttons. These basic helpers, with names ending in "_tag" (such as +text_field_tag+ and +check_box_tag+), generate just a single +<input>+ element. The first parameter to these is always the name of the input. When the form is submitted, the name will be passed along with the form data, and will make its way to the +params+ hash in the controller with the value entered by the user for that field. For example, if the form contains +<%= text_field_tag(:query) %>+, then you would be able to get the value of this field in the controller with +params[:query]+. +Rails provides a series of helpers for generating form elements such as checkboxes, text fields, and radio buttons. These basic helpers, with names ending in "_tag" (such as +text_field_tag+ and +check_box_tag+), generate just a single +<input>+ element. The first parameter to these is always the name of the input. When the form is submitted, the name will be passed along with the form data, and will make its way to the +params+ hash in the controller with the value entered by the user for that field. For example, if the form contains +<%= text_field_tag(:query) %>+, then you would be able to get the value of this field in the controller with +params[:query]+. When naming inputs, Rails uses certain conventions that make it possible to submit parameters with non-scalar values such as arrays or hashes, which will also be accessible in +params+. You can read more about them in "chapter 7 of this guide":#understanding-parameter-naming-conventions. For details on the precise usage of these helpers, please refer to the "API documentation":http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html. diff --git a/railties/guides/source/generators.textile b/railties/guides/source/generators.textile index 24f100187a..2fa1d6e21d 100644 --- a/railties/guides/source/generators.textile +++ b/railties/guides/source/generators.textile @@ -1,4 +1,4 @@ -h2. Creating and Customizing Rails Generators & Templates +h2. Creating and Customizing Rails Generators & Templates Rails generators are an essential tool if you plan to improve your workflow. With this guide you will learn how to create generators and customize existing ones. diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 3804f5e81f..9cc4dd5f04 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -454,7 +454,7 @@ app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app", TOPLEVEL_BINDING, config
-The +initialize+ method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run: +The initialize method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run: require ::File.expand_path('../config/environment', __FILE__) @@ -676,11 +676,11 @@ h4. Back to +railties/lib/rails/railtie.rb+ Once the inflector files have been loaded, the +Rails::Railtie+ class is defined. This class includes a module called +Initializable+, which is actually +Rails::Initializable+. This module includes the +initializer+ method which is used later on for setting up initializers, amongst other methods. -h4(#railties-lib-rails-initializable-rb-1). +railties/lib/rails/initializable.rb+ +h4. +railties/lib/rails/initializable.rb+ When the module from this file (+Rails::Initializable+) is included, it extends the class it's included into with the +ClassMethods+ module inside of it. This module defines the +initializer+ method which is used to define initializers throughout all of the railties. This file completes the loading of +railties/lib/rails/railtie.rb+. Now we go back to +rails/engine.rb+. -h4(#railties-lib-rails-engine-rb-1). +railties/lib/rails/engine.rb+ +h4. +railties/lib/rails/engine.rb+ The next file required in +rails/engine.rb+ is +active_support/core_ext/module/delegation+ which is documented in the "Active Support Core Extensions Guide":http://guides.rubyonrails.org/active_support_core_extensions.html#method-delegation. diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile index 0ea88d8385..75f81cf13d 100644 --- a/railties/guides/source/performance_testing.textile +++ b/railties/guides/source/performance_testing.textile @@ -207,7 +207,7 @@ GC Time measures the amount of time spent in GC for the performance test case. h5. Metric Availability -h6(#benchmarking-1). Benchmarking +h6. Benchmarking |_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time| |_.MRI | yes | yes | yes | no | yes | yes | yes | yes | @@ -215,7 +215,7 @@ h6(#benchmarking-1). Benchmarking |_.Rubinius | yes | no | no | no | yes | yes | yes | yes | |_.JRuby | yes | no | no | yes | yes | yes | yes | yes | -h6(#profiling-1). Profiling +h6. Profiling |_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time| |_.MRI | yes | yes | no | no | yes | yes | yes | yes | -- cgit v1.2.3 From 78497c7c27879aa735db24377f056de96a260bb9 Mon Sep 17 00:00:00 2001 From: Franco Catena Date: Fri, 2 Sep 2011 14:52:58 -0300 Subject: Change photos_path to photos_url in Using redirect_to Is more "correct" a complete url than only the path --- railties/guides/source/layouts_and_rendering.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index 3252f17c56..f49c2000ee 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -515,7 +515,7 @@ h4. Using +redirect_to+ Another way to handle returning responses to an HTTP request is with +redirect_to+. As you've seen, +render+ tells Rails which view (or other asset) to use in constructing a response. The +redirect_to+ method does something completely different: it tells the browser to send a new request for a different URL. For example, you could redirect from wherever you are in your code to the index of photos in your application with this call: -redirect_to photos_path +redirect_to photos_url You can use +redirect_to+ with any arguments that you could use with +link_to+ or +url_for+. In addition, there's a special redirect that sends the user back to the page they just came from: -- cgit v1.2.3 From f83f169b85eea4f580ae95609506fbb3cc5b8ccb Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 3 Sep 2011 01:40:00 +0530 Subject: some of the changes for validation earlier reverted from d20281a --- railties/guides/source/active_model_basics.textile | 2 ++ railties/guides/source/active_record_querying.textile | 4 ++-- railties/guides/source/performance_testing.textile | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index 0672669dc5..73df567579 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -163,12 +163,14 @@ person.first_name_changed? #=> true Track what was the previous value of the attribute. + #attr_name_was accessor person.first_name_was #=> "First Name" Track both previous and current value of the changed attribute. Returns an array if changed else returns nil + #attr_name_change person.first_name_change #=> ["First Name", "First Name 1"] diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 4e77a6e803..95a7bfebc3 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -132,7 +132,7 @@ SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1 Model.last returns +nil+ if no matching record is found. No exception will be raised. -h5. +first!+ +h5(#first_1). +first!+ Model.first! finds the first record. For example: @@ -149,7 +149,7 @@ SELECT * FROM clients LIMIT 1 Model.first! raises +RecordNotFound+ if no matching record is found. -h5. +last!+ +h5(#last_1). +last!+ Model.last! finds the last record. For example: diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile index 75f81cf13d..5947735deb 100644 --- a/railties/guides/source/performance_testing.textile +++ b/railties/guides/source/performance_testing.textile @@ -207,7 +207,7 @@ GC Time measures the amount of time spent in GC for the performance test case. h5. Metric Availability -h6. Benchmarking +h6(#benchmarking_1). Benchmarking |_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time| |_.MRI | yes | yes | yes | no | yes | yes | yes | yes | @@ -215,7 +215,7 @@ h6. Benchmarking |_.Rubinius | yes | no | no | no | yes | yes | yes | yes | |_.JRuby | yes | no | no | yes | yes | yes | yes | yes | -h6. Profiling +h6(#profiling_1). Profiling |_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time| |_.MRI | yes | yes | no | no | yes | yes | yes | yes | -- cgit v1.2.3 From b3a03253a78234dfc3bef0fab7dae2e49c2bfd2a Mon Sep 17 00:00:00 2001 From: David Peckham Date: Fri, 2 Sep 2011 13:38:13 -0700 Subject: Fixed a typo in the section about migration. --- railties/guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 256df0eded..6e9613cdae 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -592,7 +592,7 @@ class CreatePosts < ActiveRecord::Migration end -The above migration creates a method name +change+ which will be called when you +The above migration creates a method named +change+ which will be called when you run this migration. The action defined in that method is also reversible, which means Rails knows how to reverse the change made by this migration, in case you want to reverse it at later date. By default, when you run this migration it -- cgit v1.2.3 From a3edf3d2a307630980731b1963721c60ba2a14e0 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Sat, 3 Sep 2011 09:11:20 +1200 Subject: fix YUI description YUI CSS compressor does not extend syntax! Also added link to more info --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 192c393dca..ef35d1ed76 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -437,7 +437,7 @@ h3. Customizing the Pipeline h4. CSS Compression -There is currently one option for compressing CSS, YUI. This Gem extends the CSS syntax and offers minification. +There is currently one option for compressing CSS, YUI. The "YUI CSS compressor":http://developer.yahoo.com/yui/compressor/css.html provides minification. The following line enables YUI compression, and requires the +yui-compressor+ gem. -- cgit v1.2.3 From 5b7bcb4959a33d7a31acdd2823eb3272bcd1f322 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 3 Sep 2011 02:44:49 +0530 Subject: document send_file guesses content type from the file extension and remove info about x_send_file option to send_file --- railties/guides/source/action_controller_overview.textile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/action_controller_overview.textile b/railties/guides/source/action_controller_overview.textile index 073e3bddcf..4e47712636 100644 --- a/railties/guides/source/action_controller_overview.textile +++ b/railties/guides/source/action_controller_overview.textile @@ -684,9 +684,11 @@ end This will read and stream the file 4kB at the time, avoiding loading the entire file into memory at once. You can turn off streaming with the +:stream+ option or adjust the block size with the +:buffer_size+ option. +If +:type+ is not specified, it will be guessed from the file extension specified in +:filename+. If the content type is not registered for the extension, application/octet-stream will be used. + WARNING: Be careful when using data coming from the client (params, cookies, etc.) to locate the file on disk, as this is a security risk that might allow someone to gain access to files they are not meant to see. -TIP: It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack. Although if you do need the request to go through Rails for some reason, you can set the +:x_sendfile+ option to true, and Rails will let the web server handle sending the file to the user, freeing up the Rails process to do other things. Note that your web server needs to support the +X-Sendfile+ header for this to work. +TIP: It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack. h4. RESTful Downloads -- cgit v1.2.3 From 1b8290db527e29c6b503cb036bc42d67368f766c Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Fri, 2 Sep 2011 17:10:11 -0500 Subject: Fix asset_path example in CSS and ERB section --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index ef35d1ed76..82aa0a5256 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -147,7 +147,7 @@ h5. CSS and ERB If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then you can use the +asset_path+ helper in your CSS rules: -.class { background-image: <%= asset_path 'image.png' %> } +.class { background-image: url(<%= asset_path 'image.png') %> } This writes the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file, then that path is referenced. -- cgit v1.2.3 From 5912ed99029f76b3ec51955f05323b77fa0b22f2 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 3 Sep 2011 01:36:57 +0200 Subject: fixes CSS example in the asset pipeline guide --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 192c393dca..6935533f4a 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -147,7 +147,7 @@ h5. CSS and ERB If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then you can use the +asset_path+ helper in your CSS rules: -.class { background-image: <%= asset_path 'image.png' %> } +.class { background-image: url(<%= asset_path 'image.png' %>) } This writes the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file, then that path is referenced. -- cgit v1.2.3 From af54fc5586f00bbb82063f5110801ef08ad9ff39 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sat, 3 Sep 2011 00:05:37 -0500 Subject: Add bcrypt-ruby to Gemfile template --- railties/lib/rails/generators/rails/app/templates/Gemfile | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index c83e7ddf80..910cd16950 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -10,6 +10,9 @@ source 'http://rubygems.org' <%= assets_gemfile_entry %> <%= javascript_gemfile_entry %> +# To use ActiveModel has_secure_password +# gem 'bcrypt-ruby', '~> 3.0.0' + # Use unicorn as the web server # gem 'unicorn' -- cgit v1.2.3 From 5014b330288d41680477800847e83e049a5b57c3 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 4 Sep 2011 03:44:47 +0530 Subject: add some missing dots in the docs --- railties/guides/source/configuring.textile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index 050fcd823d..ae84bb5b92 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -134,15 +134,15 @@ Rails 3.1, by default, is set up to use the +sprockets+ gem to manage assets wit * +config.assets.prefix+ defines the prefix where assets are served from. Defaults to +/assets+. -* +config.assets.digest+ enables the use of MD5 fingerprints in asset names. Set to +true+ by default in +production.rb+ +* +config.assets.digest+ enables the use of MD5 fingerprints in asset names. Set to +true+ by default in +production.rb+. -* +config.assets.debug+ disables the concatenation and compression of assets. Set to +false+ by default in +development.rb+ +* +config.assets.debug+ disables the concatenation and compression of assets. Set to +false+ by default in +development.rb+. -* +config.assets.manifest+ defines the full path to be used for the asset precompiler's manifest file. Defaults to using +config.assets.prefix+ +* +config.assets.manifest+ defines the full path to be used for the asset precompiler's manifest file. Defaults to using +config.assets.prefix+. * +config.assets.cache_store+ defines the cache store that Sprockets will use. The default is the Rails file store. -* +config.assets.version+ is an option string that is used in MD5 hash generation. This can be changed to force all files to be recompiled. +* +config.assets.version+ is an option string that is used in MD5 hash generation. This can be changed to force all files to be recompiled. * +config.assets.compile+ is a boolean that can be used to turn on live Sprockets compilation in production. -- cgit v1.2.3 From 0a38e2a5ce2eaf7393958721edbfcf2a7fe87334 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 3 Sep 2011 15:20:18 -0700 Subject: restores the API docs of AR::Fixtures, made a quick pass over them, revises link in fixture template [closes #2840] --- railties/lib/rails/generators/test_unit/model/templates/fixtures.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml index d4138ca2f5..5c8780aa64 100644 --- a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml +++ b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml @@ -1,4 +1,4 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html <% unless attributes.empty? -%> one: -- cgit v1.2.3 From 34618e6697475bca8b4bcfaaa2d55a99e78c031a Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sun, 4 Sep 2011 08:17:53 +0530 Subject: Warnings removed for using shadow variable. --- railties/lib/rails/generators/actions.rb | 4 ++-- railties/test/generators/shared_generator_tests.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index a7462f39ba..c43a99e85c 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -119,8 +119,8 @@ module Rails if commands.is_a?(Symbol) run "git #{commands}" else - commands.each do |command, options| - run "git #{command} #{options}" + commands.each do |cmd, options| + run "git #{cmd} #{options}" end end end diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index d3074afd91..1534f0d828 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -191,11 +191,11 @@ module SharedCustomGeneratorTests end def test_builder_option_with_http - path = "http://gist.github.com/103208.txt" + url = "http://gist.github.com/103208.txt" template = "class #{builder_class}; end" template.instance_eval "def read; self; end" # Make the string respond to read - generator([destination_root], :builder => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) + generator([destination_root], :builder => url).expects(:open).with(url, 'Accept' => 'application/x-thor-template').returns(template) quietly { generator.invoke_all } default_files.each{ |path| assert_no_file(path) } -- cgit v1.2.3 From c8d0dc376a72b976ccef17b8d0b413961b306a5f Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sun, 4 Sep 2011 08:23:13 +0530 Subject: Warnings removed for "assert_match /" Please do not add more.! --- railties/test/application/asset_debugging_test.rb | 8 ++++---- railties/test/application/assets_test.rb | 18 +++++++++--------- railties/test/application/rake_test.rb | 6 +++--- railties/test/generators/plugin_new_generator_test.rb | 6 +++--- railties/test/railties/engine_test.rb | 2 +- railties/test/railties/shared_tests.rb | 10 +++++----- 6 files changed, 25 insertions(+), 25 deletions(-) (limited to 'railties') diff --git a/railties/test/application/asset_debugging_test.rb b/railties/test/application/asset_debugging_test.rb index 707abe7191..1b99af22a4 100644 --- a/railties/test/application/asset_debugging_test.rb +++ b/railties/test/application/asset_debugging_test.rb @@ -45,8 +45,8 @@ module ApplicationTests # the debug_assets params isn't used if compile is off get '/posts?debug_assets=true' - assert_match / -Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-validate+ Cache-Control HTTP header to reduce request overhead on subsequent requests -- on these the browser gets a 304 (not-modified) response. +Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-revalidate+ Cache-Control HTTP header to reduce request overhead on subsequent requests -- on these the browser gets a 304 (not-modified) response. If any of the files in the manifest have changed between requests, the server responds with a new compiled file. -- cgit v1.2.3 From e47bb1cbe7bb33318f2ed2f1ca021ddd71f6c50f Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 11 Sep 2011 19:44:42 +0530 Subject: merged the contribution guides and changed the link in the layout accordingly --- railties/guides/source/contributing_to_ruby_on_rails.textile | 10 ++++++---- railties/guides/source/layout.html.erb | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index c302d393aa..968fa7a1f1 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -257,16 +257,18 @@ h3. Contributing to the Rails Documentation Ruby on Rails has two main sets of documentation: The guides help you to learn Ruby on Rails, and the API is a reference. -You can create an issue in GitHub issues to fix or expand documentation. However, if you're confident about your changes you can push them yourself directly via "docrails":https://github.com/lifo/docrails/tree/master. docrails is a branch with an *open commit policy* and public write access. Commits to docrails are still reviewed, but that happens after they are pushed. docrails is merged with master regularly, so you are effectively editing the Ruby on Rails documentation. +You can help improve the Rails guides by making them more coherent, adding missing information, correcting factual errors, fixing typos, bringing it up to date with the latest edge Rails. To get involved in the translation of Rails guides, please see "Translating Rails Guides":https://wiki.github.com/lifo/docrails/translating-rails-guides. + +If you're confident about your changes, you can push them yourself directly via "docrails":https://github.com/lifo/docrails. docrails is a branch with an *open commit policy* and public write access. Commits to docrails are still reviewed, but that happens after they are pushed. docrails is merged with master regularly, so you are effectively editing the Ruby on Rails documentation. + +If you are unsure of the documentation changes, you can create an issue in the "Rails":https://github.com/rails/rails repository on GitHub. When working with documentation, please take into account the "API Documentation Guidelines":api_documentation_guidelines.html and the "Ruby on Rails Guides Guidelines":ruby_on_rails_guides_guidelines.html. -NOTE: As explained above, ordinary code patches should have proper documentation coverage. docrails is only used for isolated documentation improvements. +NOTE: As explained earlier, ordinary code patches should have proper documentation coverage. docrails is only used for isolated documentation improvements. WARNING: docrails has a very strict policy: no code can be touched whatsoever, no matter how trivial or small the change. Only RDoc and guides can be edited via docrails. Also, CHANGELOGs should never be edited in docrails. -If you have an idea for a new guide you can refer to the "contribution page":contribute.html for instructions on getting involved. - h3. Contributing to the Rails Code h4. Clone the Rails Repository diff --git a/railties/guides/source/layout.html.erb b/railties/guides/source/layout.html.erb index 4ef569013c..4c979888b7 100644 --- a/railties/guides/source/layout.html.erb +++ b/railties/guides/source/layout.html.erb @@ -91,7 +91,7 @@
-
  • Contribute
  • +
  • Contribute
  • Credits
  • -- cgit v1.2.3 From 6e782f8944122e99091b38b07dcc777f02b1836c Mon Sep 17 00:00:00 2001 From: Alan Zeino Date: Mon, 12 Sep 2011 11:12:09 +1000 Subject: Slight change to reflect current 'destroy' code generated by scaffold in 3.1 release. --- railties/guides/source/getting_started.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 1587b20c18..219fa5afde 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1083,8 +1083,8 @@ def destroy @post.destroy respond_to do |format| - format.html { redirect_to(posts_url) } - format.json { render :json => {}, :status => :ok } + format.html { redirect_to posts_url } + format.json { head :ok } end end -- cgit v1.2.3 From d7154d483269fc25d771d5b8b7b8a2c889e4b3f5 Mon Sep 17 00:00:00 2001 From: James Gifford Date: Mon, 12 Sep 2011 10:30:45 -0400 Subject: Added getting_started code, updated guide with link to rails github repo and path to code --- railties/guides/code/getting_started/Gemfile | 32 +++ railties/guides/code/getting_started/README | 261 +++++++++++++++++++++ railties/guides/code/getting_started/Rakefile | 7 + .../getting_started/app/assets/images/rails.png | Bin 0 -> 6646 bytes .../app/assets/javascripts/application.js | 9 + .../app/assets/javascripts/comments.js.coffee | 3 + .../app/assets/javascripts/home.js.coffee | 3 + .../app/assets/javascripts/posts.js.coffee | 3 + .../app/assets/stylesheets/application.css | 7 + .../app/assets/stylesheets/comments.css.scss | 3 + .../app/assets/stylesheets/home.css.scss | 3 + .../app/assets/stylesheets/posts.css.scss | 3 + .../app/assets/stylesheets/scaffolds.css.scss | 56 +++++ .../app/controllers/application_controller.rb | 3 + .../app/controllers/comments_controller.rb | 16 ++ .../app/controllers/home_controller.rb | 5 + .../app/controllers/posts_controller.rb | 84 +++++++ .../app/helpers/application_helper.rb | 2 + .../getting_started/app/helpers/comments_helper.rb | 2 + .../getting_started/app/helpers/home_helper.rb | 2 + .../getting_started/app/helpers/posts_helper.rb | 5 + .../code/getting_started/app/mailers/.gitkeep | 0 .../code/getting_started/app/models/.gitkeep | 0 .../code/getting_started/app/models/comment.rb | 3 + .../guides/code/getting_started/app/models/post.rb | 11 + .../guides/code/getting_started/app/models/tag.rb | 3 + .../app/views/comments/_comment.html.erb | 15 ++ .../app/views/comments/_form.html.erb | 13 + .../getting_started/app/views/home/index.html.erb | 2 + .../getting_started/app/views/home/index.html.erb~ | 2 + .../app/views/layouts/application.html.erb | 14 ++ .../getting_started/app/views/posts/_form.html.erb | 32 +++ .../getting_started/app/views/posts/edit.html.erb | 6 + .../getting_started/app/views/posts/index.html.erb | 27 +++ .../getting_started/app/views/posts/new.html.erb | 5 + .../getting_started/app/views/posts/show.html.erb | 31 +++ .../getting_started/app/views/tags/_form.html.erb | 12 + railties/guides/code/getting_started/config.ru | 4 + .../code/getting_started/config/application.rb | 48 ++++ .../guides/code/getting_started/config/boot.rb | 6 + .../code/getting_started/config/database.yml | 25 ++ .../code/getting_started/config/environment.rb | 5 + .../config/environments/development.rb | 30 +++ .../config/environments/production.rb | 60 +++++ .../getting_started/config/environments/test.rb | 42 ++++ .../config/initializers/backtrace_silencers.rb | 7 + .../config/initializers/inflections.rb | 10 + .../config/initializers/mime_types.rb | 5 + .../config/initializers/secret_token.rb | 7 + .../config/initializers/session_store.rb | 8 + .../config/initializers/wrap_parameters.rb | 14 ++ .../code/getting_started/config/locales/en.yml | 5 + .../guides/code/getting_started/config/routes.rb | 64 +++++ .../guides/code/getting_started/config/routes.rb~ | 60 +++++ .../db/migrate/20110901012504_create_posts.rb | 11 + .../db/migrate/20110901012815_create_comments.rb | 12 + .../db/migrate/20110901013701_create_tags.rb | 11 + railties/guides/code/getting_started/db/schema.rb | 43 ++++ railties/guides/code/getting_started/db/seeds.rb | 7 + .../guides/code/getting_started/doc/README_FOR_APP | 2 + .../code/getting_started/lib/assets/.gitkeep | 0 .../guides/code/getting_started/lib/tasks/.gitkeep | 0 .../guides/code/getting_started/public/404.html | 26 ++ .../guides/code/getting_started/public/422.html | 26 ++ .../guides/code/getting_started/public/500.html | 26 ++ .../guides/code/getting_started/public/favicon.ico | 0 .../guides/code/getting_started/public/robots.txt | 5 + railties/guides/code/getting_started/script/rails | 6 + .../code/getting_started/test/fixtures/.gitkeep | 0 .../getting_started/test/fixtures/comments.yml | 11 + .../code/getting_started/test/fixtures/posts.yml | 11 + .../code/getting_started/test/fixtures/tags.yml | 9 + .../code/getting_started/test/functional/.gitkeep | 0 .../test/functional/comments_controller_test.rb | 7 + .../test/functional/home_controller_test.rb | 9 + .../test/functional/posts_controller_test.rb | 49 ++++ .../code/getting_started/test/integration/.gitkeep | 0 .../test/performance/browsing_test.rb | 12 + .../code/getting_started/test/test_helper.rb | 13 + .../guides/code/getting_started/test/unit/.gitkeep | 0 .../code/getting_started/test/unit/comment_test.rb | 7 + .../test/unit/helpers/comments_helper_test.rb | 4 + .../test/unit/helpers/home_helper_test.rb | 4 + .../test/unit/helpers/posts_helper_test.rb | 4 + .../code/getting_started/test/unit/post_test.rb | 7 + .../code/getting_started/test/unit/tag_test.rb | 7 + .../vendor/assets/stylesheets/.gitkeep | 0 .../code/getting_started/vendor/plugins/.gitkeep | 0 railties/guides/source/getting_started.textile | 3 + 89 files changed, 1417 insertions(+) create mode 100644 railties/guides/code/getting_started/Gemfile create mode 100644 railties/guides/code/getting_started/README create mode 100644 railties/guides/code/getting_started/Rakefile create mode 100644 railties/guides/code/getting_started/app/assets/images/rails.png create mode 100644 railties/guides/code/getting_started/app/assets/javascripts/application.js create mode 100644 railties/guides/code/getting_started/app/assets/javascripts/comments.js.coffee create mode 100644 railties/guides/code/getting_started/app/assets/javascripts/home.js.coffee create mode 100644 railties/guides/code/getting_started/app/assets/javascripts/posts.js.coffee create mode 100644 railties/guides/code/getting_started/app/assets/stylesheets/application.css create mode 100644 railties/guides/code/getting_started/app/assets/stylesheets/comments.css.scss create mode 100644 railties/guides/code/getting_started/app/assets/stylesheets/home.css.scss create mode 100644 railties/guides/code/getting_started/app/assets/stylesheets/posts.css.scss create mode 100644 railties/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss create mode 100644 railties/guides/code/getting_started/app/controllers/application_controller.rb create mode 100644 railties/guides/code/getting_started/app/controllers/comments_controller.rb create mode 100644 railties/guides/code/getting_started/app/controllers/home_controller.rb create mode 100644 railties/guides/code/getting_started/app/controllers/posts_controller.rb create mode 100644 railties/guides/code/getting_started/app/helpers/application_helper.rb create mode 100644 railties/guides/code/getting_started/app/helpers/comments_helper.rb create mode 100644 railties/guides/code/getting_started/app/helpers/home_helper.rb create mode 100644 railties/guides/code/getting_started/app/helpers/posts_helper.rb create mode 100644 railties/guides/code/getting_started/app/mailers/.gitkeep create mode 100644 railties/guides/code/getting_started/app/models/.gitkeep create mode 100644 railties/guides/code/getting_started/app/models/comment.rb create mode 100644 railties/guides/code/getting_started/app/models/post.rb create mode 100644 railties/guides/code/getting_started/app/models/tag.rb create mode 100644 railties/guides/code/getting_started/app/views/comments/_comment.html.erb create mode 100644 railties/guides/code/getting_started/app/views/comments/_form.html.erb create mode 100644 railties/guides/code/getting_started/app/views/home/index.html.erb create mode 100644 railties/guides/code/getting_started/app/views/home/index.html.erb~ create mode 100644 railties/guides/code/getting_started/app/views/layouts/application.html.erb create mode 100644 railties/guides/code/getting_started/app/views/posts/_form.html.erb create mode 100644 railties/guides/code/getting_started/app/views/posts/edit.html.erb create mode 100644 railties/guides/code/getting_started/app/views/posts/index.html.erb create mode 100644 railties/guides/code/getting_started/app/views/posts/new.html.erb create mode 100644 railties/guides/code/getting_started/app/views/posts/show.html.erb create mode 100644 railties/guides/code/getting_started/app/views/tags/_form.html.erb create mode 100644 railties/guides/code/getting_started/config.ru create mode 100644 railties/guides/code/getting_started/config/application.rb create mode 100644 railties/guides/code/getting_started/config/boot.rb create mode 100644 railties/guides/code/getting_started/config/database.yml create mode 100644 railties/guides/code/getting_started/config/environment.rb create mode 100644 railties/guides/code/getting_started/config/environments/development.rb create mode 100644 railties/guides/code/getting_started/config/environments/production.rb create mode 100644 railties/guides/code/getting_started/config/environments/test.rb create mode 100644 railties/guides/code/getting_started/config/initializers/backtrace_silencers.rb create mode 100644 railties/guides/code/getting_started/config/initializers/inflections.rb create mode 100644 railties/guides/code/getting_started/config/initializers/mime_types.rb create mode 100644 railties/guides/code/getting_started/config/initializers/secret_token.rb create mode 100644 railties/guides/code/getting_started/config/initializers/session_store.rb create mode 100644 railties/guides/code/getting_started/config/initializers/wrap_parameters.rb create mode 100644 railties/guides/code/getting_started/config/locales/en.yml create mode 100644 railties/guides/code/getting_started/config/routes.rb create mode 100644 railties/guides/code/getting_started/config/routes.rb~ create mode 100644 railties/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb create mode 100644 railties/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb create mode 100644 railties/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb create mode 100644 railties/guides/code/getting_started/db/schema.rb create mode 100644 railties/guides/code/getting_started/db/seeds.rb create mode 100644 railties/guides/code/getting_started/doc/README_FOR_APP create mode 100644 railties/guides/code/getting_started/lib/assets/.gitkeep create mode 100644 railties/guides/code/getting_started/lib/tasks/.gitkeep create mode 100644 railties/guides/code/getting_started/public/404.html create mode 100644 railties/guides/code/getting_started/public/422.html create mode 100644 railties/guides/code/getting_started/public/500.html create mode 100644 railties/guides/code/getting_started/public/favicon.ico create mode 100644 railties/guides/code/getting_started/public/robots.txt create mode 100755 railties/guides/code/getting_started/script/rails create mode 100644 railties/guides/code/getting_started/test/fixtures/.gitkeep create mode 100644 railties/guides/code/getting_started/test/fixtures/comments.yml create mode 100644 railties/guides/code/getting_started/test/fixtures/posts.yml create mode 100644 railties/guides/code/getting_started/test/fixtures/tags.yml create mode 100644 railties/guides/code/getting_started/test/functional/.gitkeep create mode 100644 railties/guides/code/getting_started/test/functional/comments_controller_test.rb create mode 100644 railties/guides/code/getting_started/test/functional/home_controller_test.rb create mode 100644 railties/guides/code/getting_started/test/functional/posts_controller_test.rb create mode 100644 railties/guides/code/getting_started/test/integration/.gitkeep create mode 100644 railties/guides/code/getting_started/test/performance/browsing_test.rb create mode 100644 railties/guides/code/getting_started/test/test_helper.rb create mode 100644 railties/guides/code/getting_started/test/unit/.gitkeep create mode 100644 railties/guides/code/getting_started/test/unit/comment_test.rb create mode 100644 railties/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb create mode 100644 railties/guides/code/getting_started/test/unit/helpers/home_helper_test.rb create mode 100644 railties/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb create mode 100644 railties/guides/code/getting_started/test/unit/post_test.rb create mode 100644 railties/guides/code/getting_started/test/unit/tag_test.rb create mode 100644 railties/guides/code/getting_started/vendor/assets/stylesheets/.gitkeep create mode 100644 railties/guides/code/getting_started/vendor/plugins/.gitkeep (limited to 'railties') diff --git a/railties/guides/code/getting_started/Gemfile b/railties/guides/code/getting_started/Gemfile new file mode 100644 index 0000000000..51774934cd --- /dev/null +++ b/railties/guides/code/getting_started/Gemfile @@ -0,0 +1,32 @@ +source 'http://rubygems.org' + +gem 'rails', '3.1.0' +# Bundle edge Rails instead: +# gem 'rails', :git => 'git://github.com/rails/rails.git' + +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 + +gem 'jquery-rails' + +# Use unicorn as the web server +# gem 'unicorn' + +# Deploy with Capistrano +# gem 'capistrano' + +# To use debugger +# gem 'ruby-debug19', :require => 'ruby-debug' + +group :test do + # Pretty printed test output + gem 'turn', :require => false +end diff --git a/railties/guides/code/getting_started/README b/railties/guides/code/getting_started/README new file mode 100644 index 0000000000..7c36f2356e --- /dev/null +++ b/railties/guides/code/getting_started/README @@ -0,0 +1,261 @@ +== Welcome to Rails + +Rails is a web-application framework that includes everything needed to create +database-backed web applications according to the Model-View-Control pattern. + +This pattern splits the view (also called the presentation) into "dumb" +templates that are primarily responsible for inserting pre-built data in between +HTML tags. The model contains the "smart" domain objects (such as Account, +Product, Person, Post) that holds all the business logic and knows how to +persist themselves to a database. The controller handles the incoming requests +(such as Save New Account, Update Product, Show Post) by manipulating the model +and directing data to the view. + +In Rails, the model is handled by what's called an object-relational mapping +layer entitled Active Record. This layer allows you to present the data from +database rows as objects and embellish these data objects with business logic +methods. You can read more about Active Record in +link:files/vendor/rails/activerecord/README.html. + +The controller and view are handled by the Action Pack, which handles both +layers by its two parts: Action View and Action Controller. These two layers +are bundled in a single package due to their heavy interdependence. This is +unlike the relationship between the Active Record and Action Pack that is much +more separate. Each of these packages can be used independently outside of +Rails. You can read more about Action Pack in +link:files/vendor/rails/actionpack/README.html. + + +== Getting Started + +1. At the command prompt, create a new Rails application: + 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/railties/guides/code/getting_started/Rakefile b/railties/guides/code/getting_started/Rakefile new file mode 100644 index 0000000000..e1d1ec8615 --- /dev/null +++ b/railties/guides/code/getting_started/Rakefile @@ -0,0 +1,7 @@ +#!/usr/bin/env rake +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) + +Blog::Application.load_tasks diff --git a/railties/guides/code/getting_started/app/assets/images/rails.png b/railties/guides/code/getting_started/app/assets/images/rails.png new file mode 100644 index 0000000000..d5edc04e65 Binary files /dev/null and b/railties/guides/code/getting_started/app/assets/images/rails.png differ diff --git a/railties/guides/code/getting_started/app/assets/javascripts/application.js b/railties/guides/code/getting_started/app/assets/javascripts/application.js new file mode 100644 index 0000000000..37c7bfcdb5 --- /dev/null +++ b/railties/guides/code/getting_started/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/railties/guides/code/getting_started/app/assets/javascripts/comments.js.coffee b/railties/guides/code/getting_started/app/assets/javascripts/comments.js.coffee new file mode 100644 index 0000000000..761567942f --- /dev/null +++ b/railties/guides/code/getting_started/app/assets/javascripts/comments.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/railties/guides/code/getting_started/app/assets/javascripts/home.js.coffee b/railties/guides/code/getting_started/app/assets/javascripts/home.js.coffee new file mode 100644 index 0000000000..761567942f --- /dev/null +++ b/railties/guides/code/getting_started/app/assets/javascripts/home.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/railties/guides/code/getting_started/app/assets/javascripts/posts.js.coffee b/railties/guides/code/getting_started/app/assets/javascripts/posts.js.coffee new file mode 100644 index 0000000000..761567942f --- /dev/null +++ b/railties/guides/code/getting_started/app/assets/javascripts/posts.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/railties/guides/code/getting_started/app/assets/stylesheets/application.css b/railties/guides/code/getting_started/app/assets/stylesheets/application.css new file mode 100644 index 0000000000..fc25b5723f --- /dev/null +++ b/railties/guides/code/getting_started/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 . +*/ \ No newline at end of file diff --git a/railties/guides/code/getting_started/app/assets/stylesheets/comments.css.scss b/railties/guides/code/getting_started/app/assets/stylesheets/comments.css.scss new file mode 100644 index 0000000000..e730912783 --- /dev/null +++ b/railties/guides/code/getting_started/app/assets/stylesheets/comments.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Comments controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/railties/guides/code/getting_started/app/assets/stylesheets/home.css.scss b/railties/guides/code/getting_started/app/assets/stylesheets/home.css.scss new file mode 100644 index 0000000000..f0ddc6846a --- /dev/null +++ b/railties/guides/code/getting_started/app/assets/stylesheets/home.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the home controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/railties/guides/code/getting_started/app/assets/stylesheets/posts.css.scss b/railties/guides/code/getting_started/app/assets/stylesheets/posts.css.scss new file mode 100644 index 0000000000..ed4dfd10f2 --- /dev/null +++ b/railties/guides/code/getting_started/app/assets/stylesheets/posts.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Posts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/railties/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss b/railties/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 0000000000..05188f08ed --- /dev/null +++ b/railties/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss @@ -0,0 +1,56 @@ +body { + background-color: #fff; + color: #333; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; } + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; } + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; } + +a { + color: #000; + &:visited { + color: #666; } + &:hover { + color: #fff; + background-color: #000; } } + +div { + &.field, &.actions { + margin-bottom: 10px; } } + +#notice { + color: green; } + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; } + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px; + padding-bottom: 0; + margin-bottom: 20px; + background-color: #f0f0f0; + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + margin-bottom: 0px; + background-color: #c00; + color: #fff; } + ul li { + font-size: 12px; + list-style: square; } } diff --git a/railties/guides/code/getting_started/app/controllers/application_controller.rb b/railties/guides/code/getting_started/app/controllers/application_controller.rb new file mode 100644 index 0000000000..e8065d9505 --- /dev/null +++ b/railties/guides/code/getting_started/app/controllers/application_controller.rb @@ -0,0 +1,3 @@ +class ApplicationController < ActionController::Base + protect_from_forgery +end diff --git a/railties/guides/code/getting_started/app/controllers/comments_controller.rb b/railties/guides/code/getting_started/app/controllers/comments_controller.rb new file mode 100644 index 0000000000..7447fd078b --- /dev/null +++ b/railties/guides/code/getting_started/app/controllers/comments_controller.rb @@ -0,0 +1,16 @@ +class CommentsController < ApplicationController + http_basic_authenticate_with :name => "dhh", :password => "secret", :only => :destroy + def create + @post = Post.find(params[:post_id]) + @comment = @post.comments.create(params[:comment]) + redirect_to post_path(@post) + end + + def destroy + @post = Post.find(params[:post_id]) + @comment = @post.comments.find(params[:id]) + @comment.destroy + redirect_to post_path(@post) + end + +end diff --git a/railties/guides/code/getting_started/app/controllers/home_controller.rb b/railties/guides/code/getting_started/app/controllers/home_controller.rb new file mode 100644 index 0000000000..6cc31c1ca3 --- /dev/null +++ b/railties/guides/code/getting_started/app/controllers/home_controller.rb @@ -0,0 +1,5 @@ +class HomeController < ApplicationController + def index + end + +end diff --git a/railties/guides/code/getting_started/app/controllers/posts_controller.rb b/railties/guides/code/getting_started/app/controllers/posts_controller.rb new file mode 100644 index 0000000000..7e903c984c --- /dev/null +++ b/railties/guides/code/getting_started/app/controllers/posts_controller.rb @@ -0,0 +1,84 @@ +class PostsController < ApplicationController + http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index + # GET /posts + # GET /posts.json + def index + @posts = Post.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @posts } + end + end + + # GET /posts/1 + # GET /posts/1.json + def show + @post = Post.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @post } + end + end + + # GET /posts/new + # GET /posts/new.json + def new + @post = Post.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @post } + end + end + + # GET /posts/1/edit + def edit + @post = Post.find(params[:id]) + end + + # POST /posts + # POST /posts.json + def create + @post = Post.new(params[:post]) + + respond_to do |format| + if @post.save + format.html { redirect_to @post, notice: 'Post was successfully created.' } + format.json { render json: @post, status: :created, location: @post } + else + format.html { render action: "new" } + format.json { render json: @post.errors, status: :unprocessable_entity } + end + end + end + + # PUT /posts/1 + # PUT /posts/1.json + def update + @post = Post.find(params[:id]) + + respond_to do |format| + if @post.update_attributes(params[:post]) + format.html { redirect_to @post, notice: 'Post was successfully updated.' } + format.json { head :ok } + else + format.html { render action: "edit" } + format.json { render json: @post.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /posts/1 + # DELETE /posts/1.json + def destroy + @post = Post.find(params[:id]) + @post.destroy + + respond_to do |format| + format.html { redirect_to posts_url } + format.json { head :ok } + end + end +end diff --git a/railties/guides/code/getting_started/app/helpers/application_helper.rb b/railties/guides/code/getting_started/app/helpers/application_helper.rb new file mode 100644 index 0000000000..de6be7945c --- /dev/null +++ b/railties/guides/code/getting_started/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/railties/guides/code/getting_started/app/helpers/comments_helper.rb b/railties/guides/code/getting_started/app/helpers/comments_helper.rb new file mode 100644 index 0000000000..0ec9ca5f2d --- /dev/null +++ b/railties/guides/code/getting_started/app/helpers/comments_helper.rb @@ -0,0 +1,2 @@ +module CommentsHelper +end diff --git a/railties/guides/code/getting_started/app/helpers/home_helper.rb b/railties/guides/code/getting_started/app/helpers/home_helper.rb new file mode 100644 index 0000000000..23de56ac60 --- /dev/null +++ b/railties/guides/code/getting_started/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/railties/guides/code/getting_started/app/helpers/posts_helper.rb b/railties/guides/code/getting_started/app/helpers/posts_helper.rb new file mode 100644 index 0000000000..b6e8e67894 --- /dev/null +++ b/railties/guides/code/getting_started/app/helpers/posts_helper.rb @@ -0,0 +1,5 @@ +module PostsHelper + def join_tags(post) + post.tags.map { |t| t.name }.join(", ") + end +end diff --git a/railties/guides/code/getting_started/app/mailers/.gitkeep b/railties/guides/code/getting_started/app/mailers/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/guides/code/getting_started/app/models/.gitkeep b/railties/guides/code/getting_started/app/models/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/guides/code/getting_started/app/models/comment.rb b/railties/guides/code/getting_started/app/models/comment.rb new file mode 100644 index 0000000000..4e76c5b5b0 --- /dev/null +++ b/railties/guides/code/getting_started/app/models/comment.rb @@ -0,0 +1,3 @@ +class Comment < ActiveRecord::Base + belongs_to :post +end diff --git a/railties/guides/code/getting_started/app/models/post.rb b/railties/guides/code/getting_started/app/models/post.rb new file mode 100644 index 0000000000..61c2b5ae44 --- /dev/null +++ b/railties/guides/code/getting_started/app/models/post.rb @@ -0,0 +1,11 @@ +class Post < ActiveRecord::Base + validates :name, :presence => true + validates :title, :presence => true, + :length => { :minimum => 5 } + + has_many :comments, :dependent => :destroy + has_many :tags + + accepts_nested_attributes_for :tags, :allow_destroy => :true, + :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } } +end diff --git a/railties/guides/code/getting_started/app/models/tag.rb b/railties/guides/code/getting_started/app/models/tag.rb new file mode 100644 index 0000000000..30992e8ba9 --- /dev/null +++ b/railties/guides/code/getting_started/app/models/tag.rb @@ -0,0 +1,3 @@ +class Tag < ActiveRecord::Base + belongs_to :post +end diff --git a/railties/guides/code/getting_started/app/views/comments/_comment.html.erb b/railties/guides/code/getting_started/app/views/comments/_comment.html.erb new file mode 100644 index 0000000000..4c3fbf26cd --- /dev/null +++ b/railties/guides/code/getting_started/app/views/comments/_comment.html.erb @@ -0,0 +1,15 @@ +

    + Commenter: + <%= comment.commenter %> +

    + +

    + Comment: + <%= comment.body %> +

    + +

    + <%= link_to 'Destroy Comment', [comment.post, comment], + :confirm => 'Are you sure?', + :method => :delete %> +

    diff --git a/railties/guides/code/getting_started/app/views/comments/_form.html.erb b/railties/guides/code/getting_started/app/views/comments/_form.html.erb new file mode 100644 index 0000000000..d15bdd6b59 --- /dev/null +++ b/railties/guides/code/getting_started/app/views/comments/_form.html.erb @@ -0,0 +1,13 @@ +<%= form_for([@post, @post.comments.build]) do |f| %> +
    + <%= f.label :commenter %>
    + <%= f.text_field :commenter %> +
    +
    + <%= f.label :body %>
    + <%= f.text_area :body %> +
    +
    + <%= f.submit %> +
    +<% end %> diff --git a/railties/guides/code/getting_started/app/views/home/index.html.erb b/railties/guides/code/getting_started/app/views/home/index.html.erb new file mode 100644 index 0000000000..bb4f3dcd1f --- /dev/null +++ b/railties/guides/code/getting_started/app/views/home/index.html.erb @@ -0,0 +1,2 @@ +

    Hello, Rails!

    +<%= link_to "My Blog", posts_path %> diff --git a/railties/guides/code/getting_started/app/views/home/index.html.erb~ b/railties/guides/code/getting_started/app/views/home/index.html.erb~ new file mode 100644 index 0000000000..2085730c72 --- /dev/null +++ b/railties/guides/code/getting_started/app/views/home/index.html.erb~ @@ -0,0 +1,2 @@ +

    Home#index

    +

    Find me in app/views/home/index.html.erb

    diff --git a/railties/guides/code/getting_started/app/views/layouts/application.html.erb b/railties/guides/code/getting_started/app/views/layouts/application.html.erb new file mode 100644 index 0000000000..1e1e4b9a99 --- /dev/null +++ b/railties/guides/code/getting_started/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + Blog + <%= stylesheet_link_tag "application" %> + <%= javascript_include_tag "application" %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/railties/guides/code/getting_started/app/views/posts/_form.html.erb b/railties/guides/code/getting_started/app/views/posts/_form.html.erb new file mode 100644 index 0000000000..e27da7f413 --- /dev/null +++ b/railties/guides/code/getting_started/app/views/posts/_form.html.erb @@ -0,0 +1,32 @@ +<% @post.tags.build %> +<%= form_for(@post) do |post_form| %> + <% if @post.errors.any? %> +
    +

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

    +
      + <% @post.errors.full_messages.each do |msg| %> +
    • <%= msg %>
    • + <% end %> +
    +
    + <% end %> + +
    + <%= post_form.label :name %>
    + <%= post_form.text_field :name %> +
    +
    + <%= post_form.label :title %>
    + <%= post_form.text_field :title %> +
    +
    + <%= post_form.label :content %>
    + <%= post_form.text_area :content %> +
    +

    Tags

    + <%= render :partial => 'tags/form', + :locals => {:form => post_form} %> +
    + <%= post_form.submit %> +
    +<% end %> diff --git a/railties/guides/code/getting_started/app/views/posts/edit.html.erb b/railties/guides/code/getting_started/app/views/posts/edit.html.erb new file mode 100644 index 0000000000..720580236b --- /dev/null +++ b/railties/guides/code/getting_started/app/views/posts/edit.html.erb @@ -0,0 +1,6 @@ +

    Editing post

    + +<%= render 'form' %> + +<%= link_to 'Show', @post %> | +<%= link_to 'Back', posts_path %> diff --git a/railties/guides/code/getting_started/app/views/posts/index.html.erb b/railties/guides/code/getting_started/app/views/posts/index.html.erb new file mode 100644 index 0000000000..45dee1b25f --- /dev/null +++ b/railties/guides/code/getting_started/app/views/posts/index.html.erb @@ -0,0 +1,27 @@ +

    Listing posts

    + + + + + + + + + + + +<% @posts.each do |post| %> + + + + + + + + +<% end %> +
    NameTitleContent
    <%= post.name %><%= post.title %><%= post.content %><%= link_to 'Show', post %><%= link_to 'Edit', edit_post_path(post) %><%= link_to 'Destroy', post, confirm: 'Are you sure?', method: :delete %>
    + +
    + +<%= link_to 'New Post', new_post_path %> diff --git a/railties/guides/code/getting_started/app/views/posts/new.html.erb b/railties/guides/code/getting_started/app/views/posts/new.html.erb new file mode 100644 index 0000000000..36ad7421f9 --- /dev/null +++ b/railties/guides/code/getting_started/app/views/posts/new.html.erb @@ -0,0 +1,5 @@ +

    New post

    + +<%= render 'form' %> + +<%= link_to 'Back', posts_path %> diff --git a/railties/guides/code/getting_started/app/views/posts/show.html.erb b/railties/guides/code/getting_started/app/views/posts/show.html.erb new file mode 100644 index 0000000000..da78a9527b --- /dev/null +++ b/railties/guides/code/getting_started/app/views/posts/show.html.erb @@ -0,0 +1,31 @@ +

    <%= notice %>

    + +

    + Name: + <%= @post.name %> +

    + +

    + Title: + <%= @post.title %> +

    + +

    + Content: + <%= @post.content %> +

    + +

    + Tags: + <%= join_tags(@post) %> +

    + +

    Comments

    +<%= render @post.comments %> + +

    Add a comment:

    +<%= render "comments/form" %> + + +<%= link_to 'Edit Post', edit_post_path(@post) %> | +<%= link_to 'Back to Posts', posts_path %> | diff --git a/railties/guides/code/getting_started/app/views/tags/_form.html.erb b/railties/guides/code/getting_started/app/views/tags/_form.html.erb new file mode 100644 index 0000000000..7e424b0e20 --- /dev/null +++ b/railties/guides/code/getting_started/app/views/tags/_form.html.erb @@ -0,0 +1,12 @@ +<%= form.fields_for :tags do |tag_form| %> +
    + <%= tag_form.label :name, 'Tag:' %> + <%= tag_form.text_field :name %> +
    + <% unless tag_form.object.nil? || tag_form.object.new_record? %> +
    + <%= tag_form.label :_destroy, 'Remove:' %> + <%= tag_form.check_box :_destroy %> +
    + <% end %> +<% end %> diff --git a/railties/guides/code/getting_started/config.ru b/railties/guides/code/getting_started/config.ru new file mode 100644 index 0000000000..ddf869e921 --- /dev/null +++ b/railties/guides/code/getting_started/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Blog::Application diff --git a/railties/guides/code/getting_started/config/application.rb b/railties/guides/code/getting_started/config/application.rb new file mode 100644 index 0000000000..e914b5a80e --- /dev/null +++ b/railties/guides/code/getting_started/config/application.rb @@ -0,0 +1,48 @@ +require File.expand_path('../boot', __FILE__) + +require 'rails/all' + +if defined?(Bundler) + # If you precompile assets before deploying to production, use this line + Bundler.require *Rails.groups(:assets => %w(development test)) + # If you want your assets lazily compiled in production, use this line + # Bundler.require(:default, :assets, Rails.env) +end + +module Blog + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Custom directories with classes and modules you want to be autoloadable. + # config.autoload_paths += %W(#{config.root}/extras) + + # Only load the plugins named here, in the order given (default is alphabetical). + # :all can be used as a placeholder for all plugins not explicitly named. + # config.plugins = [ :exception_notification, :ssl_requirement, :all ] + + # Activate observers that should always be running. + # config.active_record.observers = :cacher, :garbage_collector, :forum_observer + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # config.time_zone = 'Central Time (US & Canada)' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de + + # Configure the default encoding used in templates for Ruby 1.9. + config.encoding = "utf-8" + + # Configure sensitive parameters which will be filtered from the log file. + config.filter_parameters += [:password] + + # Enable the asset pipeline + config.assets.enabled = true + + # Version of your assets, change this if you want to expire all your assets + config.assets.version = '1.0' + end +end diff --git a/railties/guides/code/getting_started/config/boot.rb b/railties/guides/code/getting_started/config/boot.rb new file mode 100644 index 0000000000..4489e58688 --- /dev/null +++ b/railties/guides/code/getting_started/config/boot.rb @@ -0,0 +1,6 @@ +require 'rubygems' + +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) diff --git a/railties/guides/code/getting_started/config/database.yml b/railties/guides/code/getting_started/config/database.yml new file mode 100644 index 0000000000..51a4dd459d --- /dev/null +++ b/railties/guides/code/getting_started/config/database.yml @@ -0,0 +1,25 @@ +# 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 + pool: 5 + timeout: 5000 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + adapter: sqlite3 + database: db/test.sqlite3 + pool: 5 + timeout: 5000 + +production: + adapter: sqlite3 + database: db/production.sqlite3 + pool: 5 + timeout: 5000 diff --git a/railties/guides/code/getting_started/config/environment.rb b/railties/guides/code/getting_started/config/environment.rb new file mode 100644 index 0000000000..8f728b7ce7 --- /dev/null +++ b/railties/guides/code/getting_started/config/environment.rb @@ -0,0 +1,5 @@ +# Load the rails application +require File.expand_path('../application', __FILE__) + +# Initialize the rails application +Blog::Application.initialize! diff --git a/railties/guides/code/getting_started/config/environments/development.rb b/railties/guides/code/getting_started/config/environments/development.rb new file mode 100644 index 0000000000..89932bf19b --- /dev/null +++ b/railties/guides/code/getting_started/config/environments/development.rb @@ -0,0 +1,30 @@ +Blog::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 + # every request. This slows down response time but is perfect for development + # 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. + config.whiny_nils = true + + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger + config.active_support.deprecation = :log + + # Only use best-standards-support built into browsers + config.action_dispatch.best_standards_support = :builtin + + # Do not compress assets + config.assets.compress = false + + # Expands the lines which load the assets + config.assets.debug = true +end diff --git a/railties/guides/code/getting_started/config/environments/production.rb b/railties/guides/code/getting_started/config/environments/production.rb new file mode 100644 index 0000000000..6ab63d30a6 --- /dev/null +++ b/railties/guides/code/getting_started/config/environments/production.rb @@ -0,0 +1,60 @@ +Blog::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # Code is not reloaded between requests + config.cache_classes = true + + # Full error reports are disabled and caching is turned on + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # 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 + + # Defaults to Rails.root.join("public/assets") + # config.assets.manifest = YOUR_PATH + + # 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 + + # Use a different logger for distributed setups + # config.logger = SyslogLogger.new + + # Use a different cache store in production + # config.cache_store = :mem_cache_store + + # 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 + + # Enable threaded mode + # config.threadsafe! + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found) + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners + config.active_support.deprecation = :notify +end diff --git a/railties/guides/code/getting_started/config/environments/test.rb b/railties/guides/code/getting_started/config/environments/test.rb new file mode 100644 index 0000000000..833241ace3 --- /dev/null +++ b/railties/guides/code/getting_started/config/environments/test.rb @@ -0,0 +1,42 @@ +Blog::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 + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # 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 + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Use SQL instead of Active Record's schema dumper when creating the test database. + # This is necessary if your schema can't be completely dumped by the schema dumper, + # like if you have constraints or database-specific column types + # config.active_record.schema_format = :sql + + # 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/railties/guides/code/getting_started/config/initializers/backtrace_silencers.rb b/railties/guides/code/getting_started/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000000..59385cdf37 --- /dev/null +++ b/railties/guides/code/getting_started/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/railties/guides/code/getting_started/config/initializers/inflections.rb b/railties/guides/code/getting_started/config/initializers/inflections.rb new file mode 100644 index 0000000000..9e8b0131f8 --- /dev/null +++ b/railties/guides/code/getting_started/config/initializers/inflections.rb @@ -0,0 +1,10 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format +# (all these examples are active by default): +# ActiveSupport::Inflector.inflections do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end diff --git a/railties/guides/code/getting_started/config/initializers/mime_types.rb b/railties/guides/code/getting_started/config/initializers/mime_types.rb new file mode 100644 index 0000000000..72aca7e441 --- /dev/null +++ b/railties/guides/code/getting_started/config/initializers/mime_types.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf +# Mime::Type.register_alias "text/html", :iphone diff --git a/railties/guides/code/getting_started/config/initializers/secret_token.rb b/railties/guides/code/getting_started/config/initializers/secret_token.rb new file mode 100644 index 0000000000..b0c8ee23c1 --- /dev/null +++ b/railties/guides/code/getting_started/config/initializers/secret_token.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key for verifying the integrity of signed cookies. +# 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. +Blog::Application.config.secret_token = '685a9bf865b728c6549a191c90851c1b5ec41ecb60b9e94ad79dd3f824749798aa7b5e94431901960bee57809db0947b481570f7f13376b7ca190fa28099c459' diff --git a/railties/guides/code/getting_started/config/initializers/session_store.rb b/railties/guides/code/getting_started/config/initializers/session_store.rb new file mode 100644 index 0000000000..1a67af58b5 --- /dev/null +++ b/railties/guides/code/getting_started/config/initializers/session_store.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +Blog::Application.config.session_store :cookie_store, key: '_blog_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") +# Blog::Application.config.session_store :active_record_store diff --git a/railties/guides/code/getting_started/config/initializers/wrap_parameters.rb b/railties/guides/code/getting_started/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000000..999df20181 --- /dev/null +++ b/railties/guides/code/getting_started/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/railties/guides/code/getting_started/config/locales/en.yml b/railties/guides/code/getting_started/config/locales/en.yml new file mode 100644 index 0000000000..179c14ca52 --- /dev/null +++ b/railties/guides/code/getting_started/config/locales/en.yml @@ -0,0 +1,5 @@ +# Sample localization file for English. Add more files in this directory for other locales. +# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. + +en: + hello: "Hello world" diff --git a/railties/guides/code/getting_started/config/routes.rb b/railties/guides/code/getting_started/config/routes.rb new file mode 100644 index 0000000000..31f0d210db --- /dev/null +++ b/railties/guides/code/getting_started/config/routes.rb @@ -0,0 +1,64 @@ +Blog::Application.routes.draw do + resources :posts do + resources :comments + end + + get "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 => "home#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/railties/guides/code/getting_started/config/routes.rb~ b/railties/guides/code/getting_started/config/routes.rb~ new file mode 100644 index 0000000000..3d9628b55e --- /dev/null +++ b/railties/guides/code/getting_started/config/routes.rb~ @@ -0,0 +1,60 @@ +Blog::Application.routes.draw do + get "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/railties/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb b/railties/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb new file mode 100644 index 0000000000..d45a961523 --- /dev/null +++ b/railties/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb @@ -0,0 +1,11 @@ +class CreatePosts < ActiveRecord::Migration + def change + create_table :posts do |t| + t.string :name + t.string :title + t.text :content + + t.timestamps + end + end +end diff --git a/railties/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb b/railties/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb new file mode 100644 index 0000000000..adda8078c1 --- /dev/null +++ b/railties/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb @@ -0,0 +1,12 @@ +class CreateComments < ActiveRecord::Migration + def change + create_table :comments do |t| + t.string :commenter + t.text :body + t.references :post + + t.timestamps + end + add_index :comments, :post_id + end +end diff --git a/railties/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb b/railties/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb new file mode 100644 index 0000000000..cf95b1c3d0 --- /dev/null +++ b/railties/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb @@ -0,0 +1,11 @@ +class CreateTags < ActiveRecord::Migration + def change + create_table :tags do |t| + t.string :name + t.references :post + + t.timestamps + end + add_index :tags, :post_id + end +end diff --git a/railties/guides/code/getting_started/db/schema.rb b/railties/guides/code/getting_started/db/schema.rb new file mode 100644 index 0000000000..9db4fbe4b6 --- /dev/null +++ b/railties/guides/code/getting_started/db/schema.rb @@ -0,0 +1,43 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended to check this file into your version control system. + +ActiveRecord::Schema.define(:version => 20110901013701) do + + create_table "comments", :force => true do |t| + t.string "commenter" + t.text "body" + t.integer "post_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "comments", ["post_id"], :name => "index_comments_on_post_id" + + create_table "posts", :force => true do |t| + t.string "name" + t.string "title" + t.text "content" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "tags", :force => true do |t| + t.string "name" + t.integer "post_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "tags", ["post_id"], :name => "index_tags_on_post_id" + +end diff --git a/railties/guides/code/getting_started/db/seeds.rb b/railties/guides/code/getting_started/db/seeds.rb new file mode 100644 index 0000000000..4edb1e857e --- /dev/null +++ b/railties/guides/code/getting_started/db/seeds.rb @@ -0,0 +1,7 @@ +# 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/railties/guides/code/getting_started/doc/README_FOR_APP b/railties/guides/code/getting_started/doc/README_FOR_APP new file mode 100644 index 0000000000..fe41f5cc24 --- /dev/null +++ b/railties/guides/code/getting_started/doc/README_FOR_APP @@ -0,0 +1,2 @@ +Use this README file to introduce your application and point to useful places in the API for learning more. +Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries. diff --git a/railties/guides/code/getting_started/lib/assets/.gitkeep b/railties/guides/code/getting_started/lib/assets/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/guides/code/getting_started/lib/tasks/.gitkeep b/railties/guides/code/getting_started/lib/tasks/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/guides/code/getting_started/public/404.html b/railties/guides/code/getting_started/public/404.html new file mode 100644 index 0000000000..9a48320a5f --- /dev/null +++ b/railties/guides/code/getting_started/public/404.html @@ -0,0 +1,26 @@ + + + + The page you were looking for doesn't exist (404) + + + + + +
    +

    The page you were looking for doesn't exist.

    +

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

    +
    + + diff --git a/railties/guides/code/getting_started/public/422.html b/railties/guides/code/getting_started/public/422.html new file mode 100644 index 0000000000..83660ab187 --- /dev/null +++ b/railties/guides/code/getting_started/public/422.html @@ -0,0 +1,26 @@ + + + + The change you wanted was rejected (422) + + + + + +
    +

    The change you wanted was rejected.

    +

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

    +
    + + diff --git a/railties/guides/code/getting_started/public/500.html b/railties/guides/code/getting_started/public/500.html new file mode 100644 index 0000000000..b80307fc16 --- /dev/null +++ b/railties/guides/code/getting_started/public/500.html @@ -0,0 +1,26 @@ + + + + We're sorry, but something went wrong (500) + + + + + +
    +

    We're sorry, but something went wrong.

    +

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

    +
    + + diff --git a/railties/guides/code/getting_started/public/favicon.ico b/railties/guides/code/getting_started/public/favicon.ico new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/guides/code/getting_started/public/robots.txt b/railties/guides/code/getting_started/public/robots.txt new file mode 100644 index 0000000000..085187fa58 --- /dev/null +++ b/railties/guides/code/getting_started/public/robots.txt @@ -0,0 +1,5 @@ +# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-Agent: * +# Disallow: / diff --git a/railties/guides/code/getting_started/script/rails b/railties/guides/code/getting_started/script/rails new file mode 100755 index 0000000000..f8da2cffd4 --- /dev/null +++ b/railties/guides/code/getting_started/script/rails @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby +# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. + +APP_PATH = File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/boot', __FILE__) +require 'rails/commands' diff --git a/railties/guides/code/getting_started/test/fixtures/.gitkeep b/railties/guides/code/getting_started/test/fixtures/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/guides/code/getting_started/test/fixtures/comments.yml b/railties/guides/code/getting_started/test/fixtures/comments.yml new file mode 100644 index 0000000000..d33da386bf --- /dev/null +++ b/railties/guides/code/getting_started/test/fixtures/comments.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html + +one: + commenter: MyString + body: MyText + post: + +two: + commenter: MyString + body: MyText + post: diff --git a/railties/guides/code/getting_started/test/fixtures/posts.yml b/railties/guides/code/getting_started/test/fixtures/posts.yml new file mode 100644 index 0000000000..8b0f75a33d --- /dev/null +++ b/railties/guides/code/getting_started/test/fixtures/posts.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html + +one: + name: MyString + title: MyString + content: MyText + +two: + name: MyString + title: MyString + content: MyText diff --git a/railties/guides/code/getting_started/test/fixtures/tags.yml b/railties/guides/code/getting_started/test/fixtures/tags.yml new file mode 100644 index 0000000000..8485668908 --- /dev/null +++ b/railties/guides/code/getting_started/test/fixtures/tags.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html + +one: + name: MyString + post: + +two: + name: MyString + post: diff --git a/railties/guides/code/getting_started/test/functional/.gitkeep b/railties/guides/code/getting_started/test/functional/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/guides/code/getting_started/test/functional/comments_controller_test.rb b/railties/guides/code/getting_started/test/functional/comments_controller_test.rb new file mode 100644 index 0000000000..2ec71b4ec5 --- /dev/null +++ b/railties/guides/code/getting_started/test/functional/comments_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CommentsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/railties/guides/code/getting_started/test/functional/home_controller_test.rb b/railties/guides/code/getting_started/test/functional/home_controller_test.rb new file mode 100644 index 0000000000..0d9bb47c3e --- /dev/null +++ b/railties/guides/code/getting_started/test/functional/home_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class HomeControllerTest < ActionController::TestCase + test "should get index" do + get :index + assert_response :success + end + +end diff --git a/railties/guides/code/getting_started/test/functional/posts_controller_test.rb b/railties/guides/code/getting_started/test/functional/posts_controller_test.rb new file mode 100644 index 0000000000..b8f7b07820 --- /dev/null +++ b/railties/guides/code/getting_started/test/functional/posts_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class PostsControllerTest < ActionController::TestCase + setup do + @post = posts(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:posts) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create post" do + assert_difference('Post.count') do + post :create, post: @post.attributes + end + + assert_redirected_to post_path(assigns(:post)) + end + + test "should show post" do + get :show, id: @post.to_param + assert_response :success + end + + test "should get edit" do + get :edit, id: @post.to_param + assert_response :success + end + + test "should update post" do + put :update, id: @post.to_param, post: @post.attributes + assert_redirected_to post_path(assigns(:post)) + end + + test "should destroy post" do + assert_difference('Post.count', -1) do + delete :destroy, id: @post.to_param + end + + assert_redirected_to posts_path + end +end diff --git a/railties/guides/code/getting_started/test/integration/.gitkeep b/railties/guides/code/getting_started/test/integration/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/guides/code/getting_started/test/performance/browsing_test.rb b/railties/guides/code/getting_started/test/performance/browsing_test.rb new file mode 100644 index 0000000000..3fea27b916 --- /dev/null +++ b/railties/guides/code/getting_started/test/performance/browsing_test.rb @@ -0,0 +1,12 @@ +require 'test_helper' +require 'rails/performance_test_help' + +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 +end diff --git a/railties/guides/code/getting_started/test/test_helper.rb b/railties/guides/code/getting_started/test/test_helper.rb new file mode 100644 index 0000000000..8bf1192ffe --- /dev/null +++ b/railties/guides/code/getting_started/test/test_helper.rb @@ -0,0 +1,13 @@ +ENV["RAILS_ENV"] = "test" +require File.expand_path('../../config/environment', __FILE__) +require 'rails/test_help' + +class ActiveSupport::TestCase + # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. + # + # Note: You'll currently still have to declare fixtures explicitly in integration tests + # -- they do not yet inherit this setting + fixtures :all + + # Add more helper methods to be used by all tests here... +end diff --git a/railties/guides/code/getting_started/test/unit/.gitkeep b/railties/guides/code/getting_started/test/unit/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/guides/code/getting_started/test/unit/comment_test.rb b/railties/guides/code/getting_started/test/unit/comment_test.rb new file mode 100644 index 0000000000..b6d6131a96 --- /dev/null +++ b/railties/guides/code/getting_started/test/unit/comment_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CommentTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/railties/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb b/railties/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb new file mode 100644 index 0000000000..2518c16bd5 --- /dev/null +++ b/railties/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class CommentsHelperTest < ActionView::TestCase +end diff --git a/railties/guides/code/getting_started/test/unit/helpers/home_helper_test.rb b/railties/guides/code/getting_started/test/unit/helpers/home_helper_test.rb new file mode 100644 index 0000000000..4740a18dac --- /dev/null +++ b/railties/guides/code/getting_started/test/unit/helpers/home_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class HomeHelperTest < ActionView::TestCase +end diff --git a/railties/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb b/railties/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb new file mode 100644 index 0000000000..48549c2ea1 --- /dev/null +++ b/railties/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class PostsHelperTest < ActionView::TestCase +end diff --git a/railties/guides/code/getting_started/test/unit/post_test.rb b/railties/guides/code/getting_started/test/unit/post_test.rb new file mode 100644 index 0000000000..6d9d463a71 --- /dev/null +++ b/railties/guides/code/getting_started/test/unit/post_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/railties/guides/code/getting_started/test/unit/tag_test.rb b/railties/guides/code/getting_started/test/unit/tag_test.rb new file mode 100644 index 0000000000..b8498a117c --- /dev/null +++ b/railties/guides/code/getting_started/test/unit/tag_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class TagTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/railties/guides/code/getting_started/vendor/assets/stylesheets/.gitkeep b/railties/guides/code/getting_started/vendor/assets/stylesheets/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/guides/code/getting_started/vendor/plugins/.gitkeep b/railties/guides/code/getting_started/vendor/plugins/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 1587b20c18..e1bc56823a 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -41,6 +41,9 @@ internet for learning Ruby, including: * "Programming Ruby":http://www.ruby-doc.org/docs/ProgrammingRuby/ * "Why's (Poignant) Guide to Ruby":http://mislav.uniqpath.com/poignant-guide/ +Also, the example code for this guide is available in the rails github:https://github.com/rails/rails repository +in rails/railties/guides/code/getting_started. + h3. What is Rails? Rails is a web application development framework written in the Ruby language. -- cgit v1.2.3 From 11fa70dd0903a75f2a507dd609ea640e8ec99373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Sep 2011 09:05:11 -0700 Subject: Just provide the executable for railtie. This should be fine since Rubygems now warns before overriding them. --- railties/bin/rails | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/bin/rails b/railties/bin/rails index a7d6938e0d..a1c4faaa73 100755 --- a/railties/bin/rails +++ b/railties/bin/rails @@ -1,2 +1,7 @@ #!/usr/bin/env ruby -require "rails/cli" \ No newline at end of file + +if File.exists?(File.join(File.expand_path('../../..', __FILE__), '.git')) + railties_path = File.expand_path('../../lib', __FILE__) + $:.unshift(railties_path) +end +require "rails/cli" -- cgit v1.2.3 From 3ce830272ee0516eb864a5765abba25d4b07cca4 Mon Sep 17 00:00:00 2001 From: kennyj Date: Tue, 13 Sep 2011 01:06:31 +0900 Subject: fix https://github.com/rails/rails/issues/2582 (with testcase) --- railties/test/application/rake_test.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 0e03c3dc2d..9b1b24fca1 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -1,3 +1,4 @@ +# coding:utf-8 require "isolation/abstract_unit" module ApplicationTests @@ -244,5 +245,20 @@ module ApplicationTests assert_match(/7 tests, 10 assertions, 0 failures, 0 errors/, content) end + + def test_assets_precompile_with_utf8_filename + add_to_config <<-RUBY + config.assets.precompile = [ /\.png$$/, /application.(css|js)$/ ] + RUBY + + Dir.chdir(app_path) do + `cp app/assets/images/rails.png app/assets/images/レイルズ.png` + `rake assets:precompile` + open("public/assets/manifest.yml") do |f| + assert_match(/レイルズ.png/, f.read) + end + end + end + end -end \ No newline at end of file +end -- cgit v1.2.3 From 70198fdb3614ef0299e848440df62d18b46a7f77 Mon Sep 17 00:00:00 2001 From: dharmatech Date: Mon, 12 Sep 2011 12:05:15 -0500 Subject: getting_started.textile: Fix typos in section "Rendering a Partial Form" --- railties/guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 1587b20c18..ae9a689678 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1453,7 +1453,7 @@ comment to a local variable named the same as the partial, in this case h4. Rendering a Partial Form -Lets also move that new comment section out to it's own partial, again, you +Let's also move that new comment section out to its own partial. Again, you create a file +app/views/comments/_form.html.erb+ and in it you put: -- cgit v1.2.3 From e9db21743b15f2c6e8dcbd18f420784c4e8de88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Sep 2011 10:53:20 -0700 Subject: Use the proper executable on tests. --- railties/test/isolation/abstract_unit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 685d1b154b..4a6bdb0320 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -282,7 +282,7 @@ Module.new do require_environment = "-r #{environment}" end - `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/bin/rails new #{tmp_path('app_template')}` + `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails new #{tmp_path('app_template')}` File.open("#{tmp_path}/app_template/config/boot.rb", 'w') do |f| if require_environment f.puts "Dir.chdir('#{File.dirname(environment)}') do" -- cgit v1.2.3 From c5118f29dee30d6c806c486698f3aa6ba8af919b Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 12 Sep 2011 23:24:14 +0530 Subject: change GH issue tracker url --- railties/guides/source/contributing_to_ruby_on_rails.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index 968fa7a1f1..90eab150a1 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -261,7 +261,7 @@ You can help improve the Rails guides by making them more coherent, adding missi If you're confident about your changes, you can push them yourself directly via "docrails":https://github.com/lifo/docrails. docrails is a branch with an *open commit policy* and public write access. Commits to docrails are still reviewed, but that happens after they are pushed. docrails is merged with master regularly, so you are effectively editing the Ruby on Rails documentation. -If you are unsure of the documentation changes, you can create an issue in the "Rails":https://github.com/rails/rails repository on GitHub. +If you are unsure of the documentation changes, you can create an issue in the "Rails":https://github.com/rails/rails/issues issues tracker on GitHub. When working with documentation, please take into account the "API Documentation Guidelines":api_documentation_guidelines.html and the "Ruby on Rails Guides Guidelines":ruby_on_rails_guides_guidelines.html. -- cgit v1.2.3 From acc6252cb0250df8d5554fee94b0aa6dc87b32e7 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 12 Sep 2011 23:25:33 +0530 Subject: Delete contribute.textile now that its contents are merged to the contributing_to_ruby_on_rails guide --- railties/guides/source/contribute.textile | 70 ------------------------------- 1 file changed, 70 deletions(-) delete mode 100644 railties/guides/source/contribute.textile (limited to 'railties') diff --git a/railties/guides/source/contribute.textile b/railties/guides/source/contribute.textile deleted file mode 100644 index f9bb80861c..0000000000 --- a/railties/guides/source/contribute.textile +++ /dev/null @@ -1,70 +0,0 @@ -h2. Contribute to the Rails Guides - -Rails Guides aim to improve the Rails documentation and to make the barrier to entry as low as possible. A reasonably experienced developer should be able to use the guides to come up to speed on Rails quickly. Our sponsors have contributed prizes for those who write an entire guide, but there are many other ways to contribute. - -endprologue. - -h3. How to Contribute? - -* We have an open commit policy: anyone is welcome to contribute and to review contributions. -* "docrails is hosted on GitHub":https://github.com/lifo/docrails and has public write access. -* Guides are written in Textile, and reside at +railties/guides/source+ in the docrails project. -* Follow the "Rails Guides Conventions":https://wiki.github.com/lifo/docrails/rails-guides-conventions. -* Assets are stored in the +railties/guides/assets+ directory. -* Sample format : "Active Record Associations":https://github.com/lifo/docrails/blob/3e56a3832415476fdd1cb963980d0ae390ac1ed3/railties/guides/source/association_basics.textile. -* Sample output : "Active Record Associations":association_basics.html. -* You can build the Guides during testing by running +bundle exec rake generate_guides+ in the +railties+ directory. -* You're encouraged to validate XHTML for the generated guides before committing your changes by running +bundle exec rake validate_guides+ in the +railties+ directory. -* Edge guides "can be consulted online":http://edgeguides.rubyonrails.org/. That website is generated periodically from docrails. - -h3. What to Contribute? - -* We need authors, editors, proofreaders, and translators. Adding a single paragraph of quality content to a guide is a good way to get started. -* The easiest way to start is by improving an existing guide: -** Improve the structure to make it more coherent. -** Add missing information. -** Correct any factual errors. -** Fix typos or improve style. -** Bring it up to date with the latest Edge Rails. -* We're also open to suggestions for entire new guides: -** Contact lifo or fxn to get your idea approved. See the Contact section below. -** If you're the main author on a significant guide, you're eligible for the prizes. - -h3. How is the process? - -* The preferred way to contribute is to commit to docrails directly. -* A new guide is only edited by its author until finished though. -* If you are writing a new guide freely commit to docrails partial work and ping lifo or fxn when done with a first draft. -* Guides reviewers will then provide feedback, some of it possibly in form of direct commits to agilize the process. -* Eventually the guide will be approved and added to the index. - -h3. Prizes - -For each completed guide, the lead contributor will receive all of the following prizes: - -* $200 from Caboose Rails Documentation Project. -* 1 year of GitHub Micro account worth $84. -* 1 year of RPM Basic (Production performance management) for up to 10 hosts worth 12 months x $40 per host x 10 hosts = $4800. And also, savings of $45 per host per month over list price to upgrade to advanced product. - -h3. Rules - -* Guides are licensed under a Creative Commons Attribution-Share Alike 3.0 License. -* If you're not sure whether a guide is actively being worked on, stop by IRC and ask. -* If the same guide writer wants to write multiple guides, that's ideally the situation we'd love to be in! However, that guide writer will only receive the cash prize for all the subsequent guides (and not the GitHub or RPM prizes). -* Our review team will have the final say on whether the guide is complete and of good enough quality. - -All authors should read and follow the "Rails Guides Conventions":ruby_on_rails_guides_guidelines.html and the "Rails API Documentation Conventions":api_documentation_guidelines.html. - -h3. Translations - -The translation effort for the Rails Guides is just getting underway. We know about projects to translate the Guides into Spanish, Portuguese, Polish, and French. For more details or to get involved see the "Translating Rails Guides":https://wiki.github.com/lifo/docrails/translating-rails-guides page. - -h3. Mailing List - -"Ruby on Rails: Documentation":http://groups.google.com/group/rubyonrails-docs is the mailing list for all the guides/documentation related discussions. - -h3. Contact - -* IRC : #docrails channel in irc.freenode.net -* Twitter: "@docrails":http://twitter.com/docrails, "@lifo":http://twitter.com/lifo, "@fxn":http://twitter.com/fxn -* Email : pratiknaik aT gmail, fxn aT hashref dot com -- cgit v1.2.3 From 21eaba4c39773af3e7b279325fb8d6b5ab474ef0 Mon Sep 17 00:00:00 2001 From: kennyj Date: Tue, 13 Sep 2011 02:59:57 +0900 Subject: fix https://github.com/rails/rails/issues/2947 (with testcase) --- railties/test/application/rake_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'railties') diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 9b1b24fca1..721a8c978f 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -260,5 +260,21 @@ module ApplicationTests end end + def test_assets_precompile_ignore_asset_host + add_to_config <<-RUBY + config.action_controller.asset_host = Proc.new { |source, request| "http://www.example.com/" } + RUBY + + app_file "app/assets/javascripts/test.js.erb", <<-RUBY + alert("<%= asset_path "rails.png" %>"); + RUBY + + Dir.chdir(app_path) do + `rake assets:precompile` + open("public/assets/application.js") do |f| + assert_match(/\"\/assets\/rails.png\"/, f.read) + end + end + end end end -- cgit v1.2.3 From 7d235b972b29659d94e2b290be6e0ad3bc6a2668 Mon Sep 17 00:00:00 2001 From: dharmatech Date: Mon, 12 Sep 2011 15:55:01 -0500 Subject: getting_started.textile: Fix typo and split up a sentence in section "Building a Multi-Model Form" --- railties/guides/source/getting_started.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 37aabcda83..b8dd4be73b 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1719,8 +1719,8 @@ This example shows another option of the render helper, being able to pass in local variables, in this case, we want the local variable +form+ in the partial to refer to the +post_form+ object. -We also add a @post.tags.build at the top of this form, this is to make -sure there is a new tag ready to have it's name filled in by the user. If you do +We also add a @post.tags.build at the top of this form. This is to make +sure there is a new tag ready to have its name filled in by the user. If you do not build the new tag, then the form will not appear as there is no new Tag object ready to create. -- cgit v1.2.3 From d21e0e2af3d9b21399244c3f3f73378d75cd4697 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 11 Sep 2011 17:14:42 -0700 Subject: adjust route inspection to work with Journey --- railties/lib/rails/application/route_inspector.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb index 15c6d035e5..8c6911e6bb 100644 --- a/railties/lib/rails/application/route_inspector.rb +++ b/railties/lib/rails/application/route_inspector.rb @@ -23,7 +23,8 @@ module Rails reqs = reqs.empty? ? constraints.inspect : "#{reqs} #{constraints.inspect}" end - {:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path, :reqs => reqs} + verb = route.verb.source.gsub(/[$^]/, '') + {:name => route.name.to_s, :verb => verb, :path => route.path.spec.to_s, :reqs => reqs} end # Skip the route if it's internal info route -- cgit v1.2.3 From 68ec26c70c38c388822a7acd8682ac97d0d43b5e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 12 Sep 2011 16:49:36 -0700 Subject: point rails at Journey for dev and edge --- railties/lib/rails/generators/app_base.rb | 2 ++ railties/lib/rails/generators/rails/app/app_generator.rb | 1 + 2 files changed, 3 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 93f5023a7a..294563ad06 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -138,10 +138,12 @@ module Rails if options.dev? <<-GEMFILE.strip_heredoc gem 'rails', :path => '#{Rails::Generators::RAILS_DEV_PATH}' + gem 'journey', :path => '#{Rails::Generators::JOURNEY_DEV_PATH}' GEMFILE elsif options.edge? <<-GEMFILE.strip_heredoc gem 'rails', :git => 'git://github.com/rails/rails.git' + gem 'journey', :git => 'git://github.com/rails/journey.git' GEMFILE else <<-GEMFILE.strip_heredoc diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index d9dd33518a..9cbda6649d 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -139,6 +139,7 @@ module Rails # We need to store the RAILS_DEV_PATH in a constant, otherwise the path # can change in Ruby 1.8.7 when we FileUtils.cd. RAILS_DEV_PATH = File.expand_path("../../../../../..", File.dirname(__FILE__)) + JOURNEY_DEV_PATH = File.expand_path("../../../../../../../journey", File.dirname(__FILE__)) RESERVED_NAMES = %w[application destroy benchmarker profiler plugin runner test] -- cgit v1.2.3 From 73e8dd189be11aa1440af7add3f044b12fb26565 Mon Sep 17 00:00:00 2001 From: Deepak Prasanna Date: Tue, 13 Sep 2011 11:59:40 +0530 Subject: fixed the failing generators_test --- railties/test/railties/generators_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/railties/generators_test.rb b/railties/test/railties/generators_test.rb index 1d4ba0e5b6..f8540d69d9 100644 --- a/railties/test/railties/generators_test.rb +++ b/railties/test/railties/generators_test.rb @@ -28,7 +28,7 @@ module RailtiesTests if File.exist?("#{environment}.rb") require_environment = "-r #{environment}" end - `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/bin/rails #{cmd}` + `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{cmd}` end def build_engine(is_mountable=false) -- cgit v1.2.3 From e767cda6ea171cf888c8e46b0c62e3c7df801a38 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Tue, 13 Sep 2011 03:19:02 -0500 Subject: Move asset tests to assets_test file --- railties/test/application/assets_test.rb | 31 +++++++++++++++++++++++++++++++ railties/test/application/rake_test.rb | 31 ------------------------------- 2 files changed, 31 insertions(+), 31 deletions(-) (limited to 'railties') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index b8a8665b3e..95fcb4a3dd 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- require 'isolation/abstract_unit' require 'active_support/core_ext/kernel/reporting' require 'rack/test' @@ -268,6 +269,36 @@ module ApplicationTests assert_match(/\/assets\/rails-([0-z]+)\.png/, File.read(file)) end + test "precompile ignore asset_host" do + app_file "app/assets/javascripts/application.css.erb", "<%= asset_path 'rails.png' %>" + add_to_config "config.action_controller.asset_host = Proc.new { |source, request| 'http://www.example.com/' }" + + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + + file = Dir["#{app_path}/public/assets/application.css"].first + content = File.read(file) + assert_match(/\/assets\/rails-([0-z]+)\.png/, content) + assert_no_match(/www\.example\.com/, content) + end + + test "precompile should handle utf8 filenames" do + app_file "app/assets/images/レイルズ.png", "not a image really" + add_to_config "config.assets.precompile = [ /\.png$$/, /application.(css|js)$/ ]" + + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + + assert File.exists?("#{app_path}/public/assets/レイルズ.png") + + manifest = "#{app_path}/public/assets/manifest.yml" + + assets = YAML.load_file(manifest) + assert_equal "レイルズ.png", assets["レイルズ.png"] + end + test "assets are cleaned up properly" do app_file "public/assets/application.js", "alert();" app_file "public/assets/application.css", "a { color: green; }" diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 80fd65cd9f..c76bc3d526 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -201,36 +201,5 @@ module ApplicationTests assert_match(/7 tests, 10 assertions, 0 failures, 0 errors/, content) end - - def test_assets_precompile_with_utf8_filename - add_to_config <<-RUBY - config.assets.precompile = [ /\.png$$/, /application.(css|js)$/ ] - RUBY - - Dir.chdir(app_path) do - `cp app/assets/images/rails.png app/assets/images/レイルズ.png` - `rake assets:precompile` - open("public/assets/manifest.yml") do |f| - assert_match(/レイルズ.png/, f.read) - end - end - end - - def test_assets_precompile_ignore_asset_host - add_to_config <<-RUBY - config.action_controller.asset_host = Proc.new { |source, request| "http://www.example.com/" } - RUBY - - app_file "app/assets/javascripts/test.js.erb", <<-RUBY - alert("<%= asset_path "rails.png" %>"); - RUBY - - Dir.chdir(app_path) do - `rake assets:precompile` - open("public/assets/application.js") do |f| - assert_match(/\"\/assets\/rails.png\"/, f.read) - end - end - end end end -- cgit v1.2.3 From a65010fddb00ceb9356f8ccb797405a86a1d8b9f Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Tue, 13 Sep 2011 04:35:12 -0500 Subject: Fix precompile asset_host test --- railties/test/application/assets_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 95fcb4a3dd..0901c6df3d 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -279,7 +279,7 @@ module ApplicationTests file = Dir["#{app_path}/public/assets/application.css"].first content = File.read(file) - assert_match(/\/assets\/rails-([0-z]+)\.png/, content) + assert_match(/\/assets\/rails.png/, content) assert_no_match(/www\.example\.com/, content) end -- cgit v1.2.3 From 317ad8cb62d10f77cf0692f0a123b4a3358629a5 Mon Sep 17 00:00:00 2001 From: Mike Gunderloy Date: Tue, 13 Sep 2011 06:47:13 -0500 Subject: Fix typo --- railties/guides/source/rails_on_rack.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile index 818df0ffaf..735438b155 100644 --- a/railties/guides/source/rails_on_rack.textile +++ b/railties/guides/source/rails_on_rack.textile @@ -216,7 +216,7 @@ config.middleware.clear # config.ru -use MyOwnStackFromStratch +use MyOwnStackFromScratch run ActionController::Dispatcher.new -- cgit v1.2.3 From 7b22b0193002de14a4915f064acb4a7715c24059 Mon Sep 17 00:00:00 2001 From: 45north Date: Tue, 13 Sep 2011 15:25:46 +0300 Subject: Fixed markup error. --- railties/guides/source/initialization.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 9cc4dd5f04..8aabc3ae91 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -454,7 +454,7 @@ app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app", TOPLEVEL_BINDING, config -The initialize method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run: +The +initialize+ method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run: require ::File.expand_path('../config/environment', __FILE__) -- cgit v1.2.3 From d3baa928312a13ddd550a527caa554a49267ce88 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 13 Sep 2011 18:46:34 +0530 Subject: delete stray backup files from guides sample app --- .../getting_started/app/views/home/index.html.erb~ | 2 - .../guides/code/getting_started/config/routes.rb~ | 60 ---------------------- 2 files changed, 62 deletions(-) delete mode 100644 railties/guides/code/getting_started/app/views/home/index.html.erb~ delete mode 100644 railties/guides/code/getting_started/config/routes.rb~ (limited to 'railties') diff --git a/railties/guides/code/getting_started/app/views/home/index.html.erb~ b/railties/guides/code/getting_started/app/views/home/index.html.erb~ deleted file mode 100644 index 2085730c72..0000000000 --- a/railties/guides/code/getting_started/app/views/home/index.html.erb~ +++ /dev/null @@ -1,2 +0,0 @@ -

    Home#index

    -

    Find me in app/views/home/index.html.erb

    diff --git a/railties/guides/code/getting_started/config/routes.rb~ b/railties/guides/code/getting_started/config/routes.rb~ deleted file mode 100644 index 3d9628b55e..0000000000 --- a/railties/guides/code/getting_started/config/routes.rb~ +++ /dev/null @@ -1,60 +0,0 @@ -Blog::Application.routes.draw do - get "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 -- cgit v1.2.3 From bde113a82e792ef3480d686a1e66fea56c76c46d Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Wed, 14 Sep 2011 00:09:59 +0200 Subject: Fix typos and broken link on asset pipeline guide --- railties/guides/source/asset_pipeline.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 211b02b94b..31a1aeee15 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -63,7 +63,7 @@ This has several disadvantages:
    1. Not all caches will cache content with a query string
      - "Steve Souders recommends":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/, "...avoiding a querystring for cacheable resources". He found that in these case 5-20% of requests will not be cached. + "Steve Souders recommends":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/, "...avoiding a querystring for cacheable resources". He found that in this case 5-20% of requests will not be cached.
    2. The file name can change between nodes in multi-server environments.
      @@ -132,7 +132,7 @@ In regular views you can access images in the +assets/images+ directory like thi Provided that the pipeline is enabled within your application (and not disabled in the current environment context), this file is served by Sprockets. If a file exists at +public/assets/rails.png+ it is served by the webserver. -Alternatively, a request for a file with an MD5 hash such as +public/assets/rails-af27b6a414e6da00003503148be9b409.png+ is treated the same way. How these hashes are generated is covered in the "Production Assets":#production_assets section later on in this guide. +Alternatively, a request for a file with an MD5 hash such as +public/assets/rails-af27b6a414e6da00003503148be9b409.png+ is treated the same way. How these hashes are generated is covered in the "In Production":#in-production section later on in this guide. Sprockets will also look through the paths specified in +config.assets.paths+ which includes the standard application paths and any path added by Rails engines. @@ -537,7 +537,7 @@ WARNING: If you are upgrading an existing application and intend to use this opt h3. How Caching Works -Sprockets uses the default rails cache store to cache assets in development and production. +Sprockets uses the default Rails cache store to cache assets in development and production. TODO: Add more about changing the default store. -- cgit v1.2.3 From 82afaa06861d03f6a2887d40e40c0ded76db88db Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 13 Sep 2011 15:16:53 -0700 Subject: Provide a way to access to assets without using the digest, useful for static files and emails --- railties/CHANGELOG | 3 +++ railties/test/application/assets_test.rb | 2 ++ 2 files changed, 5 insertions(+) (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 6ed76974b4..9ba93d6130 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -12,6 +12,9 @@ *Rails 3.1.0 (unreleased)* +* Provide a way to access to assets without using the digest, useful for +static files and emails. [Santiago Pastorino] + * The default database schema file is written as UTF-8. [Aaron Patterson] * Generated apps with --dev or --edge flags depend on git versions of diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 0901c6df3d..9245532e17 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -58,7 +58,9 @@ module ApplicationTests Dir.chdir(app_path){ `bundle exec rake assets:precompile` } end files = Dir["#{app_path}/public/assets/application-*.js"] + files << Dir["#{app_path}/public/assets/application.js"].first files << Dir["#{app_path}/public/assets/foo/application-*.js"].first + files << Dir["#{app_path}/public/assets/foo/application.js"].first files.each do |file| assert_not_nil file, "Expected application.js asset to be generated, but none found" assert_equal "alert()", File.read(file) -- cgit v1.2.3 From f22407dd34024886edd8a8f618dc0b19152776a0 Mon Sep 17 00:00:00 2001 From: "Mark J. Titorenko" Date: Tue, 6 Sep 2011 10:34:24 +0100 Subject: Don't mount Sprockets at config.assets.prefix if config.assets.compile is false. --- railties/test/application/assets_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'railties') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 9245532e17..0c40b88cf9 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -178,6 +178,7 @@ module ApplicationTests test "assets do not require any assets group gem when manifest file is present" do app_file "app/assets/javascripts/application.js", "alert();" + app_file "config/initializers/serve_static_assets.rb", "Rails.application.config.serve_static_assets = true" ENV["RAILS_ENV"] = "production" capture(:stdout) do @@ -314,6 +315,17 @@ module ApplicationTests assert_equal 0, files.length, "Expected no assets, but found #{files.join(', ')}" end + test "assets routes are not drawn when compilation is disabled" do + app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();" + app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = false" + + ENV["RAILS_ENV"] = "production" + require "#{app_path}/config/environment" + + get "/assets/demo.js" + assert_equal 404, last_response.status + end + test "does not stream session cookies back" do app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();" -- cgit v1.2.3 From a89d39ec889c2658120e508bd182de7be3ccdcc9 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Tue, 13 Sep 2011 18:36:38 -0500 Subject: Fix broken asset test --- railties/test/application/assets_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 0c40b88cf9..9b141ccbac 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -38,7 +38,7 @@ module ApplicationTests test "assets do not require compressors until it is used" do app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();" - add_to_config "config.assets.compile = true" + app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = true" ENV["RAILS_ENV"] = "production" require "#{app_path}/config/environment" @@ -317,7 +317,7 @@ module ApplicationTests test "assets routes are not drawn when compilation is disabled" do app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();" - app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = false" + add_to_config "config.assets.compile = false" ENV["RAILS_ENV"] = "production" require "#{app_path}/config/environment" -- cgit v1.2.3 From b3ff720567b41ca5db9e6956c37cc0792b7a3f4e Mon Sep 17 00:00:00 2001 From: Ben Walding Date: Wed, 14 Sep 2011 15:27:38 +1000 Subject: Add equivalent nginx configuration --- railties/guides/source/asset_pipeline.textile | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 31a1aeee15..ce4eafb97c 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -403,7 +403,21 @@ For Apache: -TODO: nginx instructions +For nginx: + + +location ~ ^/assets/ { + expires 1y; + add_header Cache-Control public; + + # Some browsers still send conditional-GET requests if there's a + # Last-Modified header or an ETag header even if they haven't + # reached the expiry date sent in the Expires header. + add_header Last-Modified ""; + add_header ETag ""; + break; +} + When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disk. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the +public/assets+ folder. The following configuration options can be used: -- cgit v1.2.3 From 0d48b3afa98375cf71ea0ad731eaac6c309fbb57 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 14 Sep 2011 00:29:03 -0700 Subject: Revert "Provide a way to access to assets without using the digest, useful for static files and emails" This reverts commit 82afaa06861d03f6a2887d40e40c0ded76db88db. --- railties/CHANGELOG | 3 --- railties/test/application/assets_test.rb | 2 -- 2 files changed, 5 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 9ba93d6130..6ed76974b4 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -12,9 +12,6 @@ *Rails 3.1.0 (unreleased)* -* Provide a way to access to assets without using the digest, useful for -static files and emails. [Santiago Pastorino] - * The default database schema file is written as UTF-8. [Aaron Patterson] * Generated apps with --dev or --edge flags depend on git versions of diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 9b141ccbac..959914bcea 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -58,9 +58,7 @@ module ApplicationTests Dir.chdir(app_path){ `bundle exec rake assets:precompile` } end files = Dir["#{app_path}/public/assets/application-*.js"] - files << Dir["#{app_path}/public/assets/application.js"].first files << Dir["#{app_path}/public/assets/foo/application-*.js"].first - files << Dir["#{app_path}/public/assets/foo/application.js"].first files.each do |file| assert_not_nil file, "Expected application.js asset to be generated, but none found" assert_equal "alert()", File.read(file) -- cgit v1.2.3 From 7302e1cdf22951db1a4cbad45bf116db1be0eebb Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 14 Sep 2011 19:02:08 +0530 Subject: remove info about guides hackfest --- railties/guides/source/index.html.erb | 1 - 1 file changed, 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb index 214155c088..c9a8c4fa5c 100644 --- a/railties/guides/source/index.html.erb +++ b/railties/guides/source/index.html.erb @@ -30,7 +30,6 @@ Ruby on Rails Guides <% content_for :index_section do %>
      -
      Rails Guides are a result of the ongoing Guides hackfest, and a work in progress.
      Guides marked with this icon are currently being worked on. While they might still be useful to you, they may contain incomplete information and even errors. You can help by reviewing them and posting your comments and corrections to the author.
      -- cgit v1.2.3 From c7835c51618a6a46d1b5ec63dfaf2d99e157da42 Mon Sep 17 00:00:00 2001 From: Dallas Reedy Date: Tue, 13 Sep 2011 16:32:43 -0700 Subject: Removed mention of deprecated proxy methods in favor of using proxy_association. --- railties/guides/source/association_basics.textile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile index ce4ff0389d..0439b6ac4d 100644 --- a/railties/guides/source/association_basics.textile +++ b/railties/guides/source/association_basics.textile @@ -1855,14 +1855,15 @@ class Customer < ActiveRecord::Base end -Extensions can refer to the internals of the association proxy using these three accessors: +Extensions can refer to the internals of the association proxy using these three attributes of the +proxy_association+ accessor: -* +proxy_owner+ returns the object that the association is a part of. -* +proxy_reflection+ returns the reflection object that describes the association. -* +proxy_target+ returns the associated object for +belongs_to+ or +has_one+, or the collection of associated objects for +has_many+ or +has_and_belongs_to_many+. +* +proxy_association.owner+ returns the object that the association is a part of. +* +proxy_association.reflection+ returns the reflection object that describes the association. +* +proxy_association.target+ returns the associated object for +belongs_to+ or +has_one+, or the collection of associated objects for +has_many+ or +has_and_belongs_to_many+. h3. Changelog +* September 13, 2011: Removed mention of deprecated proxy methods in favor of using +proxy_association+. * April 7, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com * April 19, 2009: Added +:touch+ option to +belongs_to+ associations by "Mike Gunderloy":credits.html#mgunderloy * February 1, 2009: Added +:autosave+ option "Mike Gunderloy":credits.html#mgunderloy -- cgit v1.2.3 From bc058509a884e81b9099072073e372e1ad9b932b Mon Sep 17 00:00:00 2001 From: Dallas Reedy Date: Wed, 14 Sep 2011 09:32:27 -0700 Subject: forgot to sign my name to the Changelog --- railties/guides/source/association_basics.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile index 0439b6ac4d..479693dbf8 100644 --- a/railties/guides/source/association_basics.textile +++ b/railties/guides/source/association_basics.textile @@ -1863,7 +1863,7 @@ Extensions can refer to the internals of the association proxy using these three h3. Changelog -* September 13, 2011: Removed mention of deprecated proxy methods in favor of using +proxy_association+. +* September 13, 2011: Removed mention of deprecated proxy methods in favor of using +proxy_association+. "Dallas Reedy":https://github.com/dallas * April 7, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com * April 19, 2009: Added +:touch+ option to +belongs_to+ associations by "Mike Gunderloy":credits.html#mgunderloy * February 1, 2009: Added +:autosave+ option "Mike Gunderloy":credits.html#mgunderloy -- cgit v1.2.3 From 823e16f57cb64c8557aa8e06b07e361d625a6e2e Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 14 Sep 2011 22:46:12 +0530 Subject: update 3.1 release date in changelogs --- railties/CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 6ed76974b4..72e5921d6d 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -10,7 +10,7 @@ * Removed old 'config.paths.app.controller' API in favor of 'config.paths["app/controller"]' API. [Guillermo Iguaran] -*Rails 3.1.0 (unreleased)* +*Rails 3.1.0 (August 30, 2011)* * The default database schema file is written as UTF-8. [Aaron Patterson] -- cgit v1.2.3 From 5e1285dfb3148f89ae644bdf4522115ae4c8144f Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 14 Sep 2011 23:05:29 +0530 Subject: change first_or_new to first_or_initialize as per 11870117, and some edits --- .../guides/source/active_record_querying.textile | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 7a853db813..ac8c15f60d 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -1042,20 +1042,26 @@ INSERT INTO clients (created_at, first_name, locked, orders_count, updated_at) V COMMIT -+first_or_create+ returns either the record that already existed or the new record. In our case, we didn't already have a client named Andy so the record was created an returned. ++first_or_create+ returns either the record that already exists or the new record. In our case, we didn't already have a client named Andy so the record is created and returned. The new record might not be saved to the database; that depends on whether validations passed or not (just like +create+). It's also worth noting that +first_or_create+ takes into account the arguments of the +where+ method. In the example above we didn't explicitly pass a +:first_name => 'Andy'+ argument to +first_or_create+. However, that was used when creating the new record because it was already passed before to the +where+ method. -NOTE: On previous versions of Rails you could do a similar thing with the +find_or_create_by+ method. Following our example, you could also run something like +Client.find_or_create_by_first_name(:first_name => "Andy", :locked => false)+. This method still works, but it's encouraged to use +first_or_create+ because it's more explicit on what arguments are used to _find_ the record and what arguments are used to _create_ it, resulting in less confusion overall. +You can do the same with the +find_or_create_by+ method: + + +Client.find_or_create_by_first_name(:first_name => "Andy", :locked => false) + + +This method still works, but it's encouraged to use +first_or_create+ because it's more explicit on which arguments are used to _find_ the record and which are used to _create_, resulting in less confusion overall. h4. +first_or_create!+ You can also use +first_or_create!+ to raise an exception if the new record is invalid. Validations are not covered on this guide, but let's assume for a moment that you temporarily add - validates :orders_count, :presence => true +validates :orders_count, :presence => true to your +Client+ model. If you try to create a new +Client+ without passing an +orders_count+, the record will be invalid and an exception will be raised: @@ -1065,14 +1071,12 @@ Client.where(:first_name => 'Andy').first_or_create!(:locked => false) # => ActiveRecord::RecordInvalid: Validation failed: Orders count can't be blank -NOTE: Be sure to check the extensive *Active Record Validations and Callbacks Guide* for more information about validations. - -h4. +first_or_new+ +h4. +first_or_initialize+ -The +first_or_new+ method will work just like +first_or_create+ but it will not call +create+ but +new+. This means that a new model instance will be created in memory but won't be saved to the database. Continuing with the +first_or_create+ example, we now want the client named 'Nick': +The +first_or_initialize+ method will work just like +first_or_create+ but it will not call +create+ but +new+. This means that a new model instance will be created in memory but won't be saved to the database. Continuing with the +first_or_create+ example, we now want the client named 'Nick': -nick = Client.where(:first_name => 'Nick').first_or_new(:locked => false) +nick = Client.where(:first_name => 'Nick').first_or_initialize(:locked => false) # => nick.persisted? @@ -1095,8 +1099,6 @@ nick.save # => true -Just like you can use *+build+* instead of *+new+*, you can use *+first_or_build+* instead of *+first_or_new+*. - h3. Finding by SQL If you'd like to use your own SQL to find records in a table you can use +find_by_sql+. The +find_by_sql+ method will return an array of objects even if the underlying query returns just a single record. For example you could run this query: -- cgit v1.2.3 From 5f2a35604e8180c916796abc93189bd1e0f7987f Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 14 Sep 2011 23:39:55 +0530 Subject: Mention that old fixes are to be done on 3-0-stable --- railties/guides/source/contributing_to_ruby_on_rails.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index 90eab150a1..86e31d79ee 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -200,11 +200,11 @@ You can also invoke +test_jdbcmysql+, +test_jdbcsqlite3+ or +test_jdbcpostgresql h4. Older versions of Ruby on Rails -If you want to add a fix to older versions of Ruby on Rails, you'll need to set up and switch to your own local tracking branch. Here is an example to switch to the 2-3-stable branch: +If you want to add a fix to older versions of Ruby on Rails, you'll need to set up and switch to your own local tracking branch. Here is an example to switch to the 3-0-stable branch: -$ git branch --track 2-3-stable origin/2-3-stable -$ git checkout 2-3-stable +$ git branch --track 3-0-stable origin/3-0-stable +$ git checkout 3-0-stable TIP: You may want to "put your git branch name in your shell prompt":http://qugstart.com/blog/git-and-svn/add-colored-git-branch-name-to-your-shell-prompt/ to make it easier to remember which version of the code you're working with. -- cgit v1.2.3 From 9980f46ca2d250d1d3e2fac84c5dc9ca6cbab1ea Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Thu, 15 Sep 2011 00:13:29 +0530 Subject: No more changelogs inside guides --- .../source/action_controller_overview.textile | 6 ------ railties/guides/source/action_mailer_basics.textile | 5 ----- railties/guides/source/action_view_overview.textile | 7 ------- railties/guides/source/active_model_basics.textile | 5 ----- .../guides/source/active_record_querying.textile | 9 --------- .../active_record_validations_callbacks.textile | 11 ----------- .../guides/source/active_resource_basics.textile | 4 ---- .../source/active_support_core_extensions.textile | 5 ----- .../source/api_documentation_guidelines.textile | 4 ---- railties/guides/source/association_basics.textile | 10 ---------- railties/guides/source/caching_with_rails.textile | 11 ----------- railties/guides/source/configuring.textile | 8 -------- .../source/contributing_to_ruby_on_rails.textile | 10 ---------- .../source/debugging_rails_applications.textile | 7 ------- railties/guides/source/form_helpers.textile | 10 ---------- railties/guides/source/generators.textile | 11 ----------- railties/guides/source/getting_started.textile | 21 --------------------- .../guides/source/layouts_and_rendering.textile | 12 ------------ railties/guides/source/migrations.textile | 6 ------ railties/guides/source/performance_testing.textile | 6 ------ railties/guides/source/plugins.textile | 8 -------- .../source/rails_application_templates.textile | 4 ---- railties/guides/source/rails_on_rack.textile | 5 ----- railties/guides/source/routing.textile | 9 --------- .../source/ruby_on_rails_guides_guidelines.textile | 5 ----- railties/guides/source/security.textile | 4 ---- railties/guides/source/testing.textile | 8 -------- 27 files changed, 211 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/action_controller_overview.textile b/railties/guides/source/action_controller_overview.textile index 4e47712636..d8d66302fe 100644 --- a/railties/guides/source/action_controller_overview.textile +++ b/railties/guides/source/action_controller_overview.textile @@ -815,9 +815,3 @@ end Please note that if you found yourself adding +force_ssl+ to many controllers, you may found yourself wanting to force the whole application to use HTTPS instead. In that case, you can set the +config.force_ssl+ in your environment file. - -h3. Changelog - -* February 17, 2009: Yet another proofread by Xavier Noria. - -* November 4, 2008: First release version by Tore Darell diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile index 67761645fa..ad5b848d2c 100644 --- a/railties/guides/source/action_mailer_basics.textile +++ b/railties/guides/source/action_mailer_basics.textile @@ -521,8 +521,3 @@ end In the test we send the email and store the returned object in the +email+ variable. We then ensure that it was sent (the first assert), then, in the second batch of assertions, we ensure that the email does indeed contain what we expect. - -h3. Changelog - -* September 1, 2011: Changed the lines that said config/environments/env.rb to config/environments/$RAILS_ENV.rb. People were mis-interpreting the filename to literally be env.rb. "Andy Leeper":http://mochaleaf.com -* September 30, 2010: Fixed typos and reformatted Action Mailer configuration table for better understanding. "Jaime Iniesta":http://jaimeiniesta.com diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile index edaaeb8543..87250c684b 100644 --- a/railties/guides/source/action_view_overview.textile +++ b/railties/guides/source/action_view_overview.textile @@ -1495,10 +1495,3 @@ end Then you could create special views like +app/views/posts/show.expert.html.erb+ that would only be displayed to expert users. You can read more about the Rails Internationalization (I18n) API "here":i18n.html. - -h3. Changelog - -* May 29, 2011: Removed references to remote_* helpers - Vijay Dev -* April 16, 2011: Added 'Using Action View with Rails', 'Templates' and 'Partials' sections. "Sebastian Martinez":http://wyeworks.com -* September 3, 2009: Continuing work by Trevor Turk, leveraging the Action Pack docs and "What's new in Edge Rails":http://ryandaigle.com/articles/2007/8/3/what-s-new-in-edge-rails-partials-get-layouts -* April 5, 2009: Starting work by Trevor Turk, leveraging Mike Gunderloy's docs diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index 73df567579..9c8ad24cee 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -203,8 +203,3 @@ person.valid? #=> true person.token = nil person.valid? #=> raises ActiveModel::StrictValidationFailed - -h3. Changelog - -* August 24, 2011: Add strict validation usage example. "Bogdan Gusiev":http://gusiev.com -* August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index ac8c15f60d..96f91cfef6 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -1248,12 +1248,3 @@ Client.sum("orders_count") For options, please see the parent section, "Calculations":#calculations. - -h3. Changelog - -* June 26 2011: Added documentation for the +scoped+, +unscoped+ and +default+ methods. "Ryan Bigg":credits.html#radar -* December 23 2010: Add documentation for the +scope+ method. "Ryan Bigg":credits.html#radar -* April 7, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com -* February 3, 2010: Update to Rails 3 by "James Miller":credits.html#bensie -* February 7, 2009: Second version by "Pratik":credits.html#lifo -* December 29 2008: Initial version by "Ryan Bigg":credits.html#radar diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index aba3224ba7..20f5e52891 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -1267,14 +1267,3 @@ end The +after_commit+ and +after_rollback+ callbacks are guaranteed to be called for all models created, updated, or destroyed within a transaction block. If any exceptions are raised within one of these callbacks, they will be ignored so that they don't interfere with the other callbacks. As such, if your callback code could raise an exception, you'll need to rescue it and handle it appropriately within the callback. - -h3. Changelog - -* February 17, 2011: Add description of transaction callbacks. -* July 20, 2010: Fixed typos and rephrased some paragraphs for clarity. "Jaime Iniesta":http://jaimeiniesta.com -* May 24, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com -* May 15, 2010: Validation Errors section updated by "Emili Parreño":http://www.eparreno.com -* March 7, 2009: Callbacks revision by Trevor Turk -* February 10, 2009: Observers revision by Trevor Turk -* February 5, 2009: Initial revision by Trevor Turk -* January 9, 2009: Initial version by "Cássio Marques":credits.html#cmarques diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 3294227f7b..851aac1a3f 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -118,7 +118,3 @@ This validates the resource with any local validations written in base class and h5. valid? Runs all the local validations and will return true if no errors. - -h3. Changelog - -* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 9e2fe2c694..d006cc9214 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -3599,8 +3599,3 @@ end NOTE: Defined in +active_support/core_ext/load_error.rb+. - -h3. Changelog - -* August 10, 2010: Starts to take shape, added to the index. -* April 18, 2009: Initial version by "Xavier Noria":credits.html#fxn diff --git a/railties/guides/source/api_documentation_guidelines.textile b/railties/guides/source/api_documentation_guidelines.textile index 3ebf0e10f1..c0f709eda8 100644 --- a/railties/guides/source/api_documentation_guidelines.textile +++ b/railties/guides/source/api_documentation_guidelines.textile @@ -183,7 +183,3 @@ self.class_eval %{ end } - -h3. Changelog - -* July 17, 2010: ported from the docrails wiki and revised by "Xavier Noria":credits.html#fxn diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile index 479693dbf8..f5f0f9340c 100644 --- a/railties/guides/source/association_basics.textile +++ b/railties/guides/source/association_basics.textile @@ -1860,13 +1860,3 @@ Extensions can refer to the internals of the association proxy using these three * +proxy_association.owner+ returns the object that the association is a part of. * +proxy_association.reflection+ returns the reflection object that describes the association. * +proxy_association.target+ returns the associated object for +belongs_to+ or +has_one+, or the collection of associated objects for +has_many+ or +has_and_belongs_to_many+. - -h3. Changelog - -* September 13, 2011: Removed mention of deprecated proxy methods in favor of using +proxy_association+. "Dallas Reedy":https://github.com/dallas -* April 7, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com -* April 19, 2009: Added +:touch+ option to +belongs_to+ associations by "Mike Gunderloy":credits.html#mgunderloy -* February 1, 2009: Added +:autosave+ option "Mike Gunderloy":credits.html#mgunderloy -* September 28, 2008: Corrected +has_many :through+ diagram, added polymorphic diagram, some reorganization by "Mike Gunderloy":credits.html#mgunderloy . First release version. -* September 22, 2008: Added diagrams, misc. cleanup by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication) -* September 14, 2008: initial version by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication) diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile index 693303950d..19378d63ce 100644 --- a/railties/guides/source/caching_with_rails.textile +++ b/railties/guides/source/caching_with_rails.textile @@ -403,14 +403,3 @@ end h3. Further reading * "Scaling Rails Screencasts":http://railslab.newrelic.com/scaling-rails - -h3. Changelog - -* Feb 17, 2011: Document 3.0.0 changes to ActiveSupport::Cache -* May 02, 2009: Formatting cleanups -* April 26, 2009: Clean up typos in submitted patch -* April 1, 2009: Made a bunch of small fixes -* February 22, 2009: Beefed up the section on cache_stores -* December 27, 2008: Typo fixes -* November 23, 2008: Incremental updates with various suggested changes and formatting cleanup -* September 15, 2008: Initial version by Aditya Chadha diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index ae84bb5b92..cad2d03c23 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -604,11 +604,3 @@ The error occurred while evaluating nil.each *+set_routes_reloader+* Configures Action Dispatch to reload the routes file using +ActionDispatch::Callbacks.to_prepare+. *+disable_dependency_loading+* Disables the automatic dependency loading if the +config.cache_classes+ is set to true and +config.dependency_loading+ is set to false. - -h3. Changelog - -* December 3, 2010: Added initialization events for Rails 3 ("Ryan Bigg":http://ryanbigg.com) -* November 26, 2010: Removed all config settings not available in Rails 3 ("Ryan Bigg":http://ryanbigg.com) -* August 13, 2009: Updated with config syntax and added general configuration options by "John Pignata" -* January 3, 2009: First reasonably complete draft by "Mike Gunderloy":credits.html#mgunderloy -* November 5, 2008: Rough outline by "Mike Gunderloy":credits.html#mgunderloy diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index 86e31d79ee..30714e7e18 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -383,13 +383,3 @@ And then...think about your next contribution! h3. Rails Contributors All contributions, either via master or docrails, get credit in "Rails Contributors":http://contributors.rubyonrails.org. - -h3. Changelog - -* May 12, 2011: Modified to prefer topic branches instead of master branch for users contributions by "Guillermo Iguaran":http://quillarb.org -* April 29, 2011: Reflect GitHub Issues and Pull Request workflow by "Dan Pickett":http://www.enlightsolutions.com -* April 14, 2011: Modified Contributing to the Rails Code section to add '[#ticket_number state:commited]' on patches commit messages by "Sebastian Martinez":http://wyeworks.com -* December 28, 2010: Complete revision by "Xavier Noria":credits.html#fxn -* April 6, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com -* August 1, 2009: Updates/amplifications by "Mike Gunderloy":credits.html#mgunderloy -* March 2, 2009: Initial draft by "Mike Gunderloy":credits.html#mgunderloy diff --git a/railties/guides/source/debugging_rails_applications.textile b/railties/guides/source/debugging_rails_applications.textile index f5bee52b5a..3552c68418 100644 --- a/railties/guides/source/debugging_rails_applications.textile +++ b/railties/guides/source/debugging_rails_applications.textile @@ -712,10 +712,3 @@ h3. References * "ruby-debug cheat sheet":http://cheat.errtheblog.com/s/rdebug/ * "Ruby on Rails Wiki: How to Configure Logging":http://wiki.rubyonrails.org/rails/pages/HowtoConfigureLogging * "Bleak House Documentation":http://blog.evanweaver.com/files/doc/fauna/bleak_house/files/README.html - -h3. Changelog - -* April 4, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com -* November 3, 2008: Accepted for publication. Added RJS, memory leaks and plugins chapters by "Emilio Tagua":credits.html#miloops -* October 19, 2008: Copy editing pass by "Mike Gunderloy":credits.html#mgunderloy -* September 16, 2008: initial version by "Emilio Tagua":credits.html#miloops diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index c277f5723a..821bb305f6 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -796,13 +796,3 @@ Many apps grow beyond simple forms editing a single object. For example when cre * Eloy Duran's "complex-forms-examples":https://github.com/alloy/complex-form-examples/ application * Lance Ivy's "nested_assignment":https://github.com/cainlevy/nested_assignment/tree/master plugin and "sample application":https://github.com/cainlevy/complex-form-examples/tree/cainlevy * James Golick's "attribute_fu":https://github.com/jamesgolick/attribute_fu plugin - -h3. Changelog - -* February 5, 2011: Added 'Forms to external resources' section. Timothy N. Tsvetkov -* April 6, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com - -h3. Authors - -* Mislav Marohnić -* "Frederick Cheung":credits.html#fcheung diff --git a/railties/guides/source/generators.textile b/railties/guides/source/generators.textile index 3f990ef54b..7a863ccbc7 100644 --- a/railties/guides/source/generators.textile +++ b/railties/guides/source/generators.textile @@ -619,14 +619,3 @@ Output the contents of a file in the template's +source_path+, usually a README. readme("README") - -h3. Changelog - -* December 1, 2010: Documenting the available methods and options for generators and templates by "Ryan Bigg":http://ryanbigg.com -* December 1, 2010: Addition of Rails application templates by "Ryan Bigg":http://ryanbigg.com - -* August 23, 2010: Edit pass by "Xavier Noria":credits.html#fxn - -* April 30, 2010: Reviewed by José Valim - -* November 20, 2009: First version by José Valim diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 95324d4da4..33f383f173 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1888,24 +1888,3 @@ Two very common sources of data that are not UTF-8: is using Latin-1 internally, and your user enters a Russian, Hebrew, or Japanese character, the data will be lost forever once it enters the database. If possible, use UTF-8 as the internal storage of your database. - -h3. Changelog - -* April 26, 2011: Change migration code from +up+, +down+ pair to +change+ method by "Prem Sichanugrist":http://sikachu.com -* April 11, 2011: Change scaffold_controller generator to create format block for JSON instead of XML by "Sebastian Martinez":http://www.wyeworks.com -* August 30, 2010: Minor editing after Rails 3 release by Joost Baaij -* July 12, 2010: Fixes, editing and updating of code samples by "Jaime Iniesta":http://jaimeiniesta.com -* May 16, 2010: Added a section on configuration gotchas to address common encoding problems that people might have by "Yehuda Katz":http://www.yehudakatz.com -* April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com -* April 25, 2010: Couple of more minor fixups by "Mikel Lindsaar":credits.html#raasdnil -* April 1, 2010: Fixed document to validate XHTML 1.0 Strict by "Jaime Iniesta":http://jaimeiniesta.com -* February 8, 2010: Full re-write for Rails 3.0-beta, added helpers and before_filters, refactored code by "Mikel Lindsaar":credits.html#raasdnil -* January 24, 2010: Re-write for Rails 3.0 by "Mikel Lindsaar":credits.html#raasdnil -* July 18, 2009: Minor cleanup in anticipation of Rails 2.3.3 by "Mike Gunderloy":credits.html#mgunderloy -* February 1, 2009: Updated for Rails 2.3 by "Mike Gunderloy":credits.html#mgunderloy -* November 3, 2008: Formatting patch from Dave Rothlisberger -* November 1, 2008: First approved version by "Mike Gunderloy":credits.html#mgunderloy -* October 16, 2008: Revised based on feedback from Pratik Naik by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication) -* October 13, 2008: First complete draft by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication) -* October 12, 2008: More detail, rearrangement, editing by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication) -* September 8, 2008: initial version by "James Miller":credits.html#bensie (not yet approved for publication) diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index f49c2000ee..69ef05104c 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -1194,15 +1194,3 @@ On pages generated by +NewsController+, you want to hide the top menu and add a That's it. The News views will use the new layout, hiding the top menu and adding a new right menu inside the "content" div. There are several ways of getting similar results with different sub-templating schemes using this technique. Note that there is no limit in nesting levels. One can use the +ActionView::render+ method via +render :template => 'layouts/news'+ to base a new layout on the News layout. If you are sure you will not subtemplate the +News+ layout, you can replace the +content_for?(:news_content) ? yield(:news_content) : yield+ with simply +yield+. - -h3. Changelog - -* April 4, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com -* January 25, 2010: Rails 3.0 Update by "Mikel Lindsaar":credits.html#raasdnil -* December 27, 2008: Merge patch from Rodrigo Rosenfeld Rosas covering subtemplates -* December 27, 2008: Information on new rendering defaults by "Mike Gunderloy":credits.html#mgunderloy -* November 9, 2008: Added partial collection counter by "Mike Gunderloy":credits.html#mgunderloy -* November 1, 2008: Added +:js+ option for +render+ by "Mike Gunderloy":credits.html#mgunderloy -* October 16, 2008: Ready for publication by "Mike Gunderloy":credits.html#mgunderloy -* October 4, 2008: Additional info on partials (+:object+, +:as+, and +:spacer_template+) by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication) -* September 28, 2008: First draft by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication) diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index 6fcc3cf4a2..7faa18e888 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -673,9 +673,3 @@ The Active Record way claims that intelligence belongs in your models, not in th Validations such as +validates :foreign_key, :uniqueness => true+ are one way in which models can enforce data integrity. The +:dependent+ option on associations allows models to automatically destroy child objects when the parent is destroyed. Like anything which operates at the application level these cannot guarantee referential integrity and so some people augment them with foreign key constraints. Although Active Record does not provide any tools for working directly with such features, the +execute+ method can be used to execute arbitrary SQL. There are also a number of plugins such as "foreign_key_migrations":https://github.com/harukizaemon/redhillonrails/tree/master/foreign_key_migrations/ which add foreign key support to Active Record (including support for dumping foreign keys in +db/schema.rb+). - -h3. Changelog - -* April 26, 2011: change generated +up+ and +down+ methods to +change+ method, and describe detail about +change+ method by "Prem Sichanugrist":http://sikachu.com -* July 15, 2010: minor typos corrected by "Jaime Iniesta":http://jaimeiniesta.com -* September 14, 2008: initial version by "Frederick Cheung":credits.html#fcheung diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile index 5947735deb..f3ea7e38bc 100644 --- a/railties/guides/source/performance_testing.textile +++ b/railties/guides/source/performance_testing.textile @@ -595,9 +595,3 @@ Rails has been lucky to have a few companies dedicated to Rails-specific perform * "New Relic":http://www.newrelic.com * "Scout":http://scoutapp.com - -h3. Changelog - -* March 30, 2011: Documented the recent improvements (multiple interpreters, options, etc) and necessary adjustments. Other minor improvements. "Gonçalo Silva":http://goncalossilva.com. -* January 9, 2009: Complete rewrite by "Pratik":credits.html#lifo -* September 6, 2008: Initial version by Matthew Bergman diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile index e8bdfa7f1c..5cfd336d1e 100644 --- a/railties/guides/source/plugins.textile +++ b/railties/guides/source/plugins.textile @@ -462,11 +462,3 @@ h4. References * "Gemspec Reference":http://docs.rubygems.org/read/chapter/20 * "GemPlugins":http://www.mbleigh.com/2008/06/11/gemplugins-a-brief-introduction-to-the-future-of-rails-plugins * "Keeping init.rb thin":http://daddy.platte.name/2007/05/rails-plugins-keep-initrb-thin.html - -h3. Changelog - -* March 10, 2011: Minor formatting tweaks. -* February 13, 2011: Get guide in synch with Rails 3.0.3. Remove information not compatible with Rails 3. Send reader elsewhere -for information that is covered elsewhere. -* April 4, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com -* November 17, 2008: Major revision by Jeff Dean diff --git a/railties/guides/source/rails_application_templates.textile b/railties/guides/source/rails_application_templates.textile index c3c8af4d3a..3b51a52733 100644 --- a/railties/guides/source/rails_application_templates.textile +++ b/railties/guides/source/rails_application_templates.textile @@ -238,7 +238,3 @@ git :init git :add => "." git :commit => "-a -m 'Initial commit'" - -h3. Changelog - -* April 29, 2009: Initial version by "Pratik":credits.html#lifo diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile index 735438b155..57c03b54dc 100644 --- a/railties/guides/source/rails_on_rack.textile +++ b/railties/guides/source/rails_on_rack.textile @@ -232,8 +232,3 @@ h4. Learning Rack h4. Understanding Middlewares * "Railscast on Rack Middlewares":http://railscasts.com/episodes/151-rack-middleware - -h3. Changelog - -* February 7, 2009: Second version by "Pratik":credits.html#lifo -* January 11, 2009: First version by "Pratik":credits.html#lifo diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 99dd9a1cd2..0a9f1e8388 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -881,12 +881,3 @@ The +assert_routing+ assertion checks the route both ways: it tests that the pat assert_routing({ :path => "photos", :method => :post }, { :controller => "photos", :action => "create" }) - -h3. Changelog - -* April 10, 2010: Updated guide to remove outdated and superfluous information, and to provide information about new features, by "Yehuda Katz":http://www.yehudakatz.com -* April 2, 2010: Updated guide to match new Routing DSL in Rails 3, by "Rizwan Reza":http://www.rizwanreza.com/ -* February 1, 2010: Modifies the routing documentation to match new routing DSL in Rails 3, by Prem Sichanugrist -* October 4, 2008: Added additional detail on specifying verbs for resource member/collection routes, by "Mike Gunderloy":credits.html#mgunderloy -* September 23, 2008: Added section on namespaced controllers and routing, by "Mike Gunderloy":credits.html#mgunderloy -* September 10, 2008: initial version by "Mike Gunderloy":credits.html#mgunderloy diff --git a/railties/guides/source/ruby_on_rails_guides_guidelines.textile b/railties/guides/source/ruby_on_rails_guides_guidelines.textile index 5989191b5c..e63f564c83 100644 --- a/railties/guides/source/ruby_on_rails_guides_guidelines.textile +++ b/railties/guides/source/ruby_on_rails_guides_guidelines.textile @@ -77,8 +77,3 @@ bundle exec rake validate_guides Particularly, titles get an ID generated from their content and this often leads to duplicates. Please set +WARNINGS=1+ when generating guides to detect them. The warning messages suggest a way to fix them. - -h3. Changelog - -* March 31, 2011: grammar tweaks by "Josiah Ivey":http://twitter.com/josiahivey -* October 5, 2010: ported from the docrails wiki and revised by "Xavier Noria":credits.html#fxn diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile index 04d1d0bda8..4cf9e2a7f3 100644 --- a/railties/guides/source/security.textile +++ b/railties/guides/source/security.textile @@ -1002,7 +1002,3 @@ The security landscape shifts and it is important to keep up to date, because mi * Subscribe to the Rails security "mailing list":http://groups.google.com/group/rubyonrails-security * "Keep up to date on the other application layers":http://secunia.com/ (they have a weekly newsletter, too) * A "good security blog":http://ha.ckers.org/blog/ including the "Cross-Site scripting Cheat Sheet":http://ha.ckers.org/xss.html - -h3. Changelog - -* November 1, 2008: First approved version by Heiko Webers diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index caa0d91a83..2341a3522c 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -945,11 +945,3 @@ The built-in +test/unit+ based testing is not the only way to test Rails applica * "Machinist":https://github.com/notahat/machinist/tree/master, another replacement for fixtures. * "Shoulda":http://www.thoughtbot.com/projects/shoulda, an extension to +test/unit+ with additional helpers, macros, and assertions. * "RSpec":http://relishapp.com/rspec, a behavior-driven development framework - -h3. Changelog - -* April 4, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com -* November 13, 2008: Revised based on feedback from Pratik Naik by "Akshay Surve":credits.html#asurve (not yet approved for publication) -* October 14, 2008: Edit and formatting pass by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication) -* October 12, 2008: First draft by "Akshay Surve":credits.html#asurve (not yet approved for publication) - -- cgit v1.2.3 From 7531aa76417a5db337287c31c1b97ad53615c8e6 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Thu, 15 Sep 2011 10:41:55 +0400 Subject: update guides, use html safe translations in i18n --- .../guides/assets/images/i18n/demo_html_safe.png | Bin 0 -> 11946 bytes railties/guides/source/i18n.textile | 22 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 railties/guides/assets/images/i18n/demo_html_safe.png (limited to 'railties') diff --git a/railties/guides/assets/images/i18n/demo_html_safe.png b/railties/guides/assets/images/i18n/demo_html_safe.png new file mode 100644 index 0000000000..f881f60dac Binary files /dev/null and b/railties/guides/assets/images/i18n/demo_html_safe.png differ diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index 4b6b08bcec..76cd14d479 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -448,6 +448,7 @@ Covered are features like these: * looking up translations * interpolating data into translations * pluralizing translations +* using safe HTML translations * localizing dates, numbers, currency, etc. h4. Looking up Translations @@ -599,6 +600,27 @@ The +I18n.locale+ defaults to +I18n.default_locale+ which defaults to :+en+. The I18n.default_locale = :de +h4. Using Safe HTML Translations + +Keys with a '_html' suffix and keys named 'html' are marked as HTML safe. Use them in views without escaping. + + +# config/locales/en.yml +en: + welcome: welcome! + hello_html: hello! + title: + html: title! + +# app/views/home/index.html.erb +
      <%= t('welcome') %>
      +
      <%= raw t('welcome') %>
      +
      <%= t('hello_html') %>
      +
      <%= t('title.html') %>
      +
      + +!images/i18n/demo_html_safe.png(i18n demo html safe)! + h3. How to Store your Custom Translations The Simple backend shipped with Active Support allows you to store translations in both plain Ruby and YAML format. [2] -- cgit v1.2.3 From b50394bf844d0520d5dca485b169bba87f6d009a Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Thu, 15 Sep 2011 19:55:52 -0500 Subject: config.action_controller.asset_host shouldn't set to nil during precompile --- railties/test/application/assets_test.rb | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'railties') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 959914bcea..dfd950aae3 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -270,20 +270,6 @@ module ApplicationTests assert_match(/\/assets\/rails-([0-z]+)\.png/, File.read(file)) end - test "precompile ignore asset_host" do - app_file "app/assets/javascripts/application.css.erb", "<%= asset_path 'rails.png' %>" - add_to_config "config.action_controller.asset_host = Proc.new { |source, request| 'http://www.example.com/' }" - - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end - - file = Dir["#{app_path}/public/assets/application.css"].first - content = File.read(file) - assert_match(/\/assets\/rails.png/, content) - assert_no_match(/www\.example\.com/, content) - end - test "precompile should handle utf8 filenames" do app_file "app/assets/images/レイルズ.png", "not a image really" add_to_config "config.assets.precompile = [ /\.png$$/, /application.(css|js)$/ ]" -- cgit v1.2.3 From 28677014a4f8121272a17870246507e86e46837c Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Thu, 15 Sep 2011 20:07:01 -0500 Subject: Add reference about --skip-sprockets to Asset Pipeline Guide --- railties/guides/source/asset_pipeline.textile | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index ce4eafb97c..74dfdfb540 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -25,6 +25,12 @@ In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +a config.assets.enabled = false +You can also disable it when you are creating a new application passing the --skip-sprockets parameter: + + +rails new appname --skip-sprockets + + It is recommended that you use the defaults for all new apps. -- cgit v1.2.3 From 302e570777b1ca8f537c96628334dcbe8a94d83f Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Fri, 16 Sep 2011 17:43:05 +0400 Subject: "Passing variables into the translation" section added --- railties/guides/source/i18n.textile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index 76cd14d479..a35cd6c506 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -365,6 +365,20 @@ NOTE: You need to restart the server when you add new locale files. You may use YAML (+.yml+) or plain Ruby (+.rb+) files for storing your translations in SimpleStore. YAML is the preferred option among Rails developers. However, it has one big disadvantage. YAML is very sensitive to whitespace and special characters, so the application may not load your dictionary properly. Ruby files will crash your application on first request, so you may easily find what's wrong. (If you encounter any "weird issues" with YAML dictionaries, try putting the relevant portion of your dictionary into a Ruby file.) +h4. Passing variables into the translation + +You may use translation with parameters, if you want. + + +# app/views/home/index.html.erb +

      <%=t 'greet_username', :user => "Bill", :message => "Goodbye" %>

      +

      <%=t 'greet_username', :user => "DHH", :message => "Hello" %>

      + +# config/locales/en.yml +en: + greet_username: "%{message}, %{user}!" +
      + h4. Adding Date/Time Formats OK! Now let's add a timestamp to the view, so we can demo the *date/time localization* feature as well. To localize the time format you pass the Time object to +I18n.l+ or (preferably) use Rails' +#l+ helper. You can pick a format by passing the +:format+ option -- by default the +:default+ format is used. -- cgit v1.2.3 From 8411f631c42de7d6f51d10d997b037b9eff0d1f1 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 16 Sep 2011 23:22:03 +0530 Subject: minor edit --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 74dfdfb540..bea5e494d5 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -25,7 +25,7 @@ In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +a config.assets.enabled = false -You can also disable it when you are creating a new application passing the --skip-sprockets parameter: +You can also disable it while creating a new application by passing the --skip-sprockets option. rails new appname --skip-sprockets -- cgit v1.2.3 From 27f1320fde03279c575693f504897f1a6171bc59 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 16 Sep 2011 22:12:41 +0530 Subject: Fixing incorrect notextile tags --- .../guides/source/action_view_overview.textile | 2 +- .../active_record_validations_callbacks.textile | 4 ++-- .../source/active_support_core_extensions.textile | 26 +++++++++++----------- railties/guides/source/ajax_on_rails.textile | 4 +++- .../source/api_documentation_guidelines.textile | 2 +- railties/guides/source/asset_pipeline.textile | 2 +- railties/guides/source/initialization.textile | 2 +- .../source/ruby_on_rails_guides_guidelines.textile | 2 +- railties/guides/source/security.textile | 6 ++--- 9 files changed, 26 insertions(+), 24 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile index 87250c684b..40cde6ad84 100644 --- a/railties/guides/source/action_view_overview.textile +++ b/railties/guides/source/action_view_overview.textile @@ -898,7 +898,7 @@ h5. select_year Returns a select tag with options for each of the five years on each side of the current, which is selected. The five year radius can be changed using the +:start_year+ and +:end_year+ keys in the +options+. -# Generates a select field for five years on either side of +Date.today+ that defaults to the current year +# Generates a select field for five years on either side of Date.today that defaults to the current year select_year(Date.today) # Generates a select field from 1900 to 2009 that defaults to the current year diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 20f5e52891..5c3aae2955 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -328,7 +328,7 @@ This helper validates that your attributes have only numeric values. By default, If you set +:only_integer+ to +true+, then it will use the -/\A[+-]?\d+\Z/ +/\A[-]?\d\Z/ regular expression to validate the attribute's value. Otherwise, it will try to convert the value to a number using +Float+. @@ -597,7 +597,7 @@ The easiest way to add custom validators for validating individual attributes is class EmailValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i + unless value =~ /\A([^@\s])@((?:[-a-z0-9]\.)+[a-z]{2,})\z/i record.errors[attribute] << (options[:message] || "is not an email") end end diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index d006cc9214..b3d8760a73 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -296,7 +296,7 @@ This method escapes whatever is needed, both for the key and the value: account.to_query('company[name]') -# => "company%5Bname%5D=Johnson+%26+Johnson" +# => "company%5Bname%5D=Johnson%26Johnson" so its output is ready to be used in a query string. @@ -3385,11 +3385,11 @@ They are analogous. Please refer to their documentation above and take into acco Time.zone_default # => # -# In Barcelona, 2010/03/28 02:00 +0100 becomes 2010/03/28 03:00 +0200 due to DST. +# In Barcelona, 2010/03/28 02:00 0100 becomes 2010/03/28 03:00 0200 due to DST. t = Time.local_time(2010, 3, 28, 1, 59, 59) -# => Sun Mar 28 01:59:59 +0100 2010 +# => Sun Mar 28 01:59:59 0100 2010 t.advance(:seconds => 1) -# => Sun Mar 28 03:00:00 +0200 2010 +# => Sun Mar 28 03:00:00 0200 2010 * If +since+ or +ago+ jump to a time that can't be expressed with +Time+ a +DateTime+ object is returned instead. @@ -3406,24 +3406,24 @@ The method +all_day+ returns a range representing the whole day of the current t now = Time.current -# => Mon, 09 Aug 2010 23:20:05 UTC +00:00 +# => Mon, 09 Aug 2010 23:20:05 UTC 00:00 now.all_day -# => Mon, 09 Aug 2010 00:00:00 UTC +00:00..Mon, 09 Aug 2010 23:59:59 UTC +00:00 +# => Mon, 09 Aug 2010 00:00:00 UTC 00:00..Mon, 09 Aug 2010 23:59:59 UTC 00:00 Analogously, +all_week+, +all_month+, +all_quarter+ and +all_year+ all serve the purpose of generating time ranges. now = Time.current -# => Mon, 09 Aug 2010 23:20:05 UTC +00:00 +# => Mon, 09 Aug 2010 23:20:05 UTC 00:00 now.all_week -# => Mon, 09 Aug 2010 00:00:00 UTC +00:00..Sun, 15 Aug 2010 23:59:59 UTC +00:00 +# => Mon, 09 Aug 2010 00:00:00 UTC 00:00..Sun, 15 Aug 2010 23:59:59 UTC 00:00 now.all_month -# => Sat, 01 Aug 2010 00:00:00 UTC +00:00..Tue, 31 Aug 2010 23:59:59 UTC +00:00 +# => Sat, 01 Aug 2010 00:00:00 UTC 00:00..Tue, 31 Aug 2010 23:59:59 UTC 00:00 now.all_quarter -# => Thu, 01 Jul 2010 00:00:00 UTC +00:00..Thu, 30 Sep 2010 23:59:59 UTC +00:00 +# => Thu, 01 Jul 2010 00:00:00 UTC 00:00..Thu, 30 Sep 2010 23:59:59 UTC 00:00 now.all_year -# => Fri, 01 Jan 2010 00:00:00 UTC +00:00..Fri, 31 Dec 2010 23:59:59 UTC +00:00 +# => Fri, 01 Jan 2010 00:00:00 UTC 00:00..Fri, 31 Dec 2010 23:59:59 UTC 00:00 h4. Time Constructors @@ -3434,7 +3434,7 @@ Active Support defines +Time.current+ to be +Time.zone.now+ if there's a user ti Time.zone_default # => # Time.current -# => Fri, 06 Aug 2010 17:11:58 CEST +02:00 +# => Fri, 06 Aug 2010 17:11:58 CEST 02:00 Analogously to +DateTime+, the predicates +past?+, and +future?+ are relative to +Time.current+. @@ -3445,7 +3445,7 @@ Use the +local_time+ class method to create time objects honoring the user time Time.zone_default # => # Time.local_time(2010, 8, 15) -# => Sun Aug 15 00:00:00 +0200 2010 +# => Sun Aug 15 00:00:00 0200 2010 The +utc_time+ class method returns a time in UTC: diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile index 77f7661deb..29d4fae888 100644 --- a/railties/guides/source/ajax_on_rails.textile +++ b/railties/guides/source/ajax_on_rails.textile @@ -104,7 +104,7 @@ Note that if we wouldn't override the default behavior (POST), the above snippet link_to_remote "Update record", :url => record_url(record), :method => :put, - :with => "'status=' + 'encodeURIComponent($('status').value) + '&completed=' + $('completed')" + :with => "'status=' 'encodeURIComponent($('status').value) '&completed=' $('completed')" This generates a remote link which adds 2 parameters to the standard URL generated by Rails, taken from the page (contained in the elements matched by the 'status' and 'completed' DOM id). @@ -124,6 +124,7 @@ link_to_remote "Add new item", 404 => "alert('Item not found!')" Let's see a typical example for the most frequent callbacks, +:success+, +:failure+ and +:complete+ in action: + link_to_remote "Add new item", :url => items_url, @@ -133,6 +134,7 @@ link_to_remote "Add new item", :success => "display_item_added(request)", :failure => "display_error(request)" + ** *:type* If you want to fire a synchronous request for some obscure reason (blocking the browser while the request is processed and doesn't return a status code), you can use the +:type+ option with the value of +:synchronous+. * Finally, using the +html_options+ parameter you can add HTML attributes to the generated tag. It works like the same parameter of the +link_to+ helper. There are interesting side effects for the +href+ and +onclick+ parameters though: ** If you specify the +href+ parameter, the AJAX link will degrade gracefully, i.e. the link will point to the URL even if JavaScript is disabled in the client browser diff --git a/railties/guides/source/api_documentation_guidelines.textile b/railties/guides/source/api_documentation_guidelines.textile index c0f709eda8..99eb668513 100644 --- a/railties/guides/source/api_documentation_guidelines.textile +++ b/railties/guides/source/api_documentation_guidelines.textile @@ -146,7 +146,7 @@ h3. Description Lists In lists of options, parameters, etc. use a hyphen between the item and its description (reads better than a colon because normally options are symbols): -# * :allow_nil - Skip validation if attribute is +nil+. +# * :allow_nil - Skip validation if attribute is nil. The description starts in upper case and ends with a full stop—it's standard English. diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index bea5e494d5..e03ae736a8 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -359,7 +359,7 @@ NOTE. If you are precompiling your assets locally, you can use +bundle install - The default matcher for compiling files includes +application.js+, +application.css+ and all files that do not end in +js+ or +css+: -[ /\w+\.(?!js|css).+/, /application.(css|js)$/ ] +[ /\w\.(?!js|css)./, /application.(css|js)$/ ] If you have other manifests or individual stylesheets and JavaScript files to include, you can add them to the +precompile+ array: diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 8aabc3ae91..32b41fdd2c 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -450,7 +450,7 @@ run YourApp::Application The +Rack::Builder.parse_file+ method here takes the content from this +config.ru+ file and parses it using this code: -app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app", +app = eval "Rack::Builder.new {( " cfgfile "\n )}.to_app", TOPLEVEL_BINDING, config diff --git a/railties/guides/source/ruby_on_rails_guides_guidelines.textile b/railties/guides/source/ruby_on_rails_guides_guidelines.textile index e63f564c83..29aefd25f8 100644 --- a/railties/guides/source/ruby_on_rails_guides_guidelines.textile +++ b/railties/guides/source/ruby_on_rails_guides_guidelines.textile @@ -26,7 +26,7 @@ h5. When are Objects Saved? Use the same typography as in regular text: -h6. The +:content_type+ Option +h6. The :content_type Option h3. API Documentation Guidelines diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile index 4cf9e2a7f3..73c7a80ff6 100644 --- a/railties/guides/source/security.textile +++ b/railties/guides/source/security.textile @@ -582,7 +582,7 @@ Ruby uses a slightly different approach than many other languages to match the e class File < ActiveRecord::Base - validates :name, :format => /^[\w\.\-\+]+$/ + validates :name, :format => /^[\w\.\-\]$/ end @@ -595,7 +595,7 @@ file.txt%0A Whereas %0A is a line feed in URL encoding, so Rails automatically converts it to "file.txt\n<script>alert('hello')</script>". This file name passes the filter because the regular expression matches – up to the line end, the rest does not matter. The correct expression should read: -/\A[\w\.\-\+]+\z/ +/\A[\w\.\-\]\z/ h4. Privilege Escalation @@ -762,7 +762,7 @@ These examples don't do any harm so far, so let's see how an attacker can steal For an attacker, of course, this is not useful, as the victim will see his own cookie. The next example will try to load an image from the URL http://www.attacker.com/ plus the cookie. Of course this URL does not exist, so the browser displays nothing. But the attacker can review his web server's access log files to see the victim's cookie. - + The log files on www.attacker.com will read like this: -- cgit v1.2.3 From 6e63e029b335b1a5dfce43c20de27ca6fae29fa4 Mon Sep 17 00:00:00 2001 From: Alex Yakoubian Date: Wed, 14 Sep 2011 23:14:23 -0700 Subject: Default precompile regexp that properly matches application.js and application.css --- railties/lib/rails/application/configuration.rb | 2 +- railties/test/application/assets_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index a48db3b6d2..141b39fb4b 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -38,7 +38,7 @@ module Rails @assets.enabled = false @assets.paths = [] @assets.precompile = [ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) }, - /application.(css|js)$/ ] + /(?:\/|\\|\A)application\.(css|js)$/ ] @assets.prefix = "/assets" @assets.version = '' @assets.debug = false diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index dfd950aae3..a62ef1e70e 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -68,6 +68,10 @@ module ApplicationTests test "precompile application.js and application.css and all other files not ending with .js or .css by default" do app_file "app/assets/javascripts/application.js", "alert();" app_file "app/assets/stylesheets/application.css", "body{}" + + app_file "app/assets/javascripts/someapplication.js", "alert();" + app_file "app/assets/stylesheets/someapplication.css", "body{}" + app_file "app/assets/javascripts/something.min.js", "alert();" app_file "app/assets/stylesheets/something.min.css", "body{}" @@ -87,8 +91,13 @@ module ApplicationTests images_should_compile.each do |filename| assert File.exists?("#{app_path}/public/assets/#{filename}") end + assert File.exists?("#{app_path}/public/assets/application.js") assert File.exists?("#{app_path}/public/assets/application.css") + + assert !File.exists?("#{app_path}/public/assets/someapplication.js") + assert !File.exists?("#{app_path}/public/assets/someapplication.css") + assert !File.exists?("#{app_path}/public/assets/something.min.js") assert !File.exists?("#{app_path}/public/assets/something.min.css") end -- cgit v1.2.3 From 663031801cac577a88931cdfe6f062555112f370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=A3is=20Ozols?= Date: Sat, 17 Sep 2011 10:00:53 +0300 Subject: sass-rails helpers - hyphenated in Sass, underscored in Ruby. --- railties/guides/source/asset_pipeline.textile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index e03ae736a8..586a9f46eb 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -170,15 +170,15 @@ Note that the closing tag cannot be of the style +-%>+. h5. CSS and Sass -When using the asset pipeline, paths to assets must be re-written and +sass-rails+ provides +_url+ and +_path+ helpers for the following asset classes: image, font, video, audio, JavaScript and stylesheet. +When using the asset pipeline, paths to assets must be re-written and +sass-rails+ provides +-url+ and +-path+ helpers (hyphenated in Sass, underscored in Ruby) for the following asset classes: image, font, video, audio, JavaScript and stylesheet. -* +image_url("rails.png")+ becomes +url(/assets/rails.png)+. -* +image_path("rails.png")+ becomes +"/assets/rails.png"+. +* +image-url("rails.png")+ becomes +url(/assets/rails.png)+ +* +image-path("rails.png")+ becomes +"/assets/rails.png"+. The more generic form can also be used but the asset path and class must both be specified: -* +asset_url("rails.png", image)+ becomes +url(/assets/rails.png)+. -* +asset_path("rails.png", image)+ becomes +"/assets/rails.png"+. +* +asset-url("rails.png", image)+ becomes +url(/assets/rails.png)+ +* +asset-path("rails.png", image)+ becomes +"/assets/rails.png"+ h5. JavaScript/CoffeeScript and ERB -- cgit v1.2.3 From ea29968bcfa455d9bef8c41436b6bea669dfc06d Mon Sep 17 00:00:00 2001 From: Jan Vlnas Date: Sun, 18 Sep 2011 16:41:21 +0300 Subject: Locale code for Czech is ":cs" --- railties/guides/source/i18n.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index a35cd6c506..14ce6a19d5 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -91,7 +91,7 @@ This means, that in the +:en+ locale, the key _hello_ will map to the _Hello wor The I18n library will use *English* as a *default locale*, i.e. if you don't set a different locale, +:en+ will be used for looking up translations. -NOTE: The i18n library takes a *pragmatic approach* to locale keys (after "some discussion":http://groups.google.com/group/rails-i18n/browse_thread/thread/14dede2c7dbe9470/80eec34395f64f3c?hl=en), including only the _locale_ ("language") part, like +:en+, +:pl+, not the _region_ part, like +:en-US+ or +:en-UK+, which are traditionally used for separating "languages" and "regional setting" or "dialects". Many international applications use only the "language" element of a locale such as +:cz+, +:th+ or +:es+ (for Czech, Thai and Spanish). However, there are also regional differences within different language groups that may be important. For instance, in the +:en-US+ locale you would have $ as a currency symbol, while in +:en-UK+, you would have £. Nothing stops you from separating regional and other settings in this way: you just have to provide full "English - United Kingdom" locale in a +:en-UK+ dictionary. Various "Rails I18n plugins":http://rails-i18n.org/wiki such as "Globalize2":https://github.com/joshmh/globalize2/tree/master may help you implement it. +NOTE: The i18n library takes a *pragmatic approach* to locale keys (after "some discussion":http://groups.google.com/group/rails-i18n/browse_thread/thread/14dede2c7dbe9470/80eec34395f64f3c?hl=en), including only the _locale_ ("language") part, like +:en+, +:pl+, not the _region_ part, like +:en-US+ or +:en-UK+, which are traditionally used for separating "languages" and "regional setting" or "dialects". Many international applications use only the "language" element of a locale such as +:cs+, +:th+ or +:es+ (for Czech, Thai and Spanish). However, there are also regional differences within different language groups that may be important. For instance, in the +:en-US+ locale you would have $ as a currency symbol, while in +:en-UK+, you would have £. Nothing stops you from separating regional and other settings in this way: you just have to provide full "English - United Kingdom" locale in a +:en-UK+ dictionary. Various "Rails I18n plugins":http://rails-i18n.org/wiki such as "Globalize2":https://github.com/joshmh/globalize2/tree/master may help you implement it. The *translations load path* (+I18n.load_path+) is just a Ruby Array of paths to your translation files that will be loaded automatically and available in your application. You can pick whatever directory and translation file naming scheme makes sense for you. -- cgit v1.2.3 From 7ed97bc8149f745317a897304c8c86f0e3bba4d2 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 20 Sep 2011 19:33:01 +0530 Subject: remove unnecessary markup --- .../guides/source/active_support_core_extensions.textile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index b3d8760a73..e81fe13010 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -3387,9 +3387,9 @@ Time.zone_default # In Barcelona, 2010/03/28 02:00 0100 becomes 2010/03/28 03:00 0200 due to DST. t = Time.local_time(2010, 3, 28, 1, 59, 59) -# => Sun Mar 28 01:59:59 0100 2010 +# => Sun Mar 28 01:59:59 +0100 2010 t.advance(:seconds => 1) -# => Sun Mar 28 03:00:00 0200 2010 +# => Sun Mar 28 03:00:00 +0200 2010 * If +since+ or +ago+ jump to a time that can't be expressed with +Time+ a +DateTime+ object is returned instead. @@ -3406,7 +3406,7 @@ The method +all_day+ returns a range representing the whole day of the current t now = Time.current -# => Mon, 09 Aug 2010 23:20:05 UTC 00:00 +# => Mon, 09 Aug 2010 23:20:05 UTC +00:00 now.all_day # => Mon, 09 Aug 2010 00:00:00 UTC 00:00..Mon, 09 Aug 2010 23:59:59 UTC 00:00 @@ -3415,7 +3415,7 @@ Analogously, +all_week+, +all_month+, +all_quarter+ and +all_year+ all serve the now = Time.current -# => Mon, 09 Aug 2010 23:20:05 UTC 00:00 +# => Mon, 09 Aug 2010 23:20:05 UTC +00:00 now.all_week # => Mon, 09 Aug 2010 00:00:00 UTC 00:00..Sun, 15 Aug 2010 23:59:59 UTC 00:00 now.all_month @@ -3434,7 +3434,7 @@ Active Support defines +Time.current+ to be +Time.zone.now+ if there's a user ti Time.zone_default # => # Time.current -# => Fri, 06 Aug 2010 17:11:58 CEST 02:00 +# => Fri, 06 Aug 2010 17:11:58 CEST +02:00 Analogously to +DateTime+, the predicates +past?+, and +future?+ are relative to +Time.current+. @@ -3445,7 +3445,7 @@ Use the +local_time+ class method to create time objects honoring the user time Time.zone_default # => # Time.local_time(2010, 8, 15) -# => Sun Aug 15 00:00:00 0200 2010 +# => Sun Aug 15 00:00:00 +0200 2010 The +utc_time+ class method returns a time in UTC: -- cgit v1.2.3 From 5684ecf74966d81e6fa7193689881b5243cbbc39 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 20 Sep 2011 19:47:33 +0530 Subject: copy edits 302e5707 --- railties/guides/source/i18n.textile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index 14ce6a19d5..11e1473ba2 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -365,14 +365,13 @@ NOTE: You need to restart the server when you add new locale files. You may use YAML (+.yml+) or plain Ruby (+.rb+) files for storing your translations in SimpleStore. YAML is the preferred option among Rails developers. However, it has one big disadvantage. YAML is very sensitive to whitespace and special characters, so the application may not load your dictionary properly. Ruby files will crash your application on first request, so you may easily find what's wrong. (If you encounter any "weird issues" with YAML dictionaries, try putting the relevant portion of your dictionary into a Ruby file.) -h4. Passing variables into the translation +h4. Passing variables to translations -You may use translation with parameters, if you want. +You can use variables in the translation messages and pass their values from the view. # app/views/home/index.html.erb -

      <%=t 'greet_username', :user => "Bill", :message => "Goodbye" %>

      -

      <%=t 'greet_username', :user => "DHH", :message => "Hello" %>

      +<%=t 'greet_username', :user => "Bill", :message => "Goodbye" %> # config/locales/en.yml en: -- cgit v1.2.3 From 952bccd1abe142c214605897a14682ae29a16adc Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Wed, 21 Sep 2011 01:23:58 -0700 Subject: add "the" to mirror the structure of the other two points --- railties/README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/README.rdoc b/railties/README.rdoc index 501541eb06..95c43045b0 100644 --- a/railties/README.rdoc +++ b/railties/README.rdoc @@ -6,7 +6,7 @@ Railties is responsible for gluing all frameworks together. Overall, it: * manages the +rails+ command line interface; -* and provides Rails generators core. +* and provides the Rails generators core. == Download -- cgit v1.2.3 From 564d7edf690ab60e439df7d7dfebc5144d8d1867 Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Wed, 21 Sep 2011 01:28:59 -0700 Subject: add a '.' to etc --- railties/guides/source/i18n.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index 11e1473ba2..81d2ba9a56 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -12,7 +12,7 @@ So, in the process of _internationalizing_ your Rails application you have to: In the process of _localizing_ your application you'll probably want to do the following three things: -* Replace or supplement Rails' default locale -- e.g. date and time formats, month names, Active Record model names, etc +* Replace or supplement Rails' default locale -- e.g. date and time formats, month names, Active Record model names, etc. * Abstract strings in your application into keyed dictionaries -- e.g. flash messages, static text in your views, etc. * Store the resulting dictionaries somewhere -- cgit v1.2.3 From 3c5340ec9cbf12d19e734289ba748186af492d60 Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Wed, 21 Sep 2011 02:10:07 -0700 Subject: add a missing "on" and remove the "endprologue" text --- railties/guides/source/i18n.textile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index 81d2ba9a56..46f6942d02 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -16,9 +16,7 @@ In the process of _localizing_ your application you'll probably want to do the f * Abstract strings in your application into keyed dictionaries -- e.g. flash messages, static text in your views, etc. * Store the resulting dictionaries somewhere -This guide will walk you through the I18n API and contains a tutorial how to internationalize a Rails application from the start. - -endprologue. +This guide will walk you through the I18n API and contains a tutorial on how to internationalize a Rails application from the start. NOTE: The Ruby I18n framework provides you with all necessary means for internationalization/localization of your Rails application. You may, however, use any of various plugins and extensions available, which add additional functionality or features. See the Rails "I18n Wiki":http://rails-i18n.org/wiki for more information. -- cgit v1.2.3 From 8d7aee71738fbf1ff090ff44a09624e592b94b04 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 21 Sep 2011 02:19:44 +0530 Subject: indentation fixes --- railties/guides/source/active_support_core_extensions.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index e81fe13010..5aee001545 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -3518,8 +3518,8 @@ h4. +around_[level]+ Takes two arguments, a +before_message+ and +after_message+ and calls the current level method on the +Logger+ instance, passing in the +before_message+, then the specified message, then the +after_message+: - logger = Logger.new("log/development.log") - logger.around_info("before", "after") { |logger| logger.info("during") } +logger = Logger.new("log/development.log") +logger.around_info("before", "after") { |logger| logger.info("during") } h4. +silence+ -- cgit v1.2.3 From 3e80462b95808457eb1584195909e26887a1a40d Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 21 Sep 2011 19:28:36 +0530 Subject: Revert "add a missing "on" and remove the "endprologue" text" This reverts commit 3c5340ec9cbf12d19e734289ba748186af492d60. Reason: endprologue should not have been removed. --- railties/guides/source/i18n.textile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index 46f6942d02..81d2ba9a56 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -16,7 +16,9 @@ In the process of _localizing_ your application you'll probably want to do the f * Abstract strings in your application into keyed dictionaries -- e.g. flash messages, static text in your views, etc. * Store the resulting dictionaries somewhere -This guide will walk you through the I18n API and contains a tutorial on how to internationalize a Rails application from the start. +This guide will walk you through the I18n API and contains a tutorial how to internationalize a Rails application from the start. + +endprologue. NOTE: The Ruby I18n framework provides you with all necessary means for internationalization/localization of your Rails application. You may, however, use any of various plugins and extensions available, which add additional functionality or features. See the Rails "I18n Wiki":http://rails-i18n.org/wiki for more information. -- cgit v1.2.3 From 007f56701102647088673d92b165c3d862fbba22 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 21 Sep 2011 20:51:30 -0300 Subject: Add jquery-rails to Gemfile of plugins, test/dummy app uses it. Closes #3091 --- railties/lib/rails/generators/rails/plugin_new/templates/Gemfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile index 160baa6906..f4efd3af74 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile +++ b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile @@ -5,6 +5,9 @@ source "http://rubygems.org" # development dependencies will be added by default to the :development group. gemspec +# jquery-rails is used by the dummy application +gem "jquery-rails" + # Declare any dependencies that are still in development here instead of in # your gemspec. These might include edge Rails or gems from your path or # Git. Remember to move these dependencies to your gemspec before releasing @@ -17,4 +20,4 @@ gemspec <% end -%> # To use debugger -# <%= ruby_debugger_gemfile_entry %> \ No newline at end of file +# <%= ruby_debugger_gemfile_entry %> -- cgit v1.2.3 From efb8a7a7b928c8075a20ea46d9ac657ef56a7faa Mon Sep 17 00:00:00 2001 From: Christopher Arrowsmith Date: Thu, 22 Sep 2011 01:18:22 +0100 Subject: Changed "en-UK" to "en-GB" Signed-off-by: Christopher Arrowsmith --- railties/guides/source/i18n.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index 81d2ba9a56..45a069b0a3 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -91,7 +91,7 @@ This means, that in the +:en+ locale, the key _hello_ will map to the _Hello wor The I18n library will use *English* as a *default locale*, i.e. if you don't set a different locale, +:en+ will be used for looking up translations. -NOTE: The i18n library takes a *pragmatic approach* to locale keys (after "some discussion":http://groups.google.com/group/rails-i18n/browse_thread/thread/14dede2c7dbe9470/80eec34395f64f3c?hl=en), including only the _locale_ ("language") part, like +:en+, +:pl+, not the _region_ part, like +:en-US+ or +:en-UK+, which are traditionally used for separating "languages" and "regional setting" or "dialects". Many international applications use only the "language" element of a locale such as +:cs+, +:th+ or +:es+ (for Czech, Thai and Spanish). However, there are also regional differences within different language groups that may be important. For instance, in the +:en-US+ locale you would have $ as a currency symbol, while in +:en-UK+, you would have £. Nothing stops you from separating regional and other settings in this way: you just have to provide full "English - United Kingdom" locale in a +:en-UK+ dictionary. Various "Rails I18n plugins":http://rails-i18n.org/wiki such as "Globalize2":https://github.com/joshmh/globalize2/tree/master may help you implement it. +NOTE: The i18n library takes a *pragmatic approach* to locale keys (after "some discussion":http://groups.google.com/group/rails-i18n/browse_thread/thread/14dede2c7dbe9470/80eec34395f64f3c?hl=en), including only the _locale_ ("language") part, like +:en+, +:pl+, not the _region_ part, like +:en-US+ or +:en-GB+, which are traditionally used for separating "languages" and "regional setting" or "dialects". Many international applications use only the "language" element of a locale such as +:cs+, +:th+ or +:es+ (for Czech, Thai and Spanish). However, there are also regional differences within different language groups that may be important. For instance, in the +:en-US+ locale you would have $ as a currency symbol, while in +:en-GB+, you would have £. Nothing stops you from separating regional and other settings in this way: you just have to provide full "English - United Kingdom" locale in a +:en-GB+ dictionary. Various "Rails I18n plugins":http://rails-i18n.org/wiki such as "Globalize2":https://github.com/joshmh/globalize2/tree/master may help you implement it. The *translations load path* (+I18n.load_path+) is just a Ruby Array of paths to your translation files that will be loaded automatically and available in your application. You can pick whatever directory and translation file naming scheme makes sense for you. -- cgit v1.2.3 From 9d46823b5d00e78c6ffaaae731a9a7acf6bb2b14 Mon Sep 17 00:00:00 2001 From: Terence Lee Date: Thu, 22 Sep 2011 12:03:59 -0500 Subject: set env to let rails know we're precompiling --- railties/test/application/assets_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index a62ef1e70e..c4a24f0f73 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -102,6 +102,15 @@ module ApplicationTests assert !File.exists?("#{app_path}/public/assets/something.min.css") end + test "precompile sets flag notifying rails its precompiling" do + compile = < Date: Fri, 23 Sep 2011 00:25:37 -0700 Subject: pluralize "locales" since that's what's used in other parts of the document, and add a missing "on" --- railties/guides/source/i18n.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index 45a069b0a3..2d4cc13571 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -8,7 +8,7 @@ So, in the process of _internationalizing_ your Rails application you have to: * Ensure you have support for i18n * Tell Rails where to find locale dictionaries -* Tell Rails how to set, preserve and switch locale +* Tell Rails how to set, preserve and switch locales In the process of _localizing_ your application you'll probably want to do the following three things: @@ -16,7 +16,7 @@ In the process of _localizing_ your application you'll probably want to do the f * Abstract strings in your application into keyed dictionaries -- e.g. flash messages, static text in your views, etc. * Store the resulting dictionaries somewhere -This guide will walk you through the I18n API and contains a tutorial how to internationalize a Rails application from the start. +This guide will walk you through the I18n API and contains a tutorial on how to internationalize a Rails application from the start. endprologue. -- cgit v1.2.3 From eb367afeed2905d1036f46940aa6c91323f7faab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 24 Sep 2011 01:56:49 +0200 Subject: `rake assets:precompile` loads the application but does not initialize it. To the app developer, this means configuration add in config/initializers/* will not be executed. Plugins developers need to special case their initializers that are meant to be run in the assets group by adding :group => :assets. Conflicts: railties/CHANGELOG railties/test/application/assets_test.rb --- railties/CHANGELOG | 12 +++ railties/lib/rails/application.rb | 5 +- railties/lib/rails/application/bootstrap.rb | 16 ++-- railties/lib/rails/engine.rb | 4 +- railties/lib/rails/initializable.rb | 8 +- railties/test/application/assets_test.rb | 110 ++++++++++++++++++---------- railties/test/initializable_test.rb | 2 +- railties/test/isolation/abstract_unit.rb | 9 +++ 8 files changed, 112 insertions(+), 54 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 72e5921d6d..54eef0473c 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -10,6 +10,18 @@ * Removed old 'config.paths.app.controller' API in favor of 'config.paths["app/controller"]' API. [Guillermo Iguaran] + +*Rails 3.1.1 + +* `rake assets:precompile` loads the application but does not initialize it. + + To the app developer, this means configuration add in + config/initializers/* will not be executed. + + Plugins developers need to special case their initializers that are + meant to be run in the assets group by adding :group => :assets. + + *Rails 3.1.0 (August 30, 2011)* * The default database schema file is written as UTF-8. [Aaron Patterson] diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 528c96ef3e..90d7d27af1 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -83,7 +83,6 @@ module Rails require environment if environment end - def reload_routes! routes_reloader.reload! end @@ -92,9 +91,9 @@ module Rails @routes_reloader ||= RoutesReloader.new end - def initialize! + def initialize!(group=nil) raise "Application has been already initialized." if @initialized - run_initializers(self) + run_initializers(group, self) @initialized = true self end diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index c9b147d075..0aff05b681 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -7,21 +7,21 @@ module Rails module Bootstrap include Initializable - initializer :load_environment_hook do end + initializer :load_environment_hook, :group => :all do end - initializer :load_active_support do + initializer :load_active_support, :group => :all do require "active_support/all" unless config.active_support.bare end # Preload all frameworks specified by the Configuration#frameworks. # Used by Passenger to ensure everything's loaded before forking and # to avoid autoload race conditions in JRuby. - initializer :preload_frameworks do + initializer :preload_frameworks, :group => :all do ActiveSupport::Autoload.eager_autoload! if config.preload_frameworks end # Initialize the logger early in the stack in case we need to log some deprecation. - initializer :initialize_logger do + initializer :initialize_logger, :group => :all do Rails.logger ||= config.logger || begin path = config.paths["log"].first logger = ActiveSupport::BufferedLogger.new(path) @@ -41,7 +41,7 @@ module Rails end # Initialize cache early in the stack so railties can make use of it. - initializer :initialize_cache do + initializer :initialize_cache, :group => :all do unless defined?(RAILS_CACHE) silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(config.cache_store) } @@ -51,7 +51,7 @@ module Rails end end - initializer :set_clear_dependencies_hook do + initializer :set_clear_dependencies_hook, :group => :all do ActionDispatch::Reloader.to_cleanup do ActiveSupport::DescendantsTracker.clear ActiveSupport::Dependencies.clear @@ -60,11 +60,11 @@ module Rails # Sets the dependency loading mechanism. # TODO: Remove files from the $" and always use require. - initializer :initialize_dependency_mechanism do + initializer :initialize_dependency_mechanism, :group => :all do ActiveSupport::Dependencies.mechanism = config.cache_classes ? :require : :load end - initializer :bootstrap_hook do |app| + initializer :bootstrap_hook, :group => :all do |app| ActiveSupport.run_load_hooks(:before_initialize, app) end end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 89b151beb6..0e1e719596 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -537,12 +537,12 @@ module Rails end end - initializer :load_environment_config, :before => :load_environment_hook do + initializer :load_environment_config, :before => :load_environment_hook, :group => :all do environment = paths["config/environments"].existent.first require environment if environment end - initializer :append_assets_path do |app| + initializer :append_assets_path, :group => :assets do |app| app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories) app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories) app.config.assets.paths.unshift(*paths["app/assets"].existent_directories) diff --git a/railties/lib/rails/initializable.rb b/railties/lib/rails/initializable.rb index 686a2dc0cb..4c1da0a5a5 100644 --- a/railties/lib/rails/initializable.rb +++ b/railties/lib/rails/initializable.rb @@ -21,6 +21,10 @@ module Rails @options[:after] end + def belongs_to?(group) + @options[:group] == group || @options[:group] == :all + end + def run(*args) @context.instance_exec(*args, &block) end @@ -44,10 +48,10 @@ module Rails end end - def run_initializers(*args) + def run_initializers(group=nil, *args) return if instance_variable_defined?(:@ran) initializers.tsort.each do |initializer| - initializer.run(*args) + initializer.run(*args) if group.nil? || initializer.belongs_to?(group) end @ran = true end diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index c4a24f0f73..fb570d8f47 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -21,6 +21,12 @@ module ApplicationTests @app ||= Rails.application end + def precompile! + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + end + test "assets routes have higher priority" do app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();" @@ -38,7 +44,7 @@ module ApplicationTests test "assets do not require compressors until it is used" do app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();" - app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = true" + add_to_env_config "production", "config.assets.compile = true" ENV["RAILS_ENV"] = "production" require "#{app_path}/config/environment" @@ -54,9 +60,8 @@ module ApplicationTests app_file "app/assets/javascripts/foo/application.js", "alert();" ENV["RAILS_ENV"] = nil - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! + files = Dir["#{app_path}/public/assets/application-*.js"] files << Dir["#{app_path}/public/assets/foo/application-*.js"].first files.each do |file| @@ -80,13 +85,12 @@ module ApplicationTests "happy.happy.face.png", "happy", "happy.face", "-happyface", "-happy.png", "-happy.face.png", "_happyface", "_happy.face.png", "_happy.png"] + images_should_compile.each do |filename| app_file "app/assets/images/#{filename}", "happy" end - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! images_should_compile.each do |filename| assert File.exists?("#{app_path}/public/assets/#{filename}") @@ -103,11 +107,12 @@ module ApplicationTests end test "precompile sets flag notifying rails its precompiling" do - compile = < :assets do + raise "ENV RAILS_ASSETS_PRECOMPILE not set" unless ENV["RAILS_ASSETS_PRECOMPILE"] + end + RUBY + precompile! assert $?.success? end @@ -127,9 +132,7 @@ COMPILE # digest is default in false, we must enable it for test environment add_to_config "config.assets.digest = true" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! manifest = "#{app_path}/public/assets/manifest.yml" @@ -146,9 +149,7 @@ COMPILE add_to_config "config.assets.manifest = '#{app_path}/shared'" FileUtils.mkdir "#{app_path}/shared" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! manifest = "#{app_path}/shared/manifest.yml" @@ -164,9 +165,7 @@ COMPILE add_to_config "config.assets.digest = true" add_to_config "config.assets.prefix = '/x'" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! manifest = "#{app_path}/public/x/manifest.yml" assets = YAML.load_file(manifest) @@ -178,9 +177,7 @@ COMPILE app_file "app/assets/javascripts/application.js", "alert();" add_to_config "config.assets.digest = false" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! assert File.exists?("#{app_path}/public/assets/application.js") assert File.exists?("#{app_path}/public/assets/application.css") @@ -194,12 +191,11 @@ COMPILE test "assets do not require any assets group gem when manifest file is present" do app_file "app/assets/javascripts/application.js", "alert();" - app_file "config/initializers/serve_static_assets.rb", "Rails.application.config.serve_static_assets = true" + add_to_env_config "production", "config.serve_static_assets = true" ENV["RAILS_ENV"] = "production" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! + manifest = "#{app_path}/public/assets/manifest.yml" assets = YAML.load_file(manifest) asset_path = assets["application.js"] @@ -223,9 +219,7 @@ COMPILE RUBY ENV["RAILS_ENV"] = "production" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! # Create file after of precompile app_file "app/assets/javascripts/app.js", "alert();" @@ -249,9 +243,7 @@ COMPILE RUBY ENV["RAILS_ENV"] = "development" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! # Create file after of precompile app_file "app/assets/javascripts/app.js", "alert();" @@ -292,10 +284,7 @@ COMPILE app_file "app/assets/images/レイルズ.png", "not a image really" add_to_config "config.assets.precompile = [ /\.png$$/, /application.(css|js)$/ ]" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end - + precompile! assert File.exists?("#{app_path}/public/assets/レイルズ.png") manifest = "#{app_path}/public/assets/manifest.yml" @@ -367,5 +356,50 @@ COMPILE assert_match "alert();", last_response.body assert_equal 200, last_response.status end + + test "assets are concatenated when debug is off and compile is off either if debug_assets param is provided" do + app_with_assets_in_view + + # config.assets.debug and config.assets.compile are false for production environment + ENV["RAILS_ENV"] = "production" + precompile! + + require "#{app_path}/config/environment" + + class ::PostsController < ActionController::Base ; end + + # the debug_assets params isn't used if compile is off + get '/posts?debug_assets=true' + assert_match(/ - - + + + The +body+ param is required by Sprockets. h4. Turning Debugging off -You can turn off debug mode by updating +development.rb+ to include: +You can turn off debug mode by updating +config/environments/development.rb+ to include: - + config.assets.debug = false - +
      -When debug mode is off Sprockets will concatenate and run the necessary preprocessors on all files, generating the following HTML: +When debug mode is off Sprockets concatenates and runs the necessary preprocessors on all files. With debug mode turned off the manifest above would generate instead: - + -Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-revalidate+ Cache-Control HTTP header to reduce request overhead on subsequent requests -- on these the browser gets a 304 (not-modified) response. +Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-revalidate+ Cache-Control HTTP header to reduce request overhead on subsequent requests -- on these the browser gets a 304 (Not Modified) response. If any of the files in the manifest have changed between requests, the server responds with a new compiled file. -You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL to enable debug mode on-demand, and this will render individual tags for each file. This is useful for tracking down exact line numbers when debugging. - -Debug can also be set in the Rails helper methods: +Debug mode can also be enabled in the Rails helper methods: <%= stylesheet_link_tag "application", :debug => true %> <%= javascript_include_tag "application", :debug => true %> -The +:debug+ option is ignored if the debug mode is off. +The +:debug+ option is redundant if debug mode is on. You could potentially also enable compression in development mode as a sanity check, and disable it on-demand as required for debugging. - h3. In Production In the production environment Rails uses the fingerprinting scheme outlined above. By default it is assumed that assets have been precompiled and will be served as static assets by your web server. -- cgit v1.2.3 From 148e4a541361f140f13aa35bb43b3d57c95831d6 Mon Sep 17 00:00:00 2001 From: Dmitriy Kiriyenko Date: Thu, 29 Sep 2011 15:35:25 +0300 Subject: Honour RAILS_ENV environment variable when running rake. --- railties/lib/rails/generators/actions.rb | 2 +- railties/test/generators/actions_test.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index 575f4bb106..5af5d3b856 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -252,7 +252,7 @@ module Rails # def rake(command, options={}) log :rake, command - env = options[:env] || 'development' + env = options[:env] || ENV["RAILS_ENV"] || 'development' sudo = options[:sudo] && RbConfig::CONFIG['host_os'] !~ /mswin|mingw/ ? 'sudo ' : '' in_root { run("#{sudo}#{extify(:rake)} #{command} RAILS_ENV=#{env}", :verbose => false) } end diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 94e9abb3cc..e621f7f6f7 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -189,6 +189,22 @@ class ActionsTest < Rails::Generators::TestCase action :rake, 'log:clear', :env => 'production' end + def test_rake_with_rails_env_variable_should_run_rake_command_in_env + generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', :verbose => false) + old_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "production" + action :rake, 'log:clear' + ensure + ENV["RAILS_ENV"] = old_env + end + + def test_env_option_should_win_over_rails_env_variable_when_running_rake + generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', :verbose => false) + old_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "staging" + action :rake, 'log:clear', :env => 'production' + ensure + ENV["RAILS_ENV"] = old_env + end + def test_rake_with_sudo_option_should_run_rake_command_with_sudo generator.expects(:run).once.with('sudo rake log:clear RAILS_ENV=development', :verbose => false) action :rake, 'log:clear', :sudo => true -- cgit v1.2.3 From d2888de5985c7018a5be23d44143ec3c6cef9032 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 29 Sep 2011 16:07:59 -0300 Subject: Add CHANGELOG entries --- railties/CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 54eef0473c..992519ee92 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -13,6 +13,8 @@ *Rails 3.1.1 +* Add jquery-rails to Gemfile of plugins, test/dummy app needs it. Closes #3091. [Santiago Pastorino] + * `rake assets:precompile` loads the application but does not initialize it. To the app developer, this means configuration add in -- cgit v1.2.3 From e81c427fe8a5bba8e5c8dd4b2a57c5e20b1c5fd0 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Fri, 30 Sep 2011 14:12:43 +0530 Subject: possibly useless use of :: in void context Warning removed --- railties/test/application/configuration_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 448982f9de..97ad47ac14 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -306,7 +306,7 @@ module ApplicationTests require "#{app_path}/config/environment" require "mail" - ActionMailer::Base + _ = ActionMailer::Base assert_equal [::MyMailInterceptor], ::Mail.send(:class_variable_get, "@@delivery_interceptors") end @@ -319,7 +319,7 @@ module ApplicationTests require "#{app_path}/config/environment" require "mail" - ActionMailer::Base + _ = ActionMailer::Base assert_equal [::MyMailInterceptor, ::MyOtherMailInterceptor], ::Mail.send(:class_variable_get, "@@delivery_interceptors") end @@ -332,7 +332,7 @@ module ApplicationTests require "#{app_path}/config/environment" require "mail" - ActionMailer::Base + _ = ActionMailer::Base assert_equal [::MyMailObserver], ::Mail.send(:class_variable_get, "@@delivery_notification_observers") end @@ -345,7 +345,7 @@ module ApplicationTests require "#{app_path}/config/environment" require "mail" - ActionMailer::Base + _ = ActionMailer::Base assert_equal [::MyMailObserver, ::MyOtherMailObserver], ::Mail.send(:class_variable_get, "@@delivery_notification_observers") end -- cgit v1.2.3 From b0b436ebcea8206015b3f52bb5915a7bba7cc5a9 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Fri, 30 Sep 2011 15:56:38 +0530 Subject: warning removed : '&' interpreted as argument prefix --- railties/lib/rails/generators/actions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index 5af5d3b856..b26839644e 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -90,7 +90,7 @@ module Rails append_file "Gemfile", "\ngroup #{name} do\n", :force => true @in_group = true - instance_eval &block + instance_eval(&block) @in_group = false append_file "Gemfile", "end\n", :force => true -- cgit v1.2.3 From 44791a2bc6611b755b418f1db3ca93f9edec0908 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Fri, 30 Sep 2011 12:05:53 -0400 Subject: Modified how to handle if ActiveRecord is defined. --- railties/lib/rails/test_help.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 68f566274d..8d0d8cacac 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -24,7 +24,7 @@ if defined?(MiniTest) end end -if defined?(ActiveRecord) +if defined?(ActiveRecord::Base) require 'active_record/test_case' class ActiveSupport::TestCase -- cgit v1.2.3 From 409268edfc3aa1e2df1cd0cb5acb720ce98ace89 Mon Sep 17 00:00:00 2001 From: Manuel Menezes de Sequeira Date: Fri, 30 Sep 2011 23:28:51 +0100 Subject: Small typo corrected. --- railties/guides/source/getting_started.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 33f383f173..23d55e6bba 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -360,7 +360,7 @@ development: h5. Configuring an SQLite3 Database for JRuby Platform -If you choose to use SQLite3 and using JRuby, your +config/database.yml+ will +If you choose to use SQLite3 and are using JRuby, your +config/database.yml+ will look a little different. Here's the development section: @@ -371,7 +371,7 @@ development: h5. Configuring a MySQL Database for JRuby Platform -If you choose to use MySQL and using JRuby, your +config/database.yml+ will look +If you choose to use MySQL and are using JRuby, your +config/database.yml+ will look a little different. Here's the development section: @@ -384,7 +384,7 @@ development: h5. Configuring a PostgreSQL Database for JRuby Platform -Finally if you choose to use PostgreSQL and using JRuby, your +Finally if you choose to use PostgreSQL and are using JRuby, your +config/database.yml+ will look a little different. Here's the development section: -- cgit v1.2.3 From 059c04d4dd20412e63e691277069b456fc8951ab Mon Sep 17 00:00:00 2001 From: Manuel Menezes de Sequeira Date: Sat, 1 Oct 2011 11:39:00 +0100 Subject: Several small corrections and clarifications. --- railties/guides/source/getting_started.textile | 60 +++++++++++++------------- 1 file changed, 31 insertions(+), 29 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 23d55e6bba..7f0a3d376e 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -599,7 +599,7 @@ The above migration creates a method named +change+ which will be called when yo run this migration. The action defined in that method is also reversible, which means Rails knows how to reverse the change made by this migration, in case you want to reverse it at later date. By default, when you run this migration it -will creates a +posts+ table with two string columns and a text column. It also +creates a +posts+ table with two string columns and a text column. It also creates two timestamp fields to track record creation and updating. More information about Rails migrations can be found in the "Rails Database Migrations":migrations.html guide. @@ -620,9 +620,9 @@ table. == CreatePosts: migrated (0.0020s) =========================================== -NOTE. Because you're working in the development environment by default, this +NOTE. Because by default you're working in the development environment, this command will apply to the database defined in the +development+ section of your -+config/database.yml+ file. If you would like to execute migrations in other ++config/database.yml+ file. If you would like to execute migrations in another environment, for instance in production, you must explicitly pass it when invoking the command: rake db:migrate RAILS_ENV=production. @@ -704,8 +704,8 @@ $ rails console TIP: The default console will make changes to your database. You can instead -open a console that will roll back any changes you make by using +rails console ---sandbox+. +open a console that will roll back any changes you make by using rails console +--sandbox . After the console loads, you can use it to work with your application's models: @@ -783,7 +783,8 @@ Here's +app/views/posts/index.html.erb+: <%= post.content %> <%= link_to 'Show', post %> <%= link_to 'Edit', edit_post_path(post) %> - <%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %> + <%= link_to 'Destroy', post, :confirm => 'Are you sure?', + :method => :delete %> <% end %> @@ -867,10 +868,10 @@ The +new.html.erb+ view displays this empty Post to the user: The +<%= render 'form' %>+ line is our first introduction to _partials_ in Rails. A partial is a snippet of HTML and Ruby code that can be reused in -multiple locations. In this case, the form used to make a new post, is basically -identical to a form used to edit a post, both have text fields for the name and -title and a text area for the content with a button to make a new post or update -the existing post. +multiple locations. In this case, the form used to make a new post is basically +identical to the form used to edit a post, both having text fields for the name and +title, a text area for the content, and a button to create the new post or to update +the existing one. If you take a look at +views/posts/_form.html.erb+ file, you will see the following: @@ -879,7 +880,8 @@ following: <%= form_for(@post) do |f| %> <% if @post.errors.any? %>
      -

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

      +

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

        <% @post.errors.full_messages.each do |msg| %>
      • <%= msg %>
      • @@ -907,15 +909,15 @@ following: This partial receives all the instance variables defined in the calling view -file, so in this case, the controller assigned the new Post object to +@post+ -and so, this is available in both the view and partial as +@post+. +file. In this case, the controller assigned the new +Post+ object to +@post+, +which will thus be available in both the view and the partial as +@post+. For more information on partials, refer to the "Layouts and Rendering in Rails":layouts_and_rendering.html#using-partials guide. The +form_for+ block is used to create an HTML form. Within this block, you have access to methods to build various controls on the form. For example, -+f.text_field :name+ tells Rails to create a text input on the form, and to hook ++f.text_field :name+ tells Rails to create a text input on the form and to hook it up to the +name+ attribute of the instance being displayed. You can only use these methods with attributes of the model that the form is based on (in this case +name+, +title+, and +content+). Rails uses +form_for+ in preference to @@ -931,9 +933,9 @@ to a model, you should use the +form_tag+ method, which provides shortcuts for building forms that are not necessarily tied to a model instance. When the user clicks the +Create Post+ button on this form, the browser will -send information back to the +create+ method of the controller (Rails knows to -call the +create+ method because the form is sent with an HTTP POST request; -that's one of the conventions that I mentioned earlier): +send information back to the +create+ action of the controller (Rails knows to +call the +create+ action because the form is sent with an HTTP POST request; +that's one of the conventions that were mentioned earlier): def create @@ -965,12 +967,12 @@ If the post was not successfully saved, due to a validation error, then the controller returns the user back to the +new+ action with any error messages so that the user has the chance to fix the error and try again. -The "Post was successfully created." message is stored inside of the Rails -+flash+ hash, (usually just called _the flash_) so that messages can be carried +The "Post was successfully created." message is stored in the Rails ++flash+ hash (usually just called _the flash_), so that messages can be carried over to another action, providing the user with useful information on the status of their request. In the case of +create+, the user never actually sees any page -rendered during the Post creation process, because it immediately redirects to -the new Post as soon Rails saves the record. The Flash carries over a message to +rendered during the post creation process, because it immediately redirects to +the new +Post+ as soon as Rails saves the record. The Flash carries over a message to the next action, so that when the user is redirected back to the +show+ action, they are presented with a message saying "Post was successfully created." @@ -1043,9 +1045,9 @@ it: <%= link_to 'Back', posts_path %> -Again, as with the +new+ action, the +edit+ action is using the +form+ partial, -this time however, the form will do a PUT action to the PostsController and the -submit button will display "Update Post" +Again, as with the +new+ action, the +edit+ action is using the +form+ partial. +This time, however, the form will do a PUT action to the +PostsController+ and the +submit button will display "Update Post". Submitting the form created by this view will invoke the +update+ action within the controller: @@ -1070,9 +1072,9 @@ end In the +update+ action, Rails first uses the +:id+ parameter passed back from the edit view to locate the database record that's being edited. The -+update_attributes+ call then takes the rest of the parameters from the request -and applies them to this record. If all goes well, the user is redirected to the -post's +show+ view. If there are any problems, it's back to the +edit+ view to ++update_attributes+ call then takes the +post+ parameter (a hash) from the request +and applies it to this record. If all goes well, the user is redirected to the +post's +show+ action. If there are any problems, it's back to the +edit+ action to correct them. h4. Destroying a Post @@ -1094,8 +1096,8 @@ end The +destroy+ method of an Active Record model instance removes the corresponding record from the database. After that's done, there isn't any -record to display, so Rails redirects the user's browser to the index view for -the model. +record to display, so Rails redirects the user's browser to the index action of +the controller. h3. Adding a Second Model -- cgit v1.2.3 From a917c2ba8b669a1644a1df2a0002cb4676388dc7 Mon Sep 17 00:00:00 2001 From: Manuel Menezes de Sequeira Date: Sat, 1 Oct 2011 12:48:34 +0100 Subject: Several other small corrections. --- railties/guides/source/getting_started.textile | 61 +++++++++++++------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 7f0a3d376e..6812b6b9fe 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1109,19 +1109,20 @@ h4. Generating a Model Models in Rails use a singular name, and their corresponding database tables use a plural name. For the model to hold comments, the convention is to use the name -Comment. Even if you don't want to use the entire apparatus set up by ++Comment+. Even if you don't want to use the entire apparatus set up by scaffolding, most Rails developers still use generators to make things like models and controllers. To create the new model, run this command in your terminal: -$ rails generate model Comment commenter:string body:text post:references +$ rails generate model Comment commenter:string body:text \ +> post:references This command will generate four files: -* +app/models/comment.rb+ - The model -* +db/migrate/20100207235629_create_comments.rb+ - The migration +* +app/models/comment.rb+ - The model. +* +db/migrate/20100207235629_create_comments.rb+ - The migration. * +test/unit/comment_test.rb+ and +test/fixtures/comments.yml+ - The test harness. First, take a look at +comment.rb+: @@ -1179,8 +1180,8 @@ Active Record associations let you easily declare the relationship between two models. In the case of comments and posts, you could write out the relationships this way: -* Each comment belongs to one post -* One post can have many comments +* Each comment belongs to one post. +* One post can have many comments. In fact, this is very close to the syntax that Rails uses to declare this association. You've already seen the line of code inside the Comment model that @@ -1206,7 +1207,7 @@ end These two declarations enable a good bit of automatic behavior. For example, if you have an instance variable +@post+ containing a post, you can retrieve all -the comments belonging to that post as the array +@post.comments+. +the comments belonging to that post as an array using +@post.comments+. TIP: For more information on Active Record associations, see the "Active Record Associations":association_basics.html guide. @@ -1215,9 +1216,9 @@ h4. Adding a Route for Comments As with the +home+ controller, we will need to add a route so that Rails knows where we would like to navigate to see +comments+. Open up the -+config/routes.rb+ file again, you will see an entry that was added -automatically for +posts+ near the top by the scaffold generator, +resources -:posts+, edit it as follows: ++config/routes.rb+ file again. Near the top, you will see the entry for +posts+ +that was added automatically by the scaffold generator: resources +:posts. Edit it as follows: resources :posts do @@ -1243,19 +1244,19 @@ $ rails generate controller Comments This creates six files and one empty directory: -* +app/controllers/comments_controller.rb+ - The controller -* +app/helpers/comments_helper.rb+ - A view helper file -* +test/functional/comments_controller_test.rb+ - The functional tests for the controller -* +test/unit/helpers/comments_helper_test.rb+ - The unit tests for the helper -* +app/views/comments/+ - Views of the controller are stored here -* +app/assets/stylesheets/comment.css.scss+ - Cascading style sheet for the controller -* +app/assets/javascripts/comment.js.coffee+ - CoffeeScript for the controller +* +app/controllers/comments_controller.rb+ - The controller. +* +app/helpers/comments_helper.rb+ - A view helper file. +* +test/functional/comments_controller_test.rb+ - The functional tests for the controller. +* +test/unit/helpers/comments_helper_test.rb+ - The unit tests for the helper. +* +app/views/comments/+ - Views of the controller are stored here. +* +app/assets/stylesheets/comment.css.scss+ - Cascading style sheet for the controller. +* +app/assets/javascripts/comment.js.coffee+ - CoffeeScript for the controller. Like with any blog, our readers will create their comments directly after reading the post, and once they have added their comment, will be sent back to the post show page to see their comment now listed. Due to this, our +CommentsController+ is there to provide a method to create comments and delete -SPAM comments when they arrive. +spam comments when they arrive. So first, we'll wire up the Post show template (+/app/views/posts/show.html.erb+) to let us make a new comment: @@ -1297,8 +1298,8 @@ So first, we'll wire up the Post show template <%= link_to 'Back to Posts', posts_path %> | -This adds a form on the Post show page that creates a new comment, which will -call the +CommentsController+ +create+ action, so let's wire that up: +This adds a form on the +Post+ show page that creates a new comment by +calling the +CommentsController+ +create+ action. Let's wire that up: class CommentsController < ApplicationController @@ -1311,9 +1312,9 @@ end You'll see a bit more complexity here than you did in the controller for posts. -That's a side-effect of the nesting that you've set up; each request for a +That's a side-effect of the nesting that you've set up. Each request for a comment has to keep track of the post to which the comment is attached, thus the -initial find action to the Post model to get the post in question. +initial call to the +find+ method of the +Post+ model to get the post in question. In addition, the code takes advantage of some of the methods available for an association. We use the +create+ method on +@post.comments+ to create and save @@ -1383,9 +1384,9 @@ right places. h3. Refactoring -Now that we have Posts and Comments working, if we take a look at the -+app/views/posts/show.html.erb+ template, it's getting long and awkward. We can -use partials to clean this up. +Now that we have posts and comments working, take a look at the ++app/views/posts/show.html.erb+ template. It is getting long and awkward. We can +use partials to clean it up. h4. Rendering Partial Collections @@ -1405,7 +1406,7 @@ following into it:

        -Then in the +app/views/posts/show.html.erb+ you can change it to look like the +Then you can change +app/views/posts/show.html.erb+ to look like the following: @@ -1458,8 +1459,8 @@ comment to a local variable named the same as the partial, in this case h4. Rendering a Partial Form -Let's also move that new comment section out to its own partial. Again, you -create a file +app/views/comments/_form.html.erb+ and in it you put: +Let us also move that new comment section out to its own partial. Again, you +create a file +app/views/comments/_form.html.erb+ containing: <%= form_for([@post, @post.comments.build]) do |f| %> @@ -1510,7 +1511,7 @@ Then you make the +app/views/posts/show.html.erb+ look like the following: The second render just defines the partial template we want to render, -comments/form, Rails is smart enough to spot the forward slash in that +comments/form. Rails is smart enough to spot the forward slash in that string and realize that you want to render the _form.html.erb file in the app/views/comments directory. @@ -1519,7 +1520,7 @@ defined it as an instance variable. h3. Deleting Comments -Another important feature on a blog is being able to delete SPAM comments. To do +Another important feature of a blog is being able to delete SPAM comments. To do this, we need to implement a link of some sort in the view and a +DELETE+ action in the +CommentsController+. -- cgit v1.2.3 From 7039def6e116b12ccab8142cec7f7feabc264220 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sun, 31 Jul 2011 16:17:37 -0500 Subject: Read extra args for 'rails new' from ~/.railsrc --- railties/lib/rails/commands/application.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/commands/application.rb b/railties/lib/rails/commands/application.rb index 1cf23a8b92..dcd4c7a529 100644 --- a/railties/lib/rails/commands/application.rb +++ b/railties/lib/rails/commands/application.rb @@ -9,6 +9,13 @@ if ARGV.first != "new" ARGV[0] = "--help" else ARGV.shift + railsrc = File.join(File.expand_path("~"), ".railsrc") + if File.exist?(railsrc) + extra_args_string = File.open(railsrc).read + extra_args = extra_args_string.split(/\n+/).map {|l| l.split}.flatten + ARGV << extra_args + ARGV.flatten! + end end require 'rubygems' if ARGV.include?("--dev") -- cgit v1.2.3 From 101fb42106db4e7e8221a3fec252e51dd84e0bb4 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sun, 2 Oct 2011 01:06:39 -0500 Subject: Print information about .railsrc to users --- railties/lib/rails/commands/application.rb | 1 + railties/lib/rails/generators/rails/app/USAGE | 6 ++++++ 2 files changed, 7 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/commands/application.rb b/railties/lib/rails/commands/application.rb index dcd4c7a529..60d1aed73a 100644 --- a/railties/lib/rails/commands/application.rb +++ b/railties/lib/rails/commands/application.rb @@ -13,6 +13,7 @@ else if File.exist?(railsrc) extra_args_string = File.open(railsrc).read extra_args = extra_args_string.split(/\n+/).map {|l| l.split}.flatten + puts "Using #{extra_args.join(" ")} from #{railsrc}" ARGV << extra_args ARGV.flatten! end diff --git a/railties/lib/rails/generators/rails/app/USAGE b/railties/lib/rails/generators/rails/app/USAGE index 9e7a78d132..691095f33f 100644 --- a/railties/lib/rails/generators/rails/app/USAGE +++ b/railties/lib/rails/generators/rails/app/USAGE @@ -2,6 +2,12 @@ Description: The 'rails new' command creates a new Rails application with a default directory structure and configuration at the path you specify. + You can specify extra command-line arguments to be used every time + 'rails new' runs in the .railsrc configuration file in your home directory. + + Note that the arguments specified in the .railsrc file don't affect the + defaults values shown above in this help message. + Example: rails new ~/Code/Ruby/weblog -- cgit v1.2.3 From 63f6da050acb1108a3f22c2bd393a8c2c05caeea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 2 Oct 2011 11:17:06 +0200 Subject: Update CHANGELOG. --- railties/CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 992519ee92..160ea0f600 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.2.0 (unreleased)* +* Default options to `rails new` can be set in ~/.railsrc [Guillermo Iguaran] + * Added destroy alias to Rails engines. [Guillermo Iguaran] * Added destroy alias for Rails command line. This allows the following: `rails d model post`. [Andrey Ognevsky] -- cgit v1.2.3 From 753424079e497d8ab7bc611093a34194200e3c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 2 Oct 2011 12:14:31 +0200 Subject: Provide initialize_on_precompile which, when set to false, does not initialize the app for precompilation. Defaults to true. --- railties/CHANGELOG | 3 ++- railties/lib/rails/application/configuration.rb | 27 +++++++++++++------------ railties/test/application/assets_test.rb | 23 +++++++++++++++++++++ 3 files changed, 39 insertions(+), 14 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 160ea0f600..187dd2428f 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -17,7 +17,8 @@ * Add jquery-rails to Gemfile of plugins, test/dummy app needs it. Closes #3091. [Santiago Pastorino] -* `rake assets:precompile` loads the application but does not initialize it. +* Add config.assets.initialize_on_precompile which, when set to false, forces + `rake assets:precompile` to load the application but does not initialize it. To the app developer, this means configuration add in config/initializers/* will not be executed. diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index c363e53c10..448521d2f0 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -37,19 +37,20 @@ module Rails @cache_store = [ :file_store, "#{root}/tmp/cache/" ] @assets = ActiveSupport::OrderedOptions.new - @assets.enabled = false - @assets.paths = [] - @assets.precompile = [ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) }, - /(?:\/|\\|\A)application\.(css|js)$/ ] - @assets.prefix = "/assets" - @assets.version = '' - @assets.debug = false - @assets.compile = true - @assets.digest = false - @assets.manifest = nil - @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] - @assets.js_compressor = nil - @assets.css_compressor = nil + @assets.enabled = false + @assets.paths = [] + @assets.precompile = [ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) }, + /(?:\/|\\|\A)application\.(css|js)$/ ] + @assets.prefix = "/assets" + @assets.version = '' + @assets.debug = false + @assets.compile = true + @assets.digest = false + @assets.manifest = nil + @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] + @assets.js_compressor = nil + @assets.css_compressor = nil + @assets.initialize_on_precompile = true end def compiled_asset_path diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 118ffff44b..7bace25fef 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -395,7 +395,30 @@ module ApplicationTests assert_match(/