aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2011-08-31 04:27:59 -0700
committerXavier Noria <fxn@hashref.com>2011-08-31 04:27:59 -0700
commit47b8415bef7edb25bb750685d6f9331f044bbd80 (patch)
treee408066b7c5df43b2e1b2fbc4f0ff5478f5efdab /railties
parent6d772c0953b418da774b2c3bf5cc297508669da7 (diff)
parente746c4047cd34accd7f63aa5d09cbb35011c24e2 (diff)
downloadrails-47b8415bef7edb25bb750685d6f9331f044bbd80.tar.gz
rails-47b8415bef7edb25bb750685d6f9331f044bbd80.tar.bz2
rails-47b8415bef7edb25bb750685d6f9331f044bbd80.zip
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG17
-rw-r--r--railties/README.rdoc8
-rw-r--r--railties/guides/rails_guides/generator.rb48
-rw-r--r--railties/guides/rails_guides/textile_extensions.rb25
-rw-r--r--railties/guides/source/3_1_release_notes.textile6
-rw-r--r--railties/guides/source/action_mailer_basics.textile57
-rw-r--r--railties/guides/source/active_model_basics.textile8
-rw-r--r--railties/guides/source/active_record_querying.textile4
-rw-r--r--railties/guides/source/active_support_core_extensions.textile4
-rw-r--r--railties/guides/source/asset_pipeline.textile43
-rw-r--r--railties/guides/source/command_line.textile2
-rw-r--r--railties/guides/source/getting_started.textile2
-rw-r--r--railties/guides/source/index.html.erb10
-rw-r--r--railties/guides/source/initialization.textile2
-rw-r--r--railties/guides/source/layout.html.erb4
-rw-r--r--railties/lib/rails.rb6
-rw-r--r--railties/lib/rails/application.rb5
-rw-r--r--railties/lib/rails/application/bootstrap.rb2
-rw-r--r--railties/lib/rails/application/configuration.rb21
-rw-r--r--railties/lib/rails/commands.rb3
-rw-r--r--railties/lib/rails/engine.rb1
-rw-r--r--railties/lib/rails/engine/commands.rb5
-rw-r--r--railties/lib/rails/generators.rb4
-rw-r--r--railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css6
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/application.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt6
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt4
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt3
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt10
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt (renamed from railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/application.html.erb.tt)0
-rw-r--r--railties/lib/rails/plugin.rb3
-rw-r--r--railties/lib/rails/railtie.rb1
-rw-r--r--railties/lib/rails/tasks/documentation.rake2
-rw-r--r--railties/test/application/asset_debugging_test.rb56
-rw-r--r--railties/test/application/assets_test.rb22
-rw-r--r--railties/test/application/middleware/sendfile_test.rb3
-rw-r--r--railties/test/generators/app_generator_test.rb11
38 files changed, 282 insertions, 136 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index a9b4deb551..6ed76974b4 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,9 @@
*Rails 3.2.0 (unreleased)*
+* 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]
+
* Attributes on scaffold and model generators default to string. This allows the following: "rails g scaffold Post title body:text author" [José Valim]
* Removed old plugin generator (`rails generate plugin`) in favor of `rails plugin new` command. [Guillermo Iguaran]
@@ -8,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]
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
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)>(.*?)</\1>}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(<<HTML)
-<notextile>
-<div class="code_container">
-<pre class="brush: #{brush}; gutter: false; toolbar: false">
-#{ERB::Util.h($2).strip}
-</pre>
-</div>
-</notextile>
-HTML
- "\ndirty_workaround_for_notextile_#{code_blocks.size - 1}\n"
- end
-
- body = yield body
-
- body.gsub(%r{<p>dirty_workaround_for_notextile_(\d+)</p>}) 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!('<plus>', '+')
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)>(.*?)</\1>}m) do |m|
- es = ERB::Util.h($2)
- css_class = $1.in?(['erb', 'shell']) ? 'html' : $1
- %{<notextile><div class="code_container"><code class="#{css_class}">#{es}</code></div></notextile>}
+ <<HTML
+<notextile>
+<div class="code_container">
+<pre class="brush: #{brush_for($1)}; gutter: false; toolbar: false">
+#{ERB::Util.h($2).strip}
+</pre>
+</div>
+</notextile>
+HTML
end
end
end
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index b9850daf15..4412d32cce 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 <tt>ActionController::ParamsWrapper</tt> 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 <tt>ActionController::Base.wrap_parameters</tt> in <tt>config/initializer/wrap_parameters.rb</tt>.
+* Added <tt>ActionController::ParamsWrapper</tt> 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 <tt>config/initializers/wrap_parameters.rb</tt>.
* Added <tt>config.action_controller.include_all_helpers</tt>. By default <tt>helper :all</tt> is done in <tt>ActionController::Base</tt>, 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).
@@ -170,7 +170,7 @@ class PostsController < ActionController::Base
end
</ruby>
-You can restrict it to some actions by using +:only+ or +:except+. Please read the docs at "<tt>ActionController::Streaming</tt>":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 "<tt>ActionController::Streaming</tt>":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.
@@ -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:
+
<ruby>
has_many :things, :conditions => proc { ["foo = ?", bar] }
</ruby>
@@ -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 <tt>ActiveRecord::Base#has_secure_password</tt> (via <tt>ActiveModel::SecurePassword</tt>) to encapsulate dead-simple password usage with BCrypt encryption and salting.
+
<ruby>
# Schema: User(name:string, password_digest:string, password_salt:string)
class User < ActiveRecord::Base
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
</ruby>
@@ -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 <tt>Mail::Message</tt> 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 <tt>#inline</tt> 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 <tt>:to</tt> key. The list of emails can be an array of email addresses or a single string with the addresses separated by commas.
<ruby>
- 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
</ruby>
The same format can be used to set carbon copy (Cc:) and blind carbon copy (Bcc:) recipients, by using the <tt>:cc</tt> and <tt>:bcc</tt> 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 <tt>"Name &lt;email&gt;"</tt>.
<ruby>
- 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
</ruby>
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
</ruby>
@@ -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:<ul><li>:address - Allows you to use a remote mail server. Just change it from its default "localhost" setting.</li><li>:port - On the off chance that your mail server doesn't run on port 25, you can change it.</li><li>:domain - If you need to specify a HELO domain, you can do it here.</li><li>:user_name - If your mail server requires authentication, set the username in this setting.</li><li>:password - If your mail server requires authentication, set the password in this setting.</li><li>: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.</li></ul>|
-|sendmail_settings|Allows you to override options for the :sendmail delivery method.<ul><li>:location - The location of the sendmail executable. Defaults to /usr/sbin/sendmail.</li><li>:arguments - The command line arguments to be passed to sendmail. Defaults to -i -t.</li></ul>|
-|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 <tt>:smtp</tt> delivery method:<ul><li><tt>:address</tt> - Allows you to use a remote mail server. Just change it from its default "localhost" setting.</li><li><tt>:port</tt> - On the off chance that your mail server doesn't run on port 25, you can change it.</li><li><tt>:domain</tt> - If you need to specify a HELO domain, you can do it here.</li><li><tt>:user_name</tt> - If your mail server requires authentication, set the username in this setting.</li><li><tt>:password</tt> - If your mail server requires authentication, set the password in this setting.</li><li><tt>:authentication</tt> - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>.</li></ul>|
+|+sendmail_settings+|Allows you to override options for the <tt>:sendmail</tt> delivery method.<ul><li><tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.</li><li><tt>:arguments</tt> - The command line arguments to be passed to sendmail. Defaults to <tt>-i -t</tt>.</li></ul>|
+|+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 <tt>:smtp</tt> (default), <tt>:sendmail</tt>, <tt>:file</tt> and <tt>:test</tt>.|
+|+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
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index 3c19fb5177..0672669dc5 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -183,22 +183,26 @@ 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
</ruby>
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 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
</ruby>
The SQL that would be executed:
+
<sql>
SELECT * FROM clients WHERE orders_count > 10 ORDER BY name DESC
</sql>
@@ -571,6 +572,7 @@ Client.where("orders_count > 10").reverse_order
</ruby>
The SQL that would be executed:
+
<sql>
SELECT * FROM clients WHERE orders_count > 10 ORDER BY clients.id DESC
</sql>
@@ -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+.
-<br />
-
This behavior can be turned off by setting <tt>ActiveRecord::Base.lock_optimistically = false</tt>.
To override the name of the +lock_version+ column, +ActiveRecord::Base+ provides a class method called +set_locking_column+:
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index e1fa374aca..b2436a2e68 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -864,7 +864,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:
<ruby>
delegate :name, :age, :address, :twitter, :to => :profile
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 8094ba18f2..96b11dbf63 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
@@ -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,9 +27,10 @@ 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.
+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.
@@ -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.
@@ -133,7 +137,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.
<plain>
-#logo { background: url(<%= asset_data_uri 'logo.png' %>)
+#logo { background: url(<%= asset_data_uri 'logo.png' %>) }
</plain>
This inserts a correctly-formatted data URI into the CSS source.
@@ -143,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:
<plain>
-.class{background-image:<%= asset_path 'image.png' %>}
+.class { background-image: <%= asset_path 'image.png' %> }
</plain>
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.
@@ -224,7 +228,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:
<plain>
//= require "projects"
@@ -247,6 +251,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.
@@ -262,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
@@ -273,7 +279,7 @@ Rails comes bundled with a rake task to compile the manifests to files on disc.
The rake task is:
<plain>
-rake assets:precompile
+bundle exec rake assets:precompile
</plain>
Capistrano (v2.8.0+) has a recipe to handle this in deployment. Add the following line to +Capfile+:
@@ -298,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']
</erb>
+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:
+
+<plain>
+---
+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
+</plain>
+
+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:
@@ -316,12 +336,16 @@ For Apache:
</LocationMatch>
</plain>
-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
@@ -369,6 +393,7 @@ To enable this, pass a +new+ Object to the config option in +application.rb+:
config.assets.css_compressor = Transformer.new
</erb>
+
h4. Changing the _assets_ Path
The public path that Sprockets uses by default is +/assets+.
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: <tt>rails d</tt>.
+
<shell>
$ rails generate model Oops
exists app/models/
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
diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb
index b48488d8a2..214155c088 100644
--- a/railties/guides/source/index.html.erb
+++ b/railties/guides/source/index.html.erb
@@ -124,13 +124,17 @@ Ruby on Rails Guides
<p>This guide covers the basic configuration settings for a Rails application.</p>
<% end %>
-<%= guide("Rails Command Line Tools and Rake tasks", 'command_line.html', :work_in_progress => true) do %>
+<%= guide("Rails Command Line Tools and Rake tasks", 'command_line.html') do %>
<p>This guide covers the command line tools and rake tasks provided by Rails.</p>
<% end %>
<%= guide("Caching with Rails", 'caching_with_rails.html', :work_in_progress => true) do %>
<p>Various caching techniques provided by Rails.</p>
<% end %>
+
+<%= guide('Asset Pipeline', 'asset_pipeline.html') do %>
+ <p>This guide documents the asset pipeline.</p>
+<% end %>
</dl>
<h3>Extending Rails</h3>
@@ -170,6 +174,10 @@ Ruby on Rails Guides
<h3>Release Notes</h3>
<dl>
+<%= guide("Ruby on Rails 3.1 Release Notes", '3_1_release_notes.html') do %>
+ <p>Release notes for Rails 3.1.</p>
+<% end %>
+
<%= guide("Ruby on Rails 3.0 Release Notes", '3_0_release_notes.html') do %>
<p>Release notes for Rails 3.0.</p>
<% end %>
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
diff --git a/railties/guides/source/layout.html.erb b/railties/guides/source/layout.html.erb
index 5dcac8e74c..3ccbc3a477 100644
--- a/railties/guides/source/layout.html.erb
+++ b/railties/guides/source/layout.html.erb
@@ -5,7 +5,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
-<title><%= yield(:page_title) || 'Ruby on Rails guides' %></title>
+<title><%= yield(:page_title) || 'Ruby on Rails Guides' %></title>
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
@@ -71,6 +71,7 @@
<dd><a href="configuring.html">Configuring Rails Applications</a></dd>
<dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
<dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+ <dd><a href="asset_pipeline.html">Asset Pipeline</a></dd>
<dt>Extending Rails</dt>
<dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
@@ -83,6 +84,7 @@
<dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
<dt>Release Notes</dt>
+ <dd><a href="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</a></dd>
<dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
<dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
<dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb
index de412553aa..73bdd0b552 100644
--- a/railties/lib/rails.rb
+++ b/railties/lib/rails.rb
@@ -22,8 +22,10 @@ require 'action_dispatch/railtie'
if RUBY_VERSION < '1.9'
$KCODE='u'
else
- Encoding.default_external = Encoding::UTF_8
- Encoding.default_internal = Encoding::UTF_8
+ silence_warnings do
+ Encoding.default_external = Encoding::UTF_8
+ Encoding.default_internal = Encoding::UTF_8
+ end
end
module Rails
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index fb60ddd9b5..528c96ef3e 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -55,6 +55,11 @@ module Rails
delegate :default_url_options, :default_url_options=, :to => :routes
+ def initialize
+ super
+ @initialized = false
+ end
+
# This method is called just after an application inherits from Rails::Application,
# allowing the developer to load classes in lib and use them during application
# configuration.
diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb
index 9f21d273e6..c9b147d075 100644
--- a/railties/lib/rails/application/bootstrap.rb
+++ b/railties/lib/rails/application/bootstrap.rb
@@ -28,7 +28,7 @@ module Rails
logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase)
logger.auto_flushing = false if Rails.env.production?
logger
- rescue StandardError => e
+ rescue StandardError
logger = ActiveSupport::BufferedLogger.new(STDERR)
logger.level = ActiveSupport::BufferedLogger::WARN
logger.warn(
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index 975e159999..5d7bd3282d 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/string/encoding'
+require 'active_support/core_ext/kernel/reporting'
require 'rails/engine/configuration'
module Rails
@@ -6,12 +7,13 @@ module Rails
class Configuration < ::Rails::Engine::Configuration
attr_accessor :allow_concurrency, :asset_host, :asset_path, :assets,
:cache_classes, :cache_store, :consider_all_requests_local,
- :dependency_loading, :encoding, :filter_parameters,
+ :dependency_loading, :filter_parameters,
:force_ssl, :helpers_paths, :logger, :preload_frameworks,
:reload_plugins, :secret_token, :serve_static_assets,
:static_cache_control, :session_options, :time_zone, :whiny_nils
attr_writer :log_level
+ attr_reader :encoding
def initialize(*)
super
@@ -33,10 +35,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.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
@@ -50,8 +55,10 @@ module Rails
def encoding=(value)
@encoding = value
if "ruby".encoding_aware?
- Encoding.default_external = value
- Encoding.default_internal = value
+ silence_warnings do
+ Encoding.default_external = value
+ Encoding.default_internal = value
+ end
else
$KCODE = value
if $KCODE == "NONE"
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
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index 2c3f61f404..89b151beb6 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -360,6 +360,7 @@ module Rails
end
def endpoint(endpoint = nil)
+ @endpoint ||= nil
@endpoint = endpoint if endpoint
@endpoint
end
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
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index fdafc91fcb..27f8d13ce8 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -77,7 +77,7 @@ module Rails
fallbacks.merge! config.fallbacks
templates_path.concat config.templates
templates_path.uniq!
- hide_namespaces *config.hidden_namespaces
+ hide_namespaces(*config.hidden_namespaces)
end
def self.templates_path
@@ -313,7 +313,7 @@ module Rails
begin
path = path.sub("#{base}/", "")
require path
- rescue Exception => e
+ rescue Exception
# No problem
end
end
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 .
+*/
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 86c9bd2d1d..3891829150 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/application.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -14,7 +14,7 @@ require "active_resource/railtie"
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
- Bundler.require *Rails.groups(:assets => %w(development test))
+ 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
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..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
@@ -29,4 +29,10 @@
# 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 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/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/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..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
@@ -4,9 +4,13 @@
# 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]" %>
+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.
-if defined?(ActiveRecord)
- ActiveRecord::Base.include_root_in_json = false
+ActiveSupport.on_load(:active_record) do
+ self.include_root_in_json = false
end
+<%- end -%>
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/application.html.erb.tt b/railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt
index 01550dec2f..01550dec2f 100644
--- 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/%name%/application.html.erb.tt
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb
index ceddd25eaa..3e27688bb9 100644
--- a/railties/lib/rails/plugin.rb
+++ b/railties/lib/rails/plugin.rb
@@ -74,7 +74,8 @@ module Rails
initializer :load_init_rb, :before => :load_config_initializers do |app|
init_rb = File.expand_path("init.rb", root)
if File.file?(init_rb)
- config = app.config
+ # This double assignment is to prevent an "unused variable" warning on Ruby 1.9.3.
+ config = config = app.config
# TODO: think about evaling initrb in context of Engine (currently it's
# always evaled in context of Rails::Application)
eval(File.read(init_rb), binding, init_rb)
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
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
diff --git a/railties/test/application/asset_debugging_test.rb b/railties/test/application/asset_debugging_test.rb
new file mode 100644
index 0000000000..38e1e21d17
--- /dev/null
+++ b/railties/test/application/asset_debugging_test.rb
@@ -0,0 +1,56 @@
+require 'isolation/abstract_unit'
+require 'rack/test'
+
+module ApplicationTests
+ class AssetDebuggingTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+ include Rack::Test::Methods
+
+ def setup
+ build_app(:initializers => true)
+
+ app_file "app/assets/javascripts/application.js", "//= require_tree ."
+ app_file "app/assets/javascripts/xmlhr.js", "function f1() { alert(); }"
+ app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'application' %>"
+
+ app_file "config/routes.rb", <<-RUBY
+ AppTemplate::Application.routes.draw do
+ match '/posts', :to => "posts#index"
+ end
+ RUBY
+
+ app_file "app/controllers/posts_controller.rb", <<-RUBY
+ class PostsController < ActionController::Base
+ end
+ RUBY
+
+ ENV["RAILS_ENV"] = "production"
+
+ boot_rails
+ end
+
+ def teardown
+ 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
+ require "#{app_path}/config/environment"
+
+ # the debug_assets params isn't used if allow_debugging is off
+ get '/posts?debug_assets=true'
+ assert_match %r{<script src="/assets/application-([0-z]+)\.js" type="text/javascript"></script>}, last_response.body
+ assert_no_match %r{<script src="/assets/xmlhr-([0-z]+)\.js" type="text/javascript"></script>}, 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{<script src="/assets/application-([0-z]+)\.js\?body=1" type="text/javascript"></script>}, last_response.body
+ assert_match %r{<script src="/assets/xmlhr-([0-z]+)\.js\?body=1" type="text/javascript"></script>}, last_response.body
+ end
+ end
+end
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb
index 802b737483..a8d1382e94 100644
--- a/railties/test/application/assets_test.rb
+++ b/railties/test/application/assets_test.rb
@@ -46,10 +46,11 @@ module ApplicationTests
assert defined?(Uglifier)
end
- test "precompile creates the file and gives it the original asset's content" 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();"
+ ENV["RAILS_ENV"] = nil
capture(:stdout) do
Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
end
@@ -57,15 +58,26 @@ module ApplicationTests
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();\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-*.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
assert_match /\/assets\/rails-([0-z]+)\.png/, File.read(file)
@@ -80,7 +92,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
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/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index fb7ebaa1fa..1b48c80042 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)
@@ -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)