From 8ff7693a8dc61f43fc4eaf72ed24d3b8699191fe Mon Sep 17 00:00:00 2001
From: Jose and Yehuda
Date: Mon, 26 Sep 2011 18:48:19 -0400
Subject: Initial commit of serializer support
---
railties/guides/source/serializers.textile | 600 +++++++++++++++++++++++++++++
1 file changed, 600 insertions(+)
create mode 100644 railties/guides/source/serializers.textile
(limited to 'railties')
diff --git a/railties/guides/source/serializers.textile b/railties/guides/source/serializers.textile
new file mode 100644
index 0000000000..a631a14694
--- /dev/null
+++ b/railties/guides/source/serializers.textile
@@ -0,0 +1,600 @@
+h2. Rails Serializers
+
+This guide describes how to use Active Model serializers to build non-trivial JSON services in Rails. By reading this guide, you will learn:
+
+* When to use the built-in Active Model serialization
+* When to use a custom serializer for your models
+* How to use serializers to encapsulate authorization concerns
+* How to create serializer templates to describe the application-wide structure of your serialized JSON
+* How to build resources not backed by a single database table for use with JSON services
+
+This guide covers an intermediate topic and assumes familiarity with Rails conventions. It is suitable for applications that expose a
+JSON API that may return different results based on the authorization status of the user.
+
+endprologue.
+
+h3. Serialization
+
+By default, Active Record objects can serialize themselves into JSON by using the `to_json` method. This method takes a series of additional
+parameter to control which properties and associations Rails should include in the serialized output.
+
+When building a web application that uses JavaScript to retrieve JSON data from the server, this mechanism has historically been the primary
+way that Rails developers prepared their responses. This works great for simple cases, as the logic for serializing an Active Record object
+is neatly encapsulated in Active Record itself.
+
+However, this solution quickly falls apart in the face of serialization requirements based on authorization. For instance, a web service
+may choose to expose additional information about a resource only if the user is entitled to access it. In addition, a JavaScript front-end
+may want information that is not neatly described in terms of serializing a single Active Record object, or in a different format than.
+
+In addition, neither the controller nor the model seems like the correct place for logic that describes how to serialize an model object
+*for the current user*.
+
+Serializers solve these problems by encapsulating serialization in an object designed for this purpose. If the default +to_json+ semantics,
+with at most a few configuration options serve your needs, by all means continue to use the built-in +to_json+. If you find yourself doing
+hash-driven-development in your controllers, juggling authorization logic and other concerns, serializers are for you!
+
+h3. The Most Basic Serializer
+
+A basic serializer is a simple Ruby object named after the model class it is serializing.
+
+
+class PostSerializer
+ def initialize(post, scope)
+ @post, @scope = post, scope
+ end
+
+ def as_json
+ { post: { title: @post.name, body: @post.body } }
+ end
+end
+
+
+A serializer is initialized with two parameters: the model object it should serialize and an authorization scope. By default, the
+authorization scope is the current user (+current_user+) but you can use a different object if you want. The serializer also
+implements an +as_json+ method, which returns a Hash that will be sent to the JSON encoder.
+
+Rails will transparently use your serializer when you use +render :json+ in your controller.
+
+
+class PostsController < ApplicationController
+ def show
+ @post = Post.find(params[:id])
+ render json: @post
+ end
+end
+
+
+Because +respond_with+ uses +render :json+ under the hood for JSON requests, Rails will automatically use your serializer when
+you use +respond_with+ as well.
+
+h4. +serializable_hash+
+
+In general, you will want to implement +serializable_hash+ and +as_json+ to allow serializers to embed associated content
+directly. The easiest way to implement these two methods is to have +as_json+ call +serializable_hash+ and insert the root.
+
+
+class PostSerializer
+ def initialize(post, scope)
+ @post, @scope = post, scope
+ end
+
+ def serializable_hash
+ { title: @post.name, body: @post.body }
+ end
+
+ def as_json
+ { post: serializable_hash }
+ end
+end
+
+
+h4. Authorization
+
+Let's update our serializer to include the email address of the author of the post, but only if the current user has superuser
+access.
+
+
+class PostSerializer
+ def initialize(post, scope)
+ @post, @scope = post, scope
+ end
+
+ def as_json
+ { post: serializable_hash }
+ end
+
+ def serializable_hash
+ hash = post
+ hash.merge!(super_data) if super?
+ hash
+ end
+
+private
+ def post
+ { title: @post.name, body: @post.body }
+ end
+
+ def super_data
+ { email: @post.email }
+ end
+
+ def super?
+ @scope.superuser?
+ end
+end
+
+
+h4. Testing
+
+One benefit of encapsulating our objects this way is that it becomes extremely straight-forward to test the serialization
+logic in isolation.
+
+
+require "ostruct"
+
+class PostSerializerTest < ActiveSupport::TestCase
+ # For now, we use a very simple authorization structure. These tests will need
+ # refactoring if we change that.
+ plebe = OpenStruct.new(super?: false)
+ god = OpenStruct.new(super?: true)
+
+ post = OpenStruct.new(title: "Welcome to my blog!", body: "Blah blah blah", email: "tenderlove@gmail.com")
+
+ test "a regular user sees just the title and body" do
+ json = PostSerializer.new(post, plebe).to_json
+ hash = JSON.parse(json)
+
+ assert_equal post.title, hash.delete("title")
+ assert_equal post.body, hash.delete("body")
+ assert_empty hash
+ end
+
+ test "a superuser sees the title, body and email" do
+ json = PostSerializer.new(post, god).to_json
+ hash = JSON.parse(json)
+
+ assert_equal post.title, hash["title"]
+ assert_equal post.body, hash["body"]
+ assert_equal post.email, hash["email"]
+ assert_empty hash
+ end
+end
+
+
+It's important to note that serializer objects define a clear interface specifically for serializing an existing object.
+In this case, the serializer expects to receive a post object with +name+, +body+ and +email+ attributes and an authorization
+scope with a +super?+ method.
+
+By defining a clear interface, it's must easier to ensure that your authorization logic is behaving correctly. In this case,
+the serializer doesn't need to concern itself with how the authorization scope decides whether to set the +super?+ flag, just
+whether it is set. In general, you should document these requirements in your serializer files and programatically via tests.
+The documentation library +YARD+ provides excellent tools for describing this kind of requirement:
+
+
+class PostSerializer
+ # @param [~body, ~title, ~email] post the post to serialize
+ # @param [~super] scope the authorization scope for this serializer
+ def initialize(post, scope)
+ @post, @scope = post, scope
+ end
+
+ # ...
+end
+
+
+h3. Attribute Sugar
+
+To simplify this process for a number of common cases, Rails provides a default superclass named +ActiveModel::Serializer+
+that you can use to implement your serializers.
+
+For example, you will sometimes want to simply include a number of existing attributes from the source model into the outputted
+JSON. In the above example, the +title+ and +body+ attributes were always included in the JSON. Let's see how to use
++ActiveModel::Serializer+ to simplify our post serializer.
+
+
+class PostSerializer < ActiveModel::Serializer
+ attributes :title, :body
+
+ def initialize(post, scope)
+ @post, @scope = post, scope
+ end
+
+ def serializable_hash
+ hash = attributes
+ hash.merge!(super_data) if super?
+ hash
+ end
+
+private
+ def super_data
+ { email: @post.email }
+ end
+
+ def super?
+ @scope.superuser?
+ end
+end
+
+
+First, we specified the list of included attributes at the top of the class. This will create an instance method called
++attributes+ that extracts those attributes from the post model.
+
+NOTE: Internally, +ActiveModel::Serializer+ uses +read_attribute_for_serialization+, which defaults to +read_attribute+, which defaults to +send+. So if you're rolling your own models for use with the serializer, you can use simple Ruby accessors for your attributes if you like.
+
+Next, we use the attributes methood in our +serializable_hash+ method, which allowed us to eliminate the +post+ method we hand-rolled
+earlier. We could also eliminate the +as_json+ method, as +ActiveModel::Serializer+ provides a default +as_json+ method for
+us that calls our +serializable_hash+ method and inserts a root. But we can go a step further!
+
+
+class PostSerializer < ActiveModel::Serializer
+ attributes :title, :body
+
+private
+ def attributes
+ hash = super
+ hash.merge!(email: post.email) if super?
+ hash
+ end
+
+ def super?
+ @scope.superuser?
+ end
+end
+
+
+The superclass provides a default +initialize+ method as well as a default +serializable_hash+ method, which uses
++attributes+. We can call +super+ to get the hash based on the attributes we declared, and then add in any additional
+attributes we want to use.
+
+NOTE: +ActiveModel::Serializer+ will create an accessor matching the name of the current class for the resource you pass in. In this case, because we have defined a PostSerializer, we can access the resource with the +post+ accessor.
+
+h3. Associations
+
+In most JSON APIs, you will want to include associated objects with your serialized object. In this case, let's include
+the comments with the current post.
+
+
+class PostSerializer < ActiveModel::Serializer
+ attributes :title. :body
+ has_many :comments
+
+private
+ def attributes
+ hash = super
+ hash.merge!(email: post.email) if super?
+ hash
+ end
+
+ def super?
+ @scope.superuser?
+ end
+end
+
+
+The default +serializable_hash+ method will include the comments as embedded objects inside the post.
+
+
+{
+ post: {
+ title: "Hello Blog!",
+ body: "This is my first post. Isn't it fabulous!",
+ comments: [
+ {
+ title: "Awesome",
+ body: "Your first post is great"
+ }
+ ]
+ }
+}
+
+
+Rails uses the same logic to generate embedded serializations as it does when you use +render :json+. In this case,
+because you didn't define a +CommentSerializer+, Rails used the default +as_json+ on your comment object.
+
+If you define a serializer, Rails will automatically instantiate it with the existing authorization scope.
+
+
+class CommentSerializer
+ def initialize(comment, scope)
+ @comment, @scope = comment, scope
+ end
+
+ def serializable_hash
+ { title: @comment.title }
+ end
+
+ def as_json
+ { comment: serializable_hash }
+ end
+end
+
+
+If we define the above comment serializer, the outputted JSON will change to:
+
+
+{
+ post: {
+ title: "Hello Blog!",
+ body: "This is my first post. Isn't it fabulous!",
+ comments: [{ title: "Awesome" }]
+ }
+}
+
+
+Let's imagine that our comment system allows an administrator to kill a comment, and we only want to allow
+users to see the comments they're entitled to see. By default, +has_many :comments+ will simply use the
++comments+ accessor on the post object. We can override the +comments+ accessor to limit the comments used
+to just the comments we want to allow for the current user.
+
+
+class PostSerializer < ActiveModel::Serializer
+ attributes :title. :body
+ has_many :comments
+
+private
+ def attributes
+ hash = super
+ hash.merge!(email: post.email) if super?
+ hash
+ end
+
+ def comments
+ post.comments_for(scope)
+ end
+
+ def super?
+ @scope.superuser?
+ end
+end
+
+
++ActiveModel::Serializer+ will still embed the comments, but this time it will use just the comments
+for the current user.
+
+NOTE: The logic for deciding which comments a user should see still belongs in the model layer. In general, you should encapsulate concerns that require making direct Active Record queries in scopes or public methods on your models.
+
+h3. Customizing Associations
+
+Not all front-ends expect embedded documents in the same form. In these cases, you can override the
+default +serializable_hash+, and use conveniences provided by +ActiveModel::Serializer+ to avoid having to
+build up the hash manually.
+
+For example, let's say our front-end expects the posts and comments in the following format:
+
+
+{
+ post: {
+ id: 1
+ title: "Hello Blog!",
+ body: "This is my first post. Isn't it fabulous!",
+ comments: [1,2]
+ },
+ comments: [
+ {
+ id: 1
+ title: "Awesome",
+ body: "Your first post is great"
+ },
+ {
+ id: 2
+ title: "Not so awesome",
+ body: "Why is it so short!"
+ }
+ ]
+}
+
+
+We could achieve this with a custom +as_json+ method. We will also need to define a serializer for comments.
+
+
+class CommentSerializer < ActiveModel::Serializer
+ attributes :id, :title, :body
+
+ # define any logic for dealing with authorization-based attributes here
+end
+
+class PostSerializer < ActiveModel::Serializer
+ attributes :title. :body
+ has_many :comments
+
+ def as_json
+ { post: serializable_hash }.merge!(associations)
+ end
+
+ def serializable_hash
+ post_hash = attributes
+ post_hash.merge!(association_ids)
+ post_hash
+ end
+
+private
+ def attributes
+ hash = super
+ hash.merge!(email: post.email) if super?
+ hash
+ end
+
+ def comments
+ post.comments_for(scope)
+ end
+
+ def super?
+ @scope.superuser?
+ end
+end
+
+
+Here, we used two convenience methods: +associations+ and +association_ids+. The first,
++associations+, creates a hash of all of the define associations, using their defined
+serializers. The second, +association_ids+, generates a hash whose key is the association
+name and whose value is an Array of the association's keys.
+
+The +association_ids+ helper will use the overridden version of the association, so in
+this case, +association_ids+ will only include the ids of the comments provided by the
++comments+ method.
+
+h3. Special Association Serializers
+
+So far, associations defined in serializers use either the +as_json+ method on the model
+or the defined serializer for the association type. Sometimes, you may want to serialize
+associated models differently when they are requested as part of another resource than
+when they are requested on their own.
+
+For instance, we might want to provide the full comment when it is requested directly,
+but only its title when requested as part of the post. To achieve this, you can define
+a serializer for associated objects nested inside the main serializer.
+
+
+class PostSerializer < ActiveModel::Serializer
+ class CommentSerializer < ActiveModel::Serializer
+ attributes :id, :title
+ end
+
+ # same as before
+ # ...
+end
+
+
+In other words, if a +PostSerializer+ is trying to serialize comments, it will first
+look for +PostSerializer::CommentSerializer+ before falling back to +CommentSerializer+
+and finally +comment.as_json+.
+
+h3. Optional Associations
+
+In some cases, you will want to allow a front-end to decide whether to include associated
+content or not. You can achieve this easily by making an association *optional*.
+
+
+class PostSerializer < ActiveModel::Serializer
+ attributes :title. :body
+ has_many :comments, :optional => true
+
+ # ...
+end
+
+
+If an association is optional, it will not be included unless the request asks for it
+with an +including+ parameter. The +including+ parameter is a comma-separated list of
+optional associations to include. If the +including+ parameter includes an association
+you did not specify in your serializer, it will receive a +401 Forbidden+ response.
+
+h3. Overriding the Defaults
+
+h4. Authorization Scope
+
+By default, the authorization scope for serializers is +:current_user+. This means
+that when you call +render json: @post+, the controller will automatically call
+its +current_user+ method and pass that along to the serializer's initializer.
+
+If you want to change that behavior, simply use the +serialization_scope+ class
+method.
+
+
+class PostsController < ApplicationController
+ serialization_scope :current_app
+end
+
+
+You can also implement an instance method called (no surprise) +serialization_scope+,
+which allows you to define a dynamic authorization scope based on the current request.
+
+WARNING: If you use different objects as authorization scopes, make sure that they all implement whatever interface you use in your serializers to control what the outputted JSON looks like.
+
+h4. Parameter to Specify Included Optional Associations
+
+In most cases, you should be able to use the default +including+ parameter to specify
+which optional associations to include. If you are already using that parameter name or
+want to reserve it for some reason, you can specify a different name by using the
++serialization_includes_param+ class method.
+
+
+class PostsController < ApplicationController
+ serialization_includes_param :associations_to_include
+end
+
+
+You can also implement a +serialization_includes+ instance method, which should return an
+Array of optional includes.
+
+WARNING: If you implement +serialization_includes+ and return an invalid association, your user will receive a +401 Forbidden+ exception.
+
+h3. Using Serializers Outside of a Request
+
+The serialization API encapsulates the concern of generating a JSON representation of
+a particular model for a particular user. As a result, you should be able to easily use
+serializers, whether you define them yourself or whether you use +ActiveModel::Serializer+
+outside a request.
+
+For instance, if you want to generate the JSON representation of a post for a user outside
+of a request:
+
+
+user = get_user # some logic to get the user in question
+PostSerializer.new(post, user).to_json # reliably generate JSON output
+
+
+If you want to generate JSON for an anonymous user, you should be able to use whatever
+technique you use in your application to generate anonymous users outside of a request.
+Typically, that means creating a new user and not saving it to the database:
+
+
+user = User.new # create a new anonymous user
+PostSerializer.new(post, user).to_json
+
+
+In general, the better you encapsulate your authorization logic, the more easily you
+will be able to use the serializer outside of the context of a request. For instance,
+if you use an authorization library like Cancan, which uses a uniform +user.can?(action, model)+,
+the authorization interface can very easily be replaced by a plain Ruby object for
+testing or usage outside the context of a request.
+
+h3. Collections
+
+So far, we've talked about serializing individual model objects. By default, Rails
+will serialize collections, including when using the +associations+ helper, by
+looping over each element of the collection, calling +serializable_hash+ on the element,
+and then grouping them by their type (using the plural version of their class name
+as the root).
+
+For example, an Array of post objects would serialize as:
+
+
+{
+ posts: [
+ {
+ title: "FIRST POST!",
+ body: "It's my first pooooost"
+ },
+ { title: "Second post!",
+ body: "Zomg I made it to my second post"
+ }
+ ]
+}
+
+
+If you want to change the behavior of serialized Arrays, you need to create
+a custom Array serializer.
+
+
+class ArraySerializer < ActiveModel::ArraySerializer
+ def serializable_array
+ serializers.map do |serializer|
+ serializer.serializable_hash
+ end
+ end
+
+ def as_json
+ hash = { root => serializable_array }
+ hash.merge!(associations)
+ hash
+ end
+end
+
+
+When generating embedded associations using the +associations+ helper inside a
+regular serializer, it will create a new ArraySerializer
with the
+associated content and call its +serializable_array+ method. In this case, those
+embedded associations will not recursively include associations.
+
+When generating an Array using +render json: posts+, the controller will invoke
+the +as_json+ method, which will include its associations and its root.
--
cgit v1.2.3
From f5836543c3cd16f7789c936a4181f4a7204141dc Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 28 Sep 2011 17:05:03 +0530
Subject: minor edits in serializers guide
---
railties/guides/source/serializers.textile | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
(limited to 'railties')
diff --git a/railties/guides/source/serializers.textile b/railties/guides/source/serializers.textile
index a631a14694..86a5e5ac8d 100644
--- a/railties/guides/source/serializers.textile
+++ b/railties/guides/source/serializers.textile
@@ -153,9 +153,9 @@ class PostSerializerTest < ActiveSupport::TestCase
json = PostSerializer.new(post, god).to_json
hash = JSON.parse(json)
- assert_equal post.title, hash["title"]
- assert_equal post.body, hash["body"]
- assert_equal post.email, hash["email"]
+ assert_equal post.title, hash.delete("title")
+ assert_equal post.body, hash.delete("body")
+ assert_equal post.email, hash.delete("email")
assert_empty hash
end
end
@@ -255,7 +255,7 @@ the comments with the current post.
class PostSerializer < ActiveModel::Serializer
- attributes :title. :body
+ attributes :title, :body
has_many :comments
private
@@ -361,7 +361,7 @@ build up the hash manually.
For example, let's say our front-end expects the posts and comments in the following format:
-
+
{
post: {
id: 1
@@ -382,7 +382,7 @@ For example, let's say our front-end expects the posts and comments in the follo
}
]
}
-
+
We could achieve this with a custom +as_json+ method. We will also need to define a serializer for comments.
@@ -394,7 +394,7 @@ class CommentSerializer < ActiveModel::Serializer
end
class PostSerializer < ActiveModel::Serializer
- attributes :title. :body
+ attributes :title, :body
has_many :comments
def as_json
@@ -558,7 +558,7 @@ as the root).
For example, an Array of post objects would serialize as:
-
+
{
posts: [
{
@@ -570,7 +570,7 @@ For example, an Array of post objects would serialize as:
}
]
}
-
+
If you want to change the behavior of serialized Arrays, you need to create
a custom Array serializer.
--
cgit v1.2.3
From da02f792fe78535628f86bf983308800207b4225 Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Mon, 14 Nov 2011 11:28:12 +0000
Subject: Sync CHANGELOGs from 3-1-stable
---
railties/CHANGELOG.md | 10 ++++++++++
1 file changed, 10 insertions(+)
(limited to 'railties')
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 0c59f59917..b05ac21b49 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -30,6 +30,16 @@
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.2 (unreleased) ##
+
+* Engines: don't blow up if db/seeds.rb is missing.
+
+ *Jeremy Kemper*
+
+* `rails new foo --skip-test-unit` should not add the `:test` task to the rake default task.
+ *GH 2564*
+
+ *José Valim*
## Rails 3.1.0 (August 30, 2011) ##
--
cgit v1.2.3
From 49cd6a0ff7a3f5b0e85707961c952bdc3b0a178f Mon Sep 17 00:00:00 2001
From: Guillermo Iguaran
Date: Mon, 14 Nov 2011 07:07:38 -0500
Subject: Added therubyrhino to default Gemfile under JRuby
---
railties/lib/rails/generators/app_base.rb | 1 +
railties/test/generators/app_generator_test.rb | 7 +++++++
2 files changed, 8 insertions(+)
(limited to 'railties')
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index 0a79d6e86e..3fbde0d989 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -199,6 +199,7 @@ module Rails
group :assets do
gem 'sass-rails', :git => 'git://github.com/rails/sass-rails.git'
gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails.git'
+ #{"gem 'therubyrhino'\n" if defined?(JRUBY_VERSION)}
gem 'uglifier', '>= 1.0.3'
end
GEMFILE
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 955ed09361..a1bd2fbaa5 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -208,6 +208,13 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_file "test/performance/browsing_test.rb"
end
+ def test_inclusion_of_therubyrhino_under_jruby
+ if defined?(JRUBY_VERSION)
+ run_generator([destination_root])
+ assert_file "Gemfile", /gem\s+["']therubyrhino["']$/
+ end
+ end
+
def test_creation_of_a_test_directory
run_generator
assert_file 'test'
--
cgit v1.2.3
From 76b6027cd80685617b5bf5ceb986fd5dc8e213b2 Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Fri, 11 Nov 2011 15:34:47 +0530
Subject: Unused variable removed
---
railties/test/application/console_test.rb | 1 -
railties/test/application/rackup_test.rb | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
(limited to 'railties')
diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb
index b3745f194e..2073c780bf 100644
--- a/railties/test/application/console_test.rb
+++ b/railties/test/application/console_test.rb
@@ -71,7 +71,6 @@ class ConsoleTest < Test::Unit::TestCase
assert !User.new.respond_to?(:age)
silence_stream(STDOUT) { irb_context.reload! }
- session = irb_context.new_session
assert User.new.respond_to?(:age)
end
diff --git a/railties/test/application/rackup_test.rb b/railties/test/application/rackup_test.rb
index ff9cdcadc7..86e1995def 100644
--- a/railties/test/application/rackup_test.rb
+++ b/railties/test/application/rackup_test.rb
@@ -6,7 +6,7 @@ module ApplicationTests
def rackup
require "rack"
- app, options = Rack::Builder.parse_file("#{app_path}/config.ru")
+ app, _ = Rack::Builder.parse_file("#{app_path}/config.ru")
app
end
--
cgit v1.2.3
From bc00514b6236d701d3e660c4ec365a767a070a91 Mon Sep 17 00:00:00 2001
From: rpq
Date: Tue, 15 Nov 2011 23:20:21 -0500
Subject: added comma
---
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 6ff5e87b6d..3681501293 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -438,7 +438,7 @@ location ~ ^/assets/ {
}
-When files are precompiled, Sprockets also creates a "gzipped":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. Web servers are typically configured to use a moderate compression ratio as a compromise, but since precompilation happens once Sprockets uses the maximum compression ratio, thus reducing the size of the data transfer to the minimum. On the other hand, web servers can be configured to serve compressed content directly from disk, rather than deflating non-compressed files themselves.
+When files are precompiled, Sprockets also creates a "gzipped":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. Web servers are typically configured to use a moderate compression ratio as a compromise, but since precompilation happens once, Sprockets uses the maximum compression ratio, thus reducing the size of the data transfer to the minimum. On the other hand, web servers can be configured to serve compressed content directly from disk, rather than deflating non-compressed files themselves.
Nginx is able to do this automatically enabling +gzip_static+:
--
cgit v1.2.3
From 21c5a0a104bf04e3e7b63aa5f0104f1c666655c3 Mon Sep 17 00:00:00 2001
From: Daniel Dyba
Date: Sat, 16 Jul 2011 16:54:03 -0700
Subject: Changed Commands module to RailsCommands.
This is to avoid a conflict that occurs when you add Rake to
your Gemfile. There is a Commands Object in Rake that conflicts
with the Commands module in plugin.rb. See rails issue #1866.
---
railties/lib/rails/commands/plugin.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'railties')
diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb
index 4df849447d..aa4551c806 100644
--- a/railties/lib/rails/commands/plugin.rb
+++ b/railties/lib/rails/commands/plugin.rb
@@ -274,7 +274,7 @@ end
# load default environment and parse arguments
require 'optparse'
-module Commands
+module RailsCommands
class Plugin
attr_reader :environment, :script_name
def initialize
@@ -327,7 +327,7 @@ module Commands
command = general.shift
if command =~ /^(install|remove)$/
- command = Commands.const_get(command.capitalize).new(self)
+ command = RailsCommands.const_get(command.capitalize).new(self)
command.parse!(sub)
else
puts "Unknown command: #{command}" unless command.blank?
@@ -539,4 +539,4 @@ class RecursiveHTTPFetcher
end
end
-Commands::Plugin.parse!
+RailsCommands::Plugin.parse!
--
cgit v1.2.3
From 325abe9fbad58b6a0e119a678039b195247a57bc Mon Sep 17 00:00:00 2001
From: Daniel Dyba
Date: Sun, 17 Jul 2011 23:09:51 -0700
Subject: Substituted RailsCommands for Rails::Commands
---
railties/lib/rails/commands/plugin.rb | 320 +++++++++++++++++-----------------
1 file changed, 161 insertions(+), 159 deletions(-)
(limited to 'railties')
diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb
index aa4551c806..c99a2e6685 100644
--- a/railties/lib/rails/commands/plugin.rb
+++ b/railties/lib/rails/commands/plugin.rb
@@ -274,198 +274,200 @@ end
# load default environment and parse arguments
require 'optparse'
-module RailsCommands
- class Plugin
- attr_reader :environment, :script_name
- def initialize
- @environment = RailsEnvironment.default
- @rails_root = RailsEnvironment.default.root
- @script_name = File.basename($0)
- end
+module Rails
+ module Commands
+ class Plugin
+ attr_reader :environment, :script_name
+ def initialize
+ @environment = RailsEnvironment.default
+ @rails_root = RailsEnvironment.default.root
+ @script_name = File.basename($0)
+ end
- def environment=(value)
- @environment = value
- RailsEnvironment.default = value
- end
+ def environment=(value)
+ @environment = value
+ RailsEnvironment.default = value
+ end
- def options
- OptionParser.new do |o|
- o.set_summary_indent(' ')
- o.banner = "Usage: plugin [OPTIONS] command"
- o.define_head "Rails plugin manager."
+ def options
+ OptionParser.new do |o|
+ o.set_summary_indent(' ')
+ o.banner = "Usage: plugin [OPTIONS] command"
+ o.define_head "Rails plugin manager."
- o.separator ""
- o.separator "GENERAL OPTIONS"
+ o.separator ""
+ o.separator "GENERAL OPTIONS"
- o.on("-r", "--root=DIR", String,
- "Set an explicit rails app directory.",
- "Default: #{@rails_root}") { |rails_root| @rails_root = rails_root; self.environment = RailsEnvironment.new(@rails_root) }
+ o.on("-r", "--root=DIR", String,
+ "Set an explicit rails app directory.",
+ "Default: #{@rails_root}") { |rails_root| @rails_root = rails_root; self.environment = RailsEnvironment.new(@rails_root) }
- o.on("-v", "--verbose", "Turn on verbose output.") { |verbose| $verbose = verbose }
- o.on("-h", "--help", "Show this help message.") { puts o; exit }
+ o.on("-v", "--verbose", "Turn on verbose output.") { |verbose| $verbose = verbose }
+ o.on("-h", "--help", "Show this help message.") { puts o; exit }
- o.separator ""
- o.separator "COMMANDS"
+ o.separator ""
+ o.separator "COMMANDS"
- o.separator " install Install plugin(s) from known repositories or URLs."
- o.separator " remove Uninstall plugins."
+ o.separator " install Install plugin(s) from known repositories or URLs."
+ o.separator " remove Uninstall plugins."
- o.separator ""
- o.separator "EXAMPLES"
- o.separator " Install a plugin from a subversion URL:"
- o.separator " #{@script_name} plugin install http://example.com/my_svn_plugin\n"
- o.separator " Install a plugin from a git URL:"
- o.separator " #{@script_name} plugin install git://github.com/SomeGuy/my_awesome_plugin.git\n"
- o.separator " Install a plugin and add a svn:externals entry to vendor/plugins"
- o.separator " #{@script_name} plugin install -x my_svn_plugin\n"
+ o.separator ""
+ o.separator "EXAMPLES"
+ o.separator " Install a plugin from a subversion URL:"
+ o.separator " #{@script_name} plugin install http://example.com/my_svn_plugin\n"
+ o.separator " Install a plugin from a git URL:"
+ o.separator " #{@script_name} plugin install git://github.com/SomeGuy/my_awesome_plugin.git\n"
+ o.separator " Install a plugin and add a svn:externals entry to vendor/plugins"
+ o.separator " #{@script_name} plugin install -x my_svn_plugin\n"
+ end
end
- end
- def parse!(args=ARGV)
- general, sub = split_args(args)
- options.parse!(general)
+ def parse!(args=ARGV)
+ general, sub = split_args(args)
+ options.parse!(general)
- command = general.shift
- if command =~ /^(install|remove)$/
- command = RailsCommands.const_get(command.capitalize).new(self)
- command.parse!(sub)
- else
- puts "Unknown command: #{command}" unless command.blank?
- puts options
- exit 1
+ command = general.shift
+ if command =~ /^(install|remove)$/
+ command = Commands.const_get(command.capitalize).new(self)
+ command.parse!(sub)
+ else
+ puts "Unknown command: #{command}" unless command.blank?
+ puts options
+ exit 1
+ end
end
- end
- def split_args(args)
- left = []
- left << args.shift while args[0] and args[0] =~ /^-/
- left << args.shift if args[0]
- [left, args]
- end
-
- def self.parse!(args=ARGV)
- Plugin.new.parse!(args)
- end
- end
+ def split_args(args)
+ left = []
+ left << args.shift while args[0] and args[0] =~ /^-/
+ left << args.shift if args[0]
+ [left, args]
+ end
- class Install
- def initialize(base_command)
- @base_command = base_command
- @method = :http
- @options = { :quiet => false, :revision => nil, :force => false }
+ def self.parse!(args=ARGV)
+ Plugin.new.parse!(args)
+ end
end
- def options
- OptionParser.new do |o|
- o.set_summary_indent(' ')
- o.banner = "Usage: #{@base_command.script_name} install PLUGIN [PLUGIN [PLUGIN] ...]"
- o.define_head "Install one or more plugins."
- o.separator ""
- o.separator "Options:"
- o.on( "-x", "--externals",
- "Use svn:externals to grab the plugin.",
- "Enables plugin updates and plugin versioning.") { |v| @method = :externals }
- o.on( "-o", "--checkout",
- "Use svn checkout to grab the plugin.",
- "Enables updating but does not add a svn:externals entry.") { |v| @method = :checkout }
- o.on( "-e", "--export",
- "Use svn export to grab the plugin.",
- "Exports the plugin, allowing you to check it into your local repository. Does not enable updates or add an svn:externals entry.") { |v| @method = :export }
- o.on( "-q", "--quiet",
- "Suppresses the output from installation.",
- "Ignored if -v is passed (rails plugin -v install ...)") { |v| @options[:quiet] = true }
- o.on( "-r REVISION", "--revision REVISION",
- "Checks out the given revision from subversion or git.",
- "Ignored if subversion/git is not used.") { |v| @options[:revision] = v }
- o.on( "-f", "--force",
- "Reinstalls a plugin if it's already installed.") { |v| @options[:force] = true }
- o.separator ""
- o.separator "You can specify plugin names as given in 'plugin list' output or absolute URLs to "
- o.separator "a plugin repository."
+ class Install
+ def initialize(base_command)
+ @base_command = base_command
+ @method = :http
+ @options = { :quiet => false, :revision => nil, :force => false }
end
- end
- def determine_install_method
- best = @base_command.environment.best_install_method
- @method = :http if best == :http and @method == :export
- case
- when (best == :http and @method != :http)
- msg = "Cannot install using subversion because `svn' cannot be found in your PATH"
- when (best == :export and (@method != :export and @method != :http))
- msg = "Cannot install using #{@method} because this project is not under subversion."
- when (best != :externals and @method == :externals)
- msg = "Cannot install using externals because vendor/plugins is not under subversion."
+ def options
+ OptionParser.new do |o|
+ o.set_summary_indent(' ')
+ o.banner = "Usage: #{@base_command.script_name} install PLUGIN [PLUGIN [PLUGIN] ...]"
+ o.define_head "Install one or more plugins."
+ o.separator ""
+ o.separator "Options:"
+ o.on( "-x", "--externals",
+ "Use svn:externals to grab the plugin.",
+ "Enables plugin updates and plugin versioning.") { |v| @method = :externals }
+ o.on( "-o", "--checkout",
+ "Use svn checkout to grab the plugin.",
+ "Enables updating but does not add a svn:externals entry.") { |v| @method = :checkout }
+ o.on( "-e", "--export",
+ "Use svn export to grab the plugin.",
+ "Exports the plugin, allowing you to check it into your local repository. Does not enable updates or add an svn:externals entry.") { |v| @method = :export }
+ o.on( "-q", "--quiet",
+ "Suppresses the output from installation.",
+ "Ignored if -v is passed (rails plugin -v install ...)") { |v| @options[:quiet] = true }
+ o.on( "-r REVISION", "--revision REVISION",
+ "Checks out the given revision from subversion or git.",
+ "Ignored if subversion/git is not used.") { |v| @options[:revision] = v }
+ o.on( "-f", "--force",
+ "Reinstalls a plugin if it's already installed.") { |v| @options[:force] = true }
+ o.separator ""
+ o.separator "You can specify plugin names as given in 'plugin list' output or absolute URLs to "
+ o.separator "a plugin repository."
+ end
end
- if msg
- puts msg
- exit 1
+
+ def determine_install_method
+ best = @base_command.environment.best_install_method
+ @method = :http if best == :http and @method == :export
+ case
+ when (best == :http and @method != :http)
+ msg = "Cannot install using subversion because `svn' cannot be found in your PATH"
+ when (best == :export and (@method != :export and @method != :http))
+ msg = "Cannot install using #{@method} because this project is not under subversion."
+ when (best != :externals and @method == :externals)
+ msg = "Cannot install using externals because vendor/plugins is not under subversion."
+ end
+ if msg
+ puts msg
+ exit 1
+ end
+ @method
end
- @method
- end
- def parse!(args)
- options.parse!(args)
- if args.blank?
- puts options
+ def parse!(args)
+ options.parse!(args)
+ if args.blank?
+ puts options
+ exit 1
+ end
+ environment = @base_command.environment
+ install_method = determine_install_method
+ puts "Plugins will be installed using #{install_method}" if $verbose
+ args.each do |name|
+ ::Plugin.find(name).install(install_method, @options)
+ end
+ rescue StandardError => e
+ puts "Plugin not found: #{args.inspect}"
+ puts e.inspect if $verbose
exit 1
end
- environment = @base_command.environment
- install_method = determine_install_method
- puts "Plugins will be installed using #{install_method}" if $verbose
- args.each do |name|
- ::Plugin.find(name).install(install_method, @options)
- end
- rescue StandardError => e
- puts "Plugin not found: #{args.inspect}"
- puts e.inspect if $verbose
- exit 1
- end
- end
-
- class Remove
- def initialize(base_command)
- @base_command = base_command
end
- def options
- OptionParser.new do |o|
- o.set_summary_indent(' ')
- o.banner = "Usage: #{@base_command.script_name} remove name [name]..."
- o.define_head "Remove plugins."
+ class Remove
+ def initialize(base_command)
+ @base_command = base_command
end
- end
- def parse!(args)
- options.parse!(args)
- if args.blank?
- puts options
- exit 1
+ def options
+ OptionParser.new do |o|
+ o.set_summary_indent(' ')
+ o.banner = "Usage: #{@base_command.script_name} remove name [name]..."
+ o.define_head "Remove plugins."
+ end
end
- root = @base_command.environment.root
- args.each do |name|
- ::Plugin.new(name).uninstall
+
+ def parse!(args)
+ options.parse!(args)
+ if args.blank?
+ puts options
+ exit 1
+ end
+ root = @base_command.environment.root
+ args.each do |name|
+ ::Plugin.new(name).uninstall
+ end
end
end
- end
- class Info
- def initialize(base_command)
- @base_command = base_command
- end
+ class Info
+ def initialize(base_command)
+ @base_command = base_command
+ end
- def options
- OptionParser.new do |o|
- o.set_summary_indent(' ')
- o.banner = "Usage: #{@base_command.script_name} info name [name]..."
- o.define_head "Shows plugin info at {url}/about.yml."
+ def options
+ OptionParser.new do |o|
+ o.set_summary_indent(' ')
+ o.banner = "Usage: #{@base_command.script_name} info name [name]..."
+ o.define_head "Shows plugin info at {url}/about.yml."
+ end
end
- end
- def parse!(args)
- options.parse!(args)
- args.each do |name|
- puts ::Plugin.find(name).info
- puts
+ def parse!(args)
+ options.parse!(args)
+ args.each do |name|
+ puts ::Plugin.find(name).info
+ puts
+ end
end
end
end
@@ -539,4 +541,4 @@ class RecursiveHTTPFetcher
end
end
-RailsCommands::Plugin.parse!
+Rails::Commands::Plugin.parse!
--
cgit v1.2.3
From 64a3175eea3c121f30a5a24034aa1ed400c80b12 Mon Sep 17 00:00:00 2001
From: capps
Date: Wed, 16 Nov 2011 15:57:54 -0800
Subject: "denoted" instead of "donated" "parentheses" instead of "use
brackets"
---
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 2d4cc13571..e9477e84cf 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -231,7 +231,7 @@ end
Now, when you call the +books_path+ method you should get +"/en/books"+ (for the default locale). An URL like +http://localhost:3001/nl/books+ should load the Netherlands locale, then, and following calls to +books_path+ should return +"/nl/books"+ (because the locale changed).
-If you don't want to force the use of a locale in your routes you can use an optional path scope (donated by the use brackets) like so:
+If you don't want to force the use of a locale in your routes you can use an optional path scope (denoted by the parentheses) like so:
# config/routes.rb
--
cgit v1.2.3
From 0af93089deaf6dc9428c0f2f7a376cdb6f81daee Mon Sep 17 00:00:00 2001
From: Alex Tambellini
Date: Thu, 17 Nov 2011 09:44:17 -0500
Subject: Move schema_format :sql config setting from test.rb to application.rb
I've moved the schema_format :sql config setting to application.rb because you would
never enable this only for the test environment. If you use database constraints
or database specific data types you would want all of your environments to use them.
---
railties/guides/code/getting_started/config/application.rb | 5 +++++
railties/guides/code/getting_started/config/environments/test.rb | 5 -----
.../lib/rails/generators/rails/app/templates/config/application.rb | 5 +++++
.../generators/rails/app/templates/config/environments/test.rb.tt | 5 -----
4 files changed, 10 insertions(+), 10 deletions(-)
(limited to 'railties')
diff --git a/railties/guides/code/getting_started/config/application.rb b/railties/guides/code/getting_started/config/application.rb
index e914b5a80e..e16da30f72 100644
--- a/railties/guides/code/getting_started/config/application.rb
+++ b/railties/guides/code/getting_started/config/application.rb
@@ -39,6 +39,11 @@ module Blog
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
+ # Use SQL instead of Active Record's schema dumper when creating the 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
+
# Enable the asset pipeline
config.assets.enabled = true
diff --git a/railties/guides/code/getting_started/config/environments/test.rb b/railties/guides/code/getting_started/config/environments/test.rb
index 833241ace3..08697cbbc9 100644
--- a/railties/guides/code/getting_started/config/environments/test.rb
+++ b/railties/guides/code/getting_started/config/environments/test.rb
@@ -29,11 +29,6 @@ Blog::Application.configure do
# 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
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 13fbe9e526..40fd843b1b 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/application.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -49,6 +49,11 @@ module <%= app_const_base %>
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
+ # Use SQL instead of Active Record's schema dumper when creating the 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
+
<% unless options.skip_sprockets? -%>
# Enable the asset pipeline
config.assets.enabled = 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..37a8b81dad 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
@@ -29,11 +29,6 @@
# 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
-
<%- unless options.skip_active_record? -%>
# Raise exception on mass assignment protection for ActiveRecord models
config.active_record.mass_assignment_sanitizer = :strict
--
cgit v1.2.3
From 8d17af23ef5202e7c28bbf701e247bce6011df07 Mon Sep 17 00:00:00 2001
From: Sunny Ripert
Date: Thu, 17 Nov 2011 17:05:53 +0100
Subject: Guides: better example to find the last sent email
---
railties/guides/source/testing.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties')
diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile
index 2341a3522c..5dbbe2c0f0 100644
--- a/railties/guides/source/testing.textile
+++ b/railties/guides/source/testing.textile
@@ -927,7 +927,7 @@ class UserControllerTest < ActionController::TestCase
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
post :invite_friend, :email => 'friend@example.com'
end
- invite_email = ActionMailer::Base.deliveries.first
+ invite_email = ActionMailer::Base.deliveries.last
assert_equal "You have been invited by me@example.com", invite_email.subject
assert_equal 'friend@example.com', invite_email.to[0]
--
cgit v1.2.3
From 9b534060bfafbf1db36e73bb3e538b8c412dcc54 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Fri, 18 Nov 2011 01:17:21 +0530
Subject: update guide: db:structure:dump produces structure.sql now
---
railties/guides/source/migrations.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties')
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 23e36b39f9..5b52a93853 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -658,7 +658,7 @@ In many ways this is exactly what it is. This file is created by inspecting the
There is however a trade-off: +db/schema.rb+ cannot express database specific items such as foreign key constraints, triggers, or stored procedures. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this, then you should set the schema format to +:sql+.
-Instead of using Active Record's schema dumper, the database's structure will be dumped using a tool specific to the database (via the +db:structure:dump+ Rake task) into +db/#{Rails.env}_structure.sql+. For example, for the PostgreSQL RDBMS, the +pg_dump+ utility is used. For MySQL, this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading these schemas is simply a question of executing the SQL statements they contain. By definition, this will create a perfect copy of the database's structure. Using the +:sql+ schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it.
+Instead of using Active Record's schema dumper, the database's structure will be dumped using a tool specific to the database (via the +db:structure:dump+ Rake task) into +db/structure.sql+. For example, for the PostgreSQL RDBMS, the +pg_dump+ utility is used. For MySQL, this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading these schemas is simply a question of executing the SQL statements they contain. By definition, this will create a perfect copy of the database's structure. Using the +:sql+ schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it.
h4. Schema Dumps and Source Control
--
cgit v1.2.3
From d57d8098fc269a26ea0051a9027a33af1a9a4b2b Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Thu, 17 Nov 2011 23:07:06 +0100
Subject: warn the user values are directly interpolated into _html translation
strings
---
railties/guides/source/i18n.textile | 12 ++++++++++++
1 file changed, 12 insertions(+)
(limited to 'railties')
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 2d4cc13571..43afa6c9e2 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -634,6 +634,18 @@ en:
!images/i18n/demo_html_safe.png(i18n demo html safe)!
+Please note that values are interpolated directly into the translation.
+If they need to be escaped you need to pass them already escaped in the +t+ call.
+
+
+# config/locales/en.yml
+en:
+ welcome_html: Welcome %{name}!
+
+<%# Note the call to h() to avoid injection %>
+<%= t('welcome_html', :name => h(user.name)) %>
+
+
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 1079724fe643fe63e6d58a37274c2cf0ff172a8b Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Thu, 17 Nov 2011 23:59:19 +0100
Subject: Revert "warn the user values are directly interpolated into _html
translation strings"
Reason: After another round of discussion, it has been
decided to let interpolation deal with unsafe strings
as it should do.
This reverts commit d57d8098fc269a26ea0051a9027a33af1a9a4b2b.
---
railties/guides/source/i18n.textile | 12 ------------
1 file changed, 12 deletions(-)
(limited to 'railties')
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 43afa6c9e2..2d4cc13571 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -634,18 +634,6 @@ en:
!images/i18n/demo_html_safe.png(i18n demo html safe)!
-Please note that values are interpolated directly into the translation.
-If they need to be escaped you need to pass them already escaped in the +t+ call.
-
-
-# config/locales/en.yml
-en:
- welcome_html: Welcome %{name}!
-
-<%# Note the call to h() to avoid injection %>
-<%= t('welcome_html', :name => h(user.name)) %>
-
-
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 9d035292ba39fcb046656ceb28e7a2f10cdb7f9c Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Fri, 18 Nov 2011 23:10:12 +0530
Subject: remove unneeded params from 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 1cd70404a3..37ead2bff2 100644
--- a/railties/guides/source/contributing_to_ruby_on_rails.textile
+++ b/railties/guides/source/contributing_to_ruby_on_rails.textile
@@ -215,7 +215,7 @@ TIP: You may want to "put your git branch name in your shell prompt":http://qugs
h3. Helping to Resolve Existing Issues
-As a next step beyond reporting issues, you can help the core team resolve existing issues. If you check the "Everyone's Issues":https://github.com/rails/rails/issues?sort=created&direction=desc&state=open list in GitHub Issues, you'll find lots of issues already requiring attention. What can you do for these? Quite a bit, actually:
+As a next step beyond reporting issues, you can help the core team resolve existing issues. If you check the "Everyone's Issues":https://github.com/rails/rails/issues list in GitHub Issues, you'll find lots of issues already requiring attention. What can you do for these? Quite a bit, actually:
h4. Verifying Bug Reports
--
cgit v1.2.3
From dda6787f44a4e9a90cc28b3efee5b63c7d8cd023 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 19 Nov 2011 00:07:50 +0530
Subject: mailer guide - update info about using default host. Fixes #3642
---
railties/guides/source/action_mailer_basics.textile | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
(limited to 'railties')
diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile
index ad5b848d2c..26c95be031 100644
--- a/railties/guides/source/action_mailer_basics.textile
+++ b/railties/guides/source/action_mailer_basics.textile
@@ -362,21 +362,14 @@ When using named routes you only need to supply the +:host+:
Email clients have no web context and so paths have no base URL to form complete web addresses. Thus, when using named routes only the "_url" variant makes sense.
-It is also possible to set a default host that will be used in all mailers by setting the +:host+ option in the +ActionMailer::Base.default_url_options+ hash as follows:
+It is also possible to set a default host that will be used in all mailers by setting the :host option as a configuration option in config/application.rb:
-class UserMailer < ActionMailer::Base
- default_url_options[:host] = "example.com"
-
- def welcome_email(user)
- @user = user
- @url = user_url(@user)
- mail(:to => user.email,
- :subject => "Welcome to My Awesome Site")
- end
-end
+config.action_mailer.default_url_options = { :host => "example.com" }
+If you use this setting, you should pass the :only_path => false option when using +url_for+. This will ensure that absolute URLs are generated because the +url_for+ view helper will, by default, generate relative URLs when a :host option isn't explicitly provided.
+
h4. Sending Multipart Emails
Action Mailer will automatically send multipart emails if you have different templates for the same action. So, for our UserMailer example, if you have +welcome_email.text.erb+ and +welcome_email.html.erb+ in +app/views/user_mailer+, Action Mailer will automatically send a multipart email with the HTML and text versions setup as different parts.
--
cgit v1.2.3
From ed5586fa9e2f585d2edeb600ab1c884e419f9f72 Mon Sep 17 00:00:00 2001
From: Matt Burke
Date: Fri, 18 Nov 2011 14:10:17 -0500
Subject: Add config.active_record.identity_map to the configuration guide.
---
railties/guides/source/configuring.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index cd6e7d116e..809948b41e 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -263,6 +263,8 @@ h4. Configuring Active Record
* +config.active_record.whitelist_attributes+ will create an empty whitelist of attributes available for mass-assignment security for all models in your app.
+* +config.active_record.identity_map+ controls whether the identity map is enabled, and is false by default.
+
The MySQL adapter adds one additional configuration option:
* +ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans+ controls whether Active Record will consider all +tinyint(1)+ columns in a MySQL database to be booleans and is true by default.
--
cgit v1.2.3
From 39d2251d8a3e50bf004b6361e0079679466b2280 Mon Sep 17 00:00:00 2001
From: lest
Date: Sat, 19 Nov 2011 19:03:44 +0200
Subject: fix rails plugin new CamelCasedName bug
refs #3684
---
.../rails/plugin_new/plugin_new_generator.rb | 20 ++++++++++++++++----
.../test/generators/plugin_new_generator_test.rb | 6 ++++++
2 files changed, 22 insertions(+), 4 deletions(-)
(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 f5c8ccf940..ff523fc26f 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
@@ -246,8 +246,20 @@ task :default => :test
"rails plugin new #{self.arguments.map(&:usage).join(' ')} [options]"
end
+ def original_name
+ @original_name ||= File.basename(destination_root)
+ end
+
def name
- @name ||= File.basename(destination_root)
+ unless @name
+ # same as ActiveSupport::Inflector#underscore except not replacing '-'
+ @name = original_name.dup
+ @name.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
+ @name.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
+ @name.downcase!
+ end
+
+ @name
end
def camelized
@@ -256,11 +268,11 @@ task :default => :test
def valid_const?
if camelized =~ /^\d/
- raise Error, "Invalid plugin name #{name}. Please give a name which does not start with numbers."
+ raise Error, "Invalid plugin name #{original_name}. Please give a name which does not start with numbers."
elsif RESERVED_NAMES.include?(name)
- raise Error, "Invalid plugin name #{name}. Please give a name which does not match one of the reserved rails words."
+ raise Error, "Invalid plugin name #{original_name}. Please give a name which does not match one of the reserved rails words."
elsif Object.const_defined?(camelized)
- raise Error, "Invalid plugin name #{name}, constant #{camelized} is already in use. Please choose another plugin name."
+ raise Error, "Invalid plugin name #{original_name}, constant #{camelized} is already in use. Please choose another plugin name."
end
end
diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb
index b70f9f4d9c..826eac904e 100644
--- a/railties/test/generators/plugin_new_generator_test.rb
+++ b/railties/test/generators/plugin_new_generator_test.rb
@@ -37,6 +37,12 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
assert_file "things-43/lib/things-43.rb", /module Things43/
end
+ def test_camelcase_plugin_name_underscores_filenames
+ run_generator [File.join(destination_root, "CamelCasedName")]
+ assert_no_file "CamelCasedName/lib/CamelCasedName.rb"
+ assert_file "CamelCasedName/lib/camel_cased_name.rb", /module CamelCasedName/
+ end
+
def test_generating_without_options
run_generator
assert_file "README.rdoc", /Bukkits/
--
cgit v1.2.3
From c220b4d833fcefb4f60fd021875c05e07dfff77d Mon Sep 17 00:00:00 2001
From: lest
Date: Sat, 19 Nov 2011 21:51:37 +0300
Subject: fix warning about instance variable in plugin generator
---
.../generators/rails/plugin_new/plugin_new_generator.rb | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
(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 ff523fc26f..cd7d51e628 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
@@ -251,15 +251,15 @@ task :default => :test
end
def name
- unless @name
+ @name ||= begin
# same as ActiveSupport::Inflector#underscore except not replacing '-'
- @name = original_name.dup
- @name.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
- @name.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
- @name.downcase!
- end
+ underscored = original_name.dup
+ underscored.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
+ underscored.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
+ underscored.downcase!
- @name
+ underscored
+ end
end
def camelized
--
cgit v1.2.3
From 6b4939c3fd22924ee3d906f08fe739d848f80a3d Mon Sep 17 00:00:00 2001
From: James Dean Shepherd
Date: Sun, 20 Nov 2011 02:34:55 +0000
Subject: Added links to the 'Rails Initialization Guide', marked as a work in
progress
---
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 c9a8c4fa5c..a8e12174ed 100644
--- a/railties/guides/source/index.html.erb
+++ b/railties/guides/source/index.html.erb
@@ -134,6 +134,10 @@ Ruby on Rails Guides
<%= guide('Asset Pipeline', 'asset_pipeline.html') do %>
This guide documents the asset pipeline.
<% end %>
+
+<%= guide('The Rails Initialization Process', 'initialization.html', :work_in_progress => true) do %>
+ This guide explains the internals of the Rails initialization process as of Rails 3.1
+<% end %>
Extending Rails
diff --git a/railties/guides/source/layout.html.erb b/railties/guides/source/layout.html.erb
index 4c979888b7..83a17988ab 100644
--- a/railties/guides/source/layout.html.erb
+++ b/railties/guides/source/layout.html.erb
@@ -72,6 +72,7 @@
Rails Command Line Tools and Rake Tasks
Caching with Rails
Asset Pipeline
+ Rails Initialization Process
Extending Rails
The Basics of Creating Rails Plugins
--
cgit v1.2.3
From 5660a16d56bb738979c47bf3dea16a40c2547b16 Mon Sep 17 00:00:00 2001
From: James Dean Shepherd
Date: Sun, 20 Nov 2011 02:36:50 +0000
Subject: Minor grammar, typo & readability fixes for beginning of Rails
Initialization guide
---
railties/guides/source/initialization.textile | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
(limited to 'railties')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 036b356a37..5ae9cf0f2b 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -17,7 +17,7 @@ As of Rails 3, +script/server+ has become +rails server+. This was done to centr
h4. +bin/rails+
-The actual +rails+ command is kept in _bin/rails_ at the and goes like this:
+The actual +rails+ command is kept in _bin/rails_:
#!/usr/bin/env ruby
@@ -31,7 +31,7 @@ rescue LoadError
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.
+This file will attempt to load +rails/cli+. If it cannot find it then +railties/lib+ is added to the load path (+$:+) before retrying.
h4. +railties/lib/rails/cli.rb+
@@ -56,7 +56,7 @@ else
end
-The +rbconfig+ file here is out of Ruby's standard library and provides us with the +RbConfig+ class which contains useful information dependent on how Ruby was compiled. We'll see this in use in +railties/lib/rails/script_rails_loader+.
+The +rbconfig+ file from the Ruby standard library provides us with the +RbConfig+ class which contains detailed information about the Ruby environment, including how Ruby was compiled. We can see this in use in +railties/lib/rails/script_rails_loader+.
require 'pathname'
@@ -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+ constant, we'll see that when we get to the +in_rails_application?+ method.
+The +rails/script_rails_loader+ file uses +RbConfig::Config+ to obtain the +bin_dir+ and +ruby_install_name+ values for the configuration which together form the path to the Ruby interpreter. 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:
@@ -79,7 +79,7 @@ Back in +rails/cli+, the next line is this:
Rails::ScriptRailsLoader.exec_script_rails!
-This method is defined in +rails/script_rails_loader+ like this:
+This method is defined in +rails/script_rails_loader+:
def self.exec_script_rails!
@@ -96,7 +96,7 @@ rescue SystemCallError
end
-This method will first check if the current working directory (+cwd+) is a Rails application or is a subdirectory of one. The way to determine this is defined in the +in_rails_application?+ method like this:
+This method will first check if the current working directory (+cwd+) is a Rails application or a subdirectory of one. This is determined by the +in_rails_application?+ method:
def self.in_rails_application?
@@ -104,7 +104,7 @@ def self.in_rails_application?
end
-The +SCRIPT_RAILS+ constant defined earlier is used here, with +File.exists?+ checking for its presence in the current directory. If this method returns +false+, then +in_rails_application_subdirectory?+ will be used:
+The +SCRIPT_RAILS+ constant defined earlier is used here, with +File.exists?+ checking for its presence in the current directory. If this method returns +false+ then +in_rails_application_subdirectory?+ will be used:
def self.in_rails_application_subdirectory?(path = Pathname.new(Dir.pwd))
@@ -112,17 +112,17 @@ def self.in_rails_application_subdirectory?(path = Pathname.new(Dir.pwd))
end
-This climbs the directory tree until it reaches a path which contains a +script/rails+ file. If a directory is reached which contains this file then this line will run:
+This climbs the directory tree until it reaches a path which contains a +script/rails+ file. If a directory containing this file is reached then this line will run:
exec RUBY, SCRIPT_RAILS, *ARGV if in_rails_application?
-This is effectively the same as doing +ruby script/rails [arguments]+. Where +[arguments]+ at this point in time is simply "server".
+This is effectively the same as running +ruby script/rails [arguments]+, where +[arguments]+ at this point in time is simply "server".
h4. +script/rails+
-This file looks like this:
+This file is as follows:
APP_PATH = File.expand_path('../../config/application', __FILE__)
@@ -130,7 +130,7 @@ require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
-The +APP_PATH+ constant here will be used later in +rails/commands+. The +config/boot+ file that +script/rails+ references is the +config/boot.rb+ file in our application which is responsible for loading Bundler and setting it up.
+The +APP_PATH+ constant will be used later in +rails/commands+. The +config/boot+ file referenced here is the +config/boot.rb+ file in our application which is responsible for loading Bundler and setting it up.
h4. +config/boot.rb+
--
cgit v1.2.3
From 4c872c017b47120b95eb2acf1d3401bd937b0647 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Tue, 22 Nov 2011 00:05:46 +0530
Subject: Remove the -h option to dbconsole which is the shorter form of
--header
This is done since the -h option to dbconsole hides the conventional
-h for help and forces users to use --help to see the usage options for
dbconsole.
---
railties/lib/rails/commands/dbconsole.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties')
diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb
index b0ba76217a..4b0acc9d88 100644
--- a/railties/lib/rails/commands/dbconsole.rb
+++ b/railties/lib/rails/commands/dbconsole.rb
@@ -33,7 +33,7 @@ module Rails
options['mode'] = mode
end
- opt.on("-h", "--header") do |h|
+ opt.on("--header") do |h|
options['header'] = h
end
--
cgit v1.2.3
From a9e8cf78fda696738f63e726796f6232c3751603 Mon Sep 17 00:00:00 2001
From: lest
Date: Mon, 21 Nov 2011 20:13:54 +0300
Subject: add ActionController::Metal#show_detailed_exceptions?
---
railties/lib/rails/application.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties')
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 82fffe86bb..817fa39cab 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -166,7 +166,7 @@ module Rails
middleware.use ::Rack::MethodOverride
middleware.use ::ActionDispatch::RequestId
middleware.use ::Rails::Rack::Logger, config.log_tags # must come after Rack::MethodOverride to properly log overridden methods
- middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local
+ middleware.use ::ActionDispatch::ShowExceptions
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
--
cgit v1.2.3
From 5c61b7230eaa316ce64f4031234b425c35668988 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Tue, 22 Nov 2011 23:14:13 +0530
Subject: Revert "Added links to the 'Rails Initialization Guide', marked as a
work in progress"
This reverts commit 6b4939c3fd22924ee3d906f08fe739d848f80a3d.
Reason: This guide is still incomplete and is not yet reviewed or ready
to go to the index.
---
railties/guides/source/index.html.erb | 4 ----
railties/guides/source/layout.html.erb | 1 -
2 files changed, 5 deletions(-)
(limited to 'railties')
diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb
index a8e12174ed..c9a8c4fa5c 100644
--- a/railties/guides/source/index.html.erb
+++ b/railties/guides/source/index.html.erb
@@ -134,10 +134,6 @@ Ruby on Rails Guides
<%= guide('Asset Pipeline', 'asset_pipeline.html') do %>
This guide documents the asset pipeline.
<% end %>
-
-<%= guide('The Rails Initialization Process', 'initialization.html', :work_in_progress => true) do %>
- This guide explains the internals of the Rails initialization process as of Rails 3.1
-<% end %>
Extending Rails
diff --git a/railties/guides/source/layout.html.erb b/railties/guides/source/layout.html.erb
index 83a17988ab..4c979888b7 100644
--- a/railties/guides/source/layout.html.erb
+++ b/railties/guides/source/layout.html.erb
@@ -72,7 +72,6 @@
Rails Command Line Tools and Rake Tasks
Caching with Rails
Asset Pipeline
- Rails Initialization Process
Extending Rails
The Basics of Creating Rails Plugins
--
cgit v1.2.3
From 05e02deb686fc21f99c2d1dcf3abc987796e0e19 Mon Sep 17 00:00:00 2001
From: Marc-Andre Lafortune
Date: Tue, 22 Nov 2011 15:16:23 -0500
Subject: Make explicit the default media when calling stylesheet_tag and
change the default generators.
---
.../guides/code/getting_started/app/views/layouts/application.html.erb | 2 +-
.../rails/app/templates/app/views/layouts/application.html.erb.tt | 2 +-
.../templates/app/views/layouts/%name%/application.html.erb.tt | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
(limited to 'railties')
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
index 1e1e4b9a99..7fd6b4f516 100644
--- a/railties/guides/code/getting_started/app/views/layouts/application.html.erb
+++ b/railties/guides/code/getting_started/app/views/layouts/application.html.erb
@@ -2,7 +2,7 @@
Blog
- <%= stylesheet_link_tag "application" %>
+ <%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
diff --git a/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt b/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt
index c63d1b6ac5..bba96a7431 100644
--- a/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt
@@ -2,7 +2,7 @@
<%= camelized %>
- <%%= stylesheet_link_tag "application" %>
+ <%%= stylesheet_link_tag "application", :media => "all" %>
<%%= javascript_include_tag "application" %>
<%%= csrf_meta_tags %>
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
index 01550dec2f..bd983fb90f 100644
--- 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
@@ -2,7 +2,7 @@
<%= camelized %>
- <%%= stylesheet_link_tag "<%= name %>/application" %>
+ <%%= stylesheet_link_tag "<%= name %>/application", :media => "all" %>
<%%= javascript_include_tag "<%= name %>/application" %>
<%%= csrf_meta_tags %>
--
cgit v1.2.3
From d78a7026fcd5eb0cd91e3da2a125ddfcf53e7a7a Mon Sep 17 00:00:00 2001
From: Sergey Parizhskiy
Date: Wed, 23 Nov 2011 14:10:30 +0200
Subject: improved code stats calculation, check on multiline comments and
rewrite regexps according to a class naming convention
---
railties/lib/rails/code_statistics.rb | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
(limited to 'railties')
diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/rails/code_statistics.rb
index e6822b75b7..435ea83ad8 100644
--- a/railties/lib/rails/code_statistics.rb
+++ b/railties/lib/rails/code_statistics.rb
@@ -38,11 +38,22 @@ class CodeStatistics #:nodoc:
next unless file_name =~ pattern
f = File.open(directory + "/" + file_name)
-
+ comment_started = false
while line = f.gets
stats["lines"] += 1
- stats["classes"] += 1 if line =~ /class [A-Z]/
- stats["methods"] += 1 if line =~ /def [a-z]/
+ if(comment_started)
+ if line =~ /^=end/
+ comment_started = false
+ end
+ next
+ else
+ if line =~ /^=begin/
+ comment_started = true
+ next
+ end
+ end
+ stats["classes"] += 1 if line =~ /^\s*class\s+[_A-Z]/
+ stats["methods"] += 1 if line =~ /^\s*def\s+[_a-z]/
stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
end
end
--
cgit v1.2.3
From fd86a1b6b068df87164d5763bdcd4a323a1e76f4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Wed, 23 Nov 2011 19:06:45 +0000
Subject: Rely on a public contract between railties instead of accessing
railtie methods directly.
---
railties/lib/rails/application.rb | 4 ++++
railties/lib/rails/engine.rb | 43 +++++++++++++++++++++--------------
railties/lib/rails/railtie.rb | 2 +-
railties/test/railties/engine_test.rb | 6 ++---
4 files changed, 34 insertions(+), 21 deletions(-)
(limited to 'railties')
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 817fa39cab..0b72a7ed84 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -141,6 +141,10 @@ module Rails
self
end
+ def helpers_paths
+ config.helpers_paths
+ end
+
protected
alias :build_middleware_stack :app
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index d652c6b7fe..335a0fb1b5 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -371,20 +371,28 @@ module Rails
self.routes.default_scope = { :module => ActiveSupport::Inflector.underscore(mod.name) }
self.isolated = true
- unless mod.respond_to?(:_railtie)
- name = engine_name
- _railtie = self
+ unless mod.respond_to?(:railtie_namespace)
+ name, railtie = engine_name, self
+
mod.singleton_class.instance_eval do
- define_method(:_railtie) do
- _railtie
- end
+ define_method(:railtie_namespace) { railtie }
unless mod.respond_to?(:table_name_prefix)
- define_method(:table_name_prefix) do
- "#{name}_"
- end
+ define_method(:table_name_prefix) { "#{name}_" }
+ end
+
+ unless mod.respond_to?(:use_relative_model_naming?)
+ class_eval "def use_relative_model_naming?; true; end", __FILE__, __LINE__
+ end
+
+ unless mod.respond_to?(:railtie_helpers_paths)
+ define_method(:railtie_helpers_paths) { railtie.helpers_paths }
+ end
+
+ unless mod.respond_to?(:railtie_routes_url_helpers)
+ define_method(:railtie_routes_url_helpers) { railtie.routes_url_helpers }
end
- end
+ end
end
end
@@ -429,13 +437,6 @@ module Rails
def helpers
@helpers ||= begin
helpers = Module.new
-
- helpers_paths = if config.respond_to?(:helpers_paths)
- config.helpers_paths
- else
- paths["app/helpers"].existent
- end
-
all = ActionController::Base.all_helpers_from_path(helpers_paths)
ActionController::Base.modules_for_helpers(all).each do |mod|
helpers.send(:include, mod)
@@ -444,6 +445,14 @@ module Rails
end
end
+ def helpers_paths
+ paths["app/helpers"].existent
+ end
+
+ def routes_url_helpers
+ routes.url_helpers
+ end
+
def app
@app ||= begin
config.middleware = config.middleware.merge_into(default_middleware_stack)
diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb
index e8fb1f3d98..f0991b99af 100644
--- a/railties/lib/rails/railtie.rb
+++ b/railties/lib/rails/railtie.rb
@@ -196,7 +196,7 @@ module Rails
end
def railtie_namespace
- @railtie_namespace ||= self.class.parents.detect { |n| n.respond_to?(:_railtie) }
+ @railtie_namespace ||= self.class.parents.detect { |n| n.respond_to?(:railtie_namespace) }
end
end
end
diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb
index 22dbcf9644..e8081c977f 100644
--- a/railties/test/railties/engine_test.rb
+++ b/railties/test/railties/engine_test.rb
@@ -323,7 +323,7 @@ module RailtiesTest
assert_equal "bukkits_", Bukkits.table_name_prefix
assert_equal "bukkits", Bukkits::Engine.engine_name
- assert_equal Bukkits._railtie, Bukkits::Engine
+ assert_equal Bukkits.railtie_namespace, Bukkits::Engine
assert ::Bukkits::MyMailer.method_defined?(:foo_path)
assert !::Bukkits::MyMailer.method_defined?(:bar_path)
@@ -467,7 +467,7 @@ module RailtiesTest
assert_nil Rails.application.load_seed
end
- test "using namespace more than once on one module should not overwrite _railtie method" do
+ test "using namespace more than once on one module should not overwrite railtie_namespace method" do
@plugin.write "lib/bukkits.rb", <<-RUBY
module AppTemplate
class Engine < ::Rails::Engine
@@ -484,7 +484,7 @@ module RailtiesTest
boot_rails
- assert_equal AppTemplate._railtie, AppTemplate::Engine
+ assert_equal AppTemplate.railtie_namespace, AppTemplate::Engine
end
test "properly reload routes" do
--
cgit v1.2.3
From 40b19e063592fc30705f17aafe6a458e7b622ff2 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Tue, 22 Nov 2011 23:26:27 +0100
Subject: Allow to change engine's loading priority with config.railties_order=
---
railties/lib/rails/application.rb | 22 +++++
railties/lib/rails/application/configuration.rb | 5 +-
railties/lib/rails/engine.rb | 24 ++++-
railties/test/railties/engine_test.rb | 126 ++++++++++++++++++++++++
4 files changed, 173 insertions(+), 4 deletions(-)
(limited to 'railties')
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 0b72a7ed84..847445d29f 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -127,6 +127,28 @@ module Rails
})
end
+ def ordered_railties
+ @ordered_railties ||= begin
+ order = config.railties_order.map do |railtie|
+ if railtie == :main_app
+ self
+ elsif railtie.respond_to?(:instance)
+ railtie.instance
+ else
+ railtie
+ end
+ end
+
+ all = (railties.all - order)
+ all.push(self) unless all.include?(self)
+ order.push(:all) unless order.include?(:all)
+
+ index = order.index(:all)
+ order[index] = all
+ order.reverse.flatten
+ end
+ end
+
def initializers
Bootstrap.initializers_for(self) +
super +
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index 8f5b28faf8..e95b0f5495 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -10,8 +10,8 @@ module Rails
:dependency_loading, :filter_parameters,
:force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks,
:reload_plugins, :secret_token, :serve_static_assets,
- :ssl_options, :static_cache_control, :session_options,
- :time_zone, :whiny_nils
+ :ssl_options, :static_cache_control, :session_options,
+ :time_zone, :whiny_nils, :railties_order
attr_writer :log_level
attr_reader :encoding
@@ -35,6 +35,7 @@ module Rails
@middleware = app_middleware
@generators = app_generators
@cache_store = [ :file_store, "#{root}/tmp/cache/" ]
+ @railties_order = [:all]
@assets = ActiveSupport::OrderedOptions.new
@assets.enabled = false
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index 335a0fb1b5..5c1af99fe2 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -330,6 +330,17 @@ module Rails
#
# MyEngine::Engine.load_seed
#
+ # == Loading priority
+ #
+ # In order to change engine's priority you can use config.railties_order in main application.
+ # It will affect the priority of loading views, helpers, assets and all the other files
+ # related to engine or application.
+ #
+ # Example:
+ #
+ # # load Blog::Engine with highest priority, followed by application and other railties
+ # config.railties_order = [Blog::Engine, :main_app, :all]
+ #
class Engine < Railtie
autoload :Configuration, "rails/engine/configuration"
autoload :Railties, "rails/engine/railties"
@@ -480,10 +491,19 @@ module Rails
@routes
end
+ def ordered_railties
+ railties.all + [self]
+ end
+
def initializers
initializers = []
- railties.all { |r| initializers += r.initializers }
- initializers += super
+ ordered_railties.each do |r|
+ if r == self
+ initializers += super
+ else
+ initializers += r.initializers
+ end
+ end
initializers
end
diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb
index e8081c977f..400cae98b2 100644
--- a/railties/test/railties/engine_test.rb
+++ b/railties/test/railties/engine_test.rb
@@ -667,6 +667,132 @@ module RailtiesTest
assert_equal expected, methods
end
+ test "setting priority for engines with config.railties_order" do
+ @blog = engine "blog" do |plugin|
+ plugin.write "lib/blog.rb", <<-RUBY
+ module Blog
+ class Engine < ::Rails::Engine
+ end
+ end
+ RUBY
+ end
+
+ @plugin.write "lib/bukkits.rb", <<-RUBY
+ module Bukkits
+ class Engine < ::Rails::Engine
+ isolate_namespace Bukkits
+ end
+ end
+ RUBY
+
+ controller "main", <<-RUBY
+ class MainController < ActionController::Base
+ def foo
+ render :inline => '<%= render :partial => "shared/foo" %>'
+ end
+
+ def bar
+ render :inline => '<%= render :partial => "shared/bar" %>'
+ end
+ end
+ RUBY
+
+ app_file "config/routes.rb", <<-RUBY
+ Rails.application.routes.draw do
+ match "/foo" => "main#foo"
+ match "/bar" => "main#bar"
+ end
+ RUBY
+
+ @plugin.write "app/views/shared/_foo.html.erb", <<-RUBY
+ Bukkit's foo partial
+ RUBY
+
+ app_file "app/views/shared/_foo.html.erb", <<-RUBY
+ App's foo partial
+ RUBY
+
+ @blog.write "app/views/shared/_bar.html.erb", <<-RUBY
+ Blog's bar partial
+ RUBY
+
+ app_file "app/views/shared/_bar.html.erb", <<-RUBY
+ App's bar partial
+ RUBY
+
+ @plugin.write "app/assets/javascripts/foo.js", <<-RUBY
+ // Bukkit's foo js
+ RUBY
+
+ app_file "app/assets/javascripts/foo.js", <<-RUBY
+ // App's foo js
+ RUBY
+
+ @blog.write "app/assets/javascripts/bar.js", <<-RUBY
+ // Blog's bar js
+ RUBY
+
+ app_file "app/assets/javascripts/bar.js", <<-RUBY
+ // App's bar js
+ RUBY
+
+ add_to_config("config.railties_order = [:all, :main_app, Blog::Engine]")
+
+ boot_rails
+ require "#{rails_root}/config/environment"
+
+ get("/foo")
+ assert_equal "Bukkit's foo partial", last_response.body.strip
+
+ get("/bar")
+ assert_equal "App's bar partial", last_response.body.strip
+
+ get("/assets/foo.js")
+ assert_equal "// Bukkit's foo js\n;", last_response.body.strip
+
+ get("/assets/bar.js")
+ assert_equal "// App's bar js\n;", last_response.body.strip
+ end
+
+ test "railties_order adds :all with lowest priority if not given" do
+ @plugin.write "lib/bukkits.rb", <<-RUBY
+ module Bukkits
+ class Engine < ::Rails::Engine
+ end
+ end
+ RUBY
+
+ controller "main", <<-RUBY
+ class MainController < ActionController::Base
+ def foo
+ render :inline => '<%= render :partial => "shared/foo" %>'
+ end
+ end
+ RUBY
+
+ app_file "config/routes.rb", <<-RUBY
+ Rails.application.routes.draw do
+ match "/foo" => "main#foo"
+ end
+ RUBY
+
+ @plugin.write "app/views/shared/_foo.html.erb", <<-RUBY
+ Bukkit's foo partial
+ RUBY
+
+ app_file "app/views/shared/_foo.html.erb", <<-RUBY
+ App's foo partial
+ RUBY
+
+ add_to_config("config.railties_order = [Bukkits::Engine]")
+
+ boot_rails
+ require "#{rails_root}/config/environment"
+
+ get("/foo")
+ assert_equal "Bukkit's foo partial", last_response.body.strip
+ end
+
private
def app
Rails.application
--
cgit v1.2.3
From 98a1717e7c094d011c89ea1ed88673a595af2de8 Mon Sep 17 00:00:00 2001
From: lest
Date: Wed, 23 Nov 2011 23:36:56 +0300
Subject: configuration option to always write cookie
---
.../test/application/middleware/cookies_test.rb | 47 ++++++++++++++++++++++
1 file changed, 47 insertions(+)
create mode 100644 railties/test/application/middleware/cookies_test.rb
(limited to 'railties')
diff --git a/railties/test/application/middleware/cookies_test.rb b/railties/test/application/middleware/cookies_test.rb
new file mode 100644
index 0000000000..13556cbed2
--- /dev/null
+++ b/railties/test/application/middleware/cookies_test.rb
@@ -0,0 +1,47 @@
+require 'isolation/abstract_unit'
+
+module ApplicationTests
+ class CookiesTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def new_app
+ File.expand_path("#{app_path}/../new_app")
+ end
+
+ def setup
+ build_app
+ boot_rails
+ FileUtils.rm_rf("#{app_path}/config/environments")
+ end
+
+ def teardown
+ teardown_app
+ FileUtils.rm_rf(new_app) if File.directory?(new_app)
+ end
+
+ test 'always_write_cookie is true by default in development' do
+ require 'rails'
+ Rails.env = 'development'
+ require "#{app_path}/config/environment"
+ assert_equal true, ActionDispatch::Cookies::CookieJar.always_write_cookie
+ end
+
+ test 'always_write_cookie is false by default in production' do
+ require 'rails'
+ Rails.env = 'production'
+ require "#{app_path}/config/environment"
+ assert_equal false, ActionDispatch::Cookies::CookieJar.always_write_cookie
+ end
+
+ test 'always_write_cookie can be overrided' do
+ add_to_config <<-RUBY
+ config.action_dispatch.always_write_cookie = false
+ RUBY
+
+ require 'rails'
+ Rails.env = 'development'
+ require "#{app_path}/config/environment"
+ assert_equal false, ActionDispatch::Cookies::CookieJar.always_write_cookie
+ end
+ end
+end
--
cgit v1.2.3
From 6da52c617e2a075b9d9e7142786f316d8f2c7930 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Wed, 23 Nov 2011 23:22:46 +0000
Subject: Remove listings from the serialization guide that won't make 3.2.
---
railties/guides/source/serializers.textile | 37 ------------------------------
1 file changed, 37 deletions(-)
(limited to 'railties')
diff --git a/railties/guides/source/serializers.textile b/railties/guides/source/serializers.textile
index 86a5e5ac8d..efc7cbf248 100644
--- a/railties/guides/source/serializers.textile
+++ b/railties/guides/source/serializers.textile
@@ -459,25 +459,6 @@ In other words, if a +PostSerializer+ is trying to serialize comments, it will f
look for +PostSerializer::CommentSerializer+ before falling back to +CommentSerializer+
and finally +comment.as_json+.
-h3. Optional Associations
-
-In some cases, you will want to allow a front-end to decide whether to include associated
-content or not. You can achieve this easily by making an association *optional*.
-
-
-class PostSerializer < ActiveModel::Serializer
- attributes :title. :body
- has_many :comments, :optional => true
-
- # ...
-end
-
-
-If an association is optional, it will not be included unless the request asks for it
-with an +including+ parameter. The +including+ parameter is a comma-separated list of
-optional associations to include. If the +including+ parameter includes an association
-you did not specify in your serializer, it will receive a +401 Forbidden+ response.
-
h3. Overriding the Defaults
h4. Authorization Scope
@@ -500,24 +481,6 @@ which allows you to define a dynamic authorization scope based on the current re
WARNING: If you use different objects as authorization scopes, make sure that they all implement whatever interface you use in your serializers to control what the outputted JSON looks like.
-h4. Parameter to Specify Included Optional Associations
-
-In most cases, you should be able to use the default +including+ parameter to specify
-which optional associations to include. If you are already using that parameter name or
-want to reserve it for some reason, you can specify a different name by using the
-+serialization_includes_param+ class method.
-
-
-class PostsController < ApplicationController
- serialization_includes_param :associations_to_include
-end
-
-
-You can also implement a +serialization_includes+ instance method, which should return an
-Array of optional includes.
-
-WARNING: If you implement +serialization_includes+ and return an invalid association, your user will receive a +401 Forbidden+ exception.
-
h3. Using Serializers Outside of a Request
The serialization API encapsulates the concern of generating a JSON representation of
--
cgit v1.2.3
From 0e7443060b298d080292b18a5888aaf554cce344 Mon Sep 17 00:00:00 2001
From: Michael Pearson
Date: Thu, 24 Nov 2011 10:33:04 +1100
Subject: Add step to getting_started to install JS Runtime.
abstrakt on #rubyonrails found that the guide, when followed step by step,
does fails at the 'rails server' command due to a lacking JS runtime.
---
railties/guides/source/getting_started.textile | 12 ++++++++++++
1 file changed, 12 insertions(+)
(limited to 'railties')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index fde83ae730..55415dd41b 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -250,6 +250,18 @@ $ rails --version
If it says something like "Rails 3.1.1" you are ready to continue.
+h5. Installing a JavaScript Runtime
+
+By default, Rails requires a JavaScript interpreter to compile CoffeeScript to JavaScript.
+
+You can install one by running:
+
+
+# gem install therubyracer
+
+
+Or investigate the list of alternatives give by "ExecJS":https://github.com/sstephenson/execjs.
+
h4. Creating the Blog Application
To begin, open a terminal, navigate to a folder where you have rights to create
--
cgit v1.2.3
From ef38c3089e1269e2b315aff503e61c0b23c95f00 Mon Sep 17 00:00:00 2001
From: Michael Pearson
Date: Thu, 24 Nov 2011 10:59:29 +1100
Subject: Move JS runtime instructions to where the error would be encountered,
remove gem install.
---
railties/guides/source/getting_started.textile | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
(limited to 'railties')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 55415dd41b..5774eba5ae 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -250,18 +250,6 @@ $ rails --version
If it says something like "Rails 3.1.1" you are ready to continue.
-h5. Installing a JavaScript Runtime
-
-By default, Rails requires a JavaScript interpreter to compile CoffeeScript to JavaScript.
-
-You can install one by running:
-
-
-# gem install therubyracer
-
-
-Or investigate the list of alternatives give by "ExecJS":https://github.com/sstephenson/execjs.
-
h4. Creating the Blog Application
To begin, open a terminal, navigate to a folder where you have rights to create
@@ -462,6 +450,12 @@ start a web server on your development machine. You can do this by running:
$ rails server
+TIP: Some environments require that you install a JavaScript runtime to compile
+CoffeeScript to JavaScript and will give you an +execjs+ error the first time
+you run +rails server+. +therubyracer+ and +therubyrhino+ are commonly used
+runtimes for Ruby and JRuby respectively. You can also investigate a list
+of runtimes at "ExecJS":https://github.com/sstephenson/execjs.
+
This will fire up an instance of the WEBrick web server by default (Rails can
also use several other web servers). To see your application in action, open a
browser window and navigate to "http://localhost:3000":http://localhost:3000.
--
cgit v1.2.3
From 510502ee3abfc8feacdf82868013f2f81676c8ff Mon Sep 17 00:00:00 2001
From: rpq
Date: Wed, 23 Nov 2011 23:23:48 -0500
Subject: comma
---
railties/guides/source/active_support_core_extensions.textile | 2 +-
1 file changed, 1 insertion(+), 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 ff6c5f967f..da70f9206d 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -571,7 +571,7 @@ NOTE: Defined in +active_support/core_ext/module/attr_accessor_with_default.rb+.
h5. Internal Attributes
-When you are defining an attribute in a class that is meant to be subclassed name collisions are a risk. That's remarkably important for libraries.
+When you are defining an attribute in a class that is meant to be subclassed, name collisions are a risk. That's remarkably important for libraries.
Active Support defines the macros +attr_internal_reader+, +attr_internal_writer+, and +attr_internal_accessor+. They behave like their Ruby built-in +attr_*+ counterparts, except they name the underlying instance variable in a way that makes collisions less likely.
--
cgit v1.2.3
From a478389b7d70536f1629d080a50a9ecd87c005d0 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Thu, 24 Nov 2011 01:59:01 +0100
Subject: Forgot to add CHANGELOG entry for config.railties_order
---
railties/CHANGELOG.md | 4 ++++
1 file changed, 4 insertions(+)
(limited to 'railties')
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index b05ac21b49..2d7a1db2be 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,5 +1,9 @@
## Rails 3.2.0 (unreleased) ##
+* Allow to change the loading order of railties with `config.railties_order=`. Example:
+
+ config.railties_order = [Blog::Engine, :main_app, :all]
+
* Scaffold returns 204 No Content for API requests without content. This makes scaffold work with jQuery out of the box. *José Valim*
* Updated Rails::Rack::Logger middleware to apply any tags set in config.log_tags to the newly ActiveSupport::TaggedLogging Rails.logger. This makes it easy to tag log lines with debug information like subdomain and request id -- both very helpful in debugging multi-user production applications *DHH*
--
cgit v1.2.3
From 0cd3bf84068dd2b2d0bbb26062f2cdc7093a1b04 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Thu, 24 Nov 2011 01:45:50 +0100
Subject: Allow to display engine's routes when running `rake routes
ENGINES=true`
---
railties/CHANGELOG.md | 7 +++--
railties/lib/rails/application/route_inspector.rb | 37 +++++++++++++++++++++--
railties/lib/rails/tasks/routes.rake | 2 +-
railties/test/application/route_inspect_test.rb | 30 ++++++++++++++++++
4 files changed, 70 insertions(+), 6 deletions(-)
(limited to 'railties')
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 2d7a1db2be..a7afb72562 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,8 +1,11 @@
## Rails 3.2.0 (unreleased) ##
-* Allow to change the loading order of railties with `config.railties_order=`. Example:
+* Added displaying of mounted engine's routes with `rake routes ENGINES=true`. *Piotr Sarnacki*
- config.railties_order = [Blog::Engine, :main_app, :all]
+* Allow to change the loading order of railties with `config.railties_order=`. *Piotr Sarnacki*
+
+ Example:
+ config.railties_order = [Blog::Engine, :main_app, :all]
* Scaffold returns 204 No Content for API requests without content. This makes scaffold work with jQuery out of the box. *José Valim*
diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb
index 8252f21aa7..8da7de2584 100644
--- a/railties/lib/rails/application/route_inspector.rb
+++ b/railties/lib/rails/application/route_inspector.rb
@@ -4,12 +4,23 @@ module Rails
# This class is just used for displaying route information when someone
# executes `rake routes`. People should not use this class.
class RouteInspector # :nodoc:
+ def initialize
+ @engines = ActiveSupport::OrderedHash.new
+ end
+
def format all_routes, filter = nil
if filter
all_routes = all_routes.select{ |route| route.defaults[:controller] == filter }
end
- routes = all_routes.collect do |route|
+ routes = collect_routes(all_routes)
+
+ formatted_routes(routes) +
+ formatted_routes_for_engines
+ end
+
+ def collect_routes(routes)
+ routes = routes.collect do |route|
route_reqs = route.requirements
rack_app = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
@@ -25,12 +36,32 @@ module Rails
verb = route.verb.source.gsub(/[$^]/, '')
- {:name => route.name.to_s, :verb => verb, :path => route.path.spec.to_s, :reqs => reqs}
+ collect_engine_routes(reqs, rack_app)
+
+ {: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
- routes.reject! { |r| r[:path] =~ %r{/rails/info/properties|^/assets} }
+ routes.reject { |r| r[:path] =~ %r{/rails/info/properties|^/assets} }
+ end
+
+ def collect_engine_routes(name, rack_app)
+ return unless rack_app && ENV["ENGINES"] && rack_app.respond_to?(:routes)
+ return if @engines[name]
+
+ routes = rack_app.routes
+ if routes.is_a?(ActionDispatch::Routing::RouteSet)
+ @engines[name] = collect_routes(routes.routes)
+ end
+ end
+
+ def formatted_routes_for_engines
+ @engines.map do |name, routes|
+ ["\nRoutes for #{name}:"] + formatted_routes(routes)
+ end.flatten
+ end
+ def formatted_routes(routes)
name_width = routes.map{ |r| r[:name].length }.max
verb_width = routes.map{ |r| r[:verb].length }.max
path_width = routes.map{ |r| r[:path].length }.max
diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake
index 7dc54144da..df72baef67 100644
--- a/railties/lib/rails/tasks/routes.rake
+++ b/railties/lib/rails/tasks/routes.rake
@@ -1,4 +1,4 @@
-desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
+desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x. Include engine\'s routes with ENGINES=true'
task :routes => :environment do
Rails.application.reload_routes!
all_routes = Rails.application.routes.routes
diff --git a/railties/test/application/route_inspect_test.rb b/railties/test/application/route_inspect_test.rb
index 78980705ed..130d4e52f8 100644
--- a/railties/test/application/route_inspect_test.rb
+++ b/railties/test/application/route_inspect_test.rb
@@ -1,6 +1,7 @@
require 'test/unit'
require 'rails/application/route_inspector'
require 'action_controller'
+require 'rails/engine'
module ApplicationTests
class RouteInspectTest < Test::Unit::TestCase
@@ -9,6 +10,35 @@ module ApplicationTests
@inspector = Rails::Application::RouteInspector.new
end
+ def test_displaying_routes_for_engines
+ ENV["ENGINES"] = "true"
+
+ engine = Class.new(Rails::Engine) do
+ def self.to_s
+ "Blog::Engine"
+ end
+ end
+ engine.routes.draw do
+ get '/cart', :to => 'cart#show'
+ end
+
+ @set.draw do
+ get '/custom/assets', :to => 'custom_assets#show'
+ mount engine => "/blog", :as => "blog"
+ end
+
+ output = @inspector.format @set.routes
+ expected = [
+ "custom_assets GET /custom/assets(.:format) custom_assets#show",
+ " blog /blog Blog::Engine",
+ "\nRoutes for Blog::Engine:",
+ "cart GET /cart(.:format) cart#show"
+ ]
+ assert_equal expected, output
+ ensure
+ ENV["ENGINES"] = nil
+ end
+
def test_cart_inspect
@set.draw do
get '/cart', :to => 'cart#show'
--
cgit v1.2.3
From ebb8ea22f30dc029f4a868a550828443b160f639 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Fri, 25 Nov 2011 09:13:19 +0000
Subject: Add generators for serializers.
---
.../lib/rails/generators/rails/serializer/USAGE | 9 ++++
.../rails/serializer/serializer_generator.rb | 39 ++++++++++++++
.../rails/serializer/templates/serializer.rb | 9 ++++
.../test_unit/serializer/serializer_generator.rb | 13 +++++
.../test_unit/serializer/templates/unit_test.rb | 9 ++++
.../test/generators/serializer_generator_test.rb | 63 ++++++++++++++++++++++
6 files changed, 142 insertions(+)
create mode 100644 railties/lib/rails/generators/rails/serializer/USAGE
create mode 100644 railties/lib/rails/generators/rails/serializer/serializer_generator.rb
create mode 100644 railties/lib/rails/generators/rails/serializer/templates/serializer.rb
create mode 100644 railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb
create mode 100644 railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb
create mode 100644 railties/test/generators/serializer_generator_test.rb
(limited to 'railties')
diff --git a/railties/lib/rails/generators/rails/serializer/USAGE b/railties/lib/rails/generators/rails/serializer/USAGE
new file mode 100644
index 0000000000..a49f7ea1fb
--- /dev/null
+++ b/railties/lib/rails/generators/rails/serializer/USAGE
@@ -0,0 +1,9 @@
+Description:
+ Generates a serializer for the given resource with tests.
+
+Example:
+ `rails generate serializer Account name created_at`
+
+ For TestUnit it creates:
+ Serializer: app/serializers/account_serializer.rb
+ TestUnit: test/unit/account_serializer_test.rb
diff --git a/railties/lib/rails/generators/rails/serializer/serializer_generator.rb b/railties/lib/rails/generators/rails/serializer/serializer_generator.rb
new file mode 100644
index 0000000000..2118906227
--- /dev/null
+++ b/railties/lib/rails/generators/rails/serializer/serializer_generator.rb
@@ -0,0 +1,39 @@
+module Rails
+ module Generators
+ class SerializerGenerator < NamedBase
+ check_class_collision :suffix => "Serializer"
+
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
+
+ class_option :parent, :type => :string, :desc => "The parent class for the generated serializer"
+
+ def create_serializer_file
+ template 'serializer.rb', File.join('app/serializers', class_path, "#{file_name}_serializer.rb")
+ end
+
+ hook_for :test_framework
+
+ private
+
+ def attributes_names
+ attributes.select { |attr| !attr.reference? }.map { |a| a.name.to_sym }
+ end
+
+ def association_names
+ attributes.select { |attr| attr.reference? }.map { |a| a.name.to_sym }
+ end
+
+ def parent_class_name
+ if options[:parent]
+ options[:parent]
+ elsif (n = Rails::Generators.namespace) && n.const_defined?(:ApplicationSerializer)
+ "ApplicationSerializer"
+ elsif Object.const_defined?(:ApplicationSerializer)
+ "ApplicationSerializer"
+ else
+ "ActiveModel::Serializer"
+ end
+ end
+ end
+ end
+end
diff --git a/railties/lib/rails/generators/rails/serializer/templates/serializer.rb b/railties/lib/rails/generators/rails/serializer/templates/serializer.rb
new file mode 100644
index 0000000000..30c058c7e9
--- /dev/null
+++ b/railties/lib/rails/generators/rails/serializer/templates/serializer.rb
@@ -0,0 +1,9 @@
+<% module_namespacing do -%>
+class <%= class_name %>Serializer < <%= parent_class_name %>
+<% if attributes.any? -%> attributes <%= attributes_names.map(&:inspect).join(", ") %>
+<% end -%>
+<% association_names.each do |attribute| -%>
+ has_one :<%= attribute %>
+<% end -%>
+end
+<% end -%>
\ No newline at end of file
diff --git a/railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb b/railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb
new file mode 100644
index 0000000000..533c032c3b
--- /dev/null
+++ b/railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb
@@ -0,0 +1,13 @@
+require 'rails/generators/test_unit'
+
+module TestUnit
+ module Generators
+ class SerializerGenerator < Base
+ check_class_collision :suffix => "SerializerTest"
+
+ def create_test_files
+ template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_serializer_test.rb")
+ end
+ end
+ end
+end
diff --git a/railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb b/railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb
new file mode 100644
index 0000000000..0b1bbdcaa5
--- /dev/null
+++ b/railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+<% module_namespacing do -%>
+class <%= class_name %>SerializerTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
+<% end -%>
diff --git a/railties/test/generators/serializer_generator_test.rb b/railties/test/generators/serializer_generator_test.rb
new file mode 100644
index 0000000000..2afaa65693
--- /dev/null
+++ b/railties/test/generators/serializer_generator_test.rb
@@ -0,0 +1,63 @@
+require 'generators/generators_test_helper'
+require 'rails/generators/rails/serializer/serializer_generator'
+
+class SerializerGeneratorTest < Rails::Generators::TestCase
+ include GeneratorsTestHelper
+ arguments %w(account name:string description:text business:references)
+
+ def test_generates_a_serializer
+ run_generator
+ assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < ActiveModel::Serializer/
+ end
+
+ def test_generates_a_namespaced_serializer
+ run_generator ["admin/account"]
+ assert_file "app/serializers/admin/account_serializer.rb", /class Admin::AccountSerializer < ActiveModel::Serializer/
+ end
+
+ def test_uses_application_serializer_if_one_exists
+ Object.const_set(:ApplicationSerializer, Class.new)
+ run_generator
+ assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < ApplicationSerializer/
+ ensure
+ Object.send :remove_const, :ApplicationSerializer
+ end
+
+ def test_uses_namespace_application_serializer_if_one_exists
+ Object.const_set(:SerializerNamespace, Module.new)
+ SerializerNamespace.const_set(:ApplicationSerializer, Class.new)
+ Rails::Generators.namespace = SerializerNamespace
+ run_generator
+ assert_file "app/serializers/serializer_namespace/account_serializer.rb",
+ /module SerializerNamespace\n class AccountSerializer < ApplicationSerializer/
+ ensure
+ Object.send :remove_const, :SerializerNamespace
+ Rails::Generators.namespace = nil
+ end
+
+ def test_uses_given_parent
+ Object.const_set(:ApplicationSerializer, Class.new)
+ run_generator ["Account", "--parent=MySerializer"]
+ assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < MySerializer/
+ ensure
+ Object.send :remove_const, :ApplicationSerializer
+ end
+
+ def test_generates_attributes_and_associations
+ run_generator
+ assert_file "app/serializers/account_serializer.rb" do |serializer|
+ assert_match(/^ attributes :name, :description$/, serializer)
+ assert_match(/^ has_one :business$/, serializer)
+ end
+ end
+
+ def test_with_no_attributes_does_not_add_extra_space
+ run_generator ["account"]
+ assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < ActiveModel::Serializer\nend/
+ end
+
+ def test_invokes_default_test_framework
+ run_generator
+ assert_file "test/unit/account_serializer_test.rb", /class AccountSerializerTest < ActiveSupport::TestCase/
+ end
+end
--
cgit v1.2.3
From 6d9f9b3b05f6ea55aad9853888912bcca4d81c9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Fri, 25 Nov 2011 09:17:32 +0000
Subject: Add a hook for serializers in the scaffold generator (off for now).
---
railties/lib/rails/generators.rb | 4 +++-
.../lib/rails/generators/rails/scaffold/scaffold_generator.rb | 1 +
railties/test/generators/scaffold_generator_test.rb | 9 +++++++++
3 files changed, 13 insertions(+), 1 deletion(-)
(limited to 'railties')
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 27f8d13ce8..f1ca9080ff 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -33,7 +33,8 @@ module Rails
:stylesheets => '-y',
:stylesheet_engine => '-se',
:template_engine => '-e',
- :test_framework => '-t'
+ :test_framework => '-t',
+ :serializer => '-z'
},
:test_unit => {
@@ -58,6 +59,7 @@ module Rails
:performance_tool => nil,
:resource_controller => :controller,
:scaffold_controller => :scaffold_controller,
+ :serializer => false,
:stylesheets => true,
:stylesheet_engine => :css,
:test_framework => false,
diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
index 03a61a035e..7353a67c83 100644
--- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
+++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
@@ -10,6 +10,7 @@ module Rails
class_option :stylesheet_engine, :desc => "Engine for Stylesheets"
hook_for :scaffold_controller, :required => true
+ hook_for :serializer
hook_for :assets do |assets|
invoke assets, [controller_name]
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index 2db8090621..2e8b03fbef 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -264,6 +264,15 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
assert_file "app/assets/stylesheets/posts.css"
end
+ def test_scaffold_also_generators_serializer
+ run_generator [ "posts", "name:string", "author:references", "--serializer" ]
+ assert_file "app/serializers/post_serializer.rb" do |serializer|
+ assert_match /class PostSerializer < ActiveModel::Serializer/, serializer
+ assert_match /^ attributes :name$/, serializer
+ assert_match /^ has_one :author$/, serializer
+ end
+ end
+
def test_scaffold_generator_outputs_error_message_on_missing_attribute_type
run_generator ["post", "title", "body:text", "author"]
--
cgit v1.2.3
From c8d7291b6b5736562b112007365317648ae2b790 Mon Sep 17 00:00:00 2001
From: ganesh
Date: Fri, 25 Nov 2011 14:55:28 +0530
Subject: Added tests for #3751
---
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 b26839644e..184cb2866b 100644
--- a/railties/lib/rails/generators/actions.rb
+++ b/railties/lib/rails/generators/actions.rb
@@ -68,7 +68,7 @@ module Rails
end
in_root do
- str = "gem #{parts.join(", ")}\n"
+ str = "\ngem #{parts.join(", ")}\n"
str = " " + str if @in_group
append_file "Gemfile", str, :verbose => false
end
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb
index 51fa2fe16f..917b196777 100644
--- a/railties/test/generators/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -113,7 +113,7 @@ class ActionsTest < Rails::Generators::TestCase
gem 'fakeweb'
end
- assert_file 'Gemfile', /\ngroup :development, :test do\n gem "rspec-rails"\nend\n\ngroup :test do\n gem "fakeweb"\nend/
+ assert_file 'Gemfile', /\ngroup :development, :test do\n \ngem "rspec-rails"\nend\n\ngroup :test do\n \ngem "fakeweb"\nend/
end
def test_environment_should_include_data_in_environment_initializer_block
--
cgit v1.2.3
From 696d01f7f4a8ed787924a41cce6df836cd73c46f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Fri, 25 Nov 2011 09:49:54 +0000
Subject: Add docs to serializers. Update CHANGELOGs.
---
railties/CHANGELOG.md | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
(limited to 'railties')
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index b05ac21b49..b055b051be 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,20 +1,22 @@
## Rails 3.2.0 (unreleased) ##
+* Add a serializer generator and add a hook for it in the scaffold generators *José Valim*
+
* Scaffold returns 204 No Content for API requests without content. This makes scaffold work with jQuery out of the box. *José Valim*
-* Updated Rails::Rack::Logger middleware to apply any tags set in config.log_tags to the newly ActiveSupport::TaggedLogging Rails.logger. This makes it easy to tag log lines with debug information like subdomain and request id -- both very helpful in debugging multi-user production applications *DHH*
+* Update Rails::Rack::Logger middleware to apply any tags set in config.log_tags to the newly ActiveSupport::TaggedLogging Rails.logger. This makes it easy to tag log lines with debug information like subdomain and request id -- both very helpful in debugging multi-user production applications *DHH*
* Default options to `rails new` can be set in ~/.railsrc *Guillermo Iguaran*
-* Added destroy alias to Rails engines. *Guillermo Iguaran*
+* Add destroy alias to Rails engines *Guillermo Iguaran*
-* Added destroy alias for Rails command line. This allows the following: `rails d model post`. *Andrey Ognevsky*
+* Add 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*
+* Remove old plugin generator (`rails generate plugin`) in favor of `rails plugin new` command *Guillermo Iguaran*
-* Removed old 'config.paths.app.controller' API in favor of 'config.paths["app/controller"]' API. *Guillermo Iguaran*
+* Remove old 'config.paths.app.controller' API in favor of 'config.paths["app/controller"]' API *Guillermo Iguaran*
* Rails 3.1.1
--
cgit v1.2.3
From cd9d28d6fdff6819dac3c6643fe882eb568b5a39 Mon Sep 17 00:00:00 2001
From: lest
Date: Thu, 24 Nov 2011 22:37:48 +0300
Subject: middlewares should use logger from env
---
railties/lib/rails/application.rb | 3 ++-
railties/test/application/configuration_test.rb | 1 +
2 files changed, 3 insertions(+), 1 deletion(-)
(limited to 'railties')
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 847445d29f..25ff74506a 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -123,7 +123,8 @@ module Rails
@env_config ||= super.merge({
"action_dispatch.parameter_filter" => config.filter_parameters,
"action_dispatch.secret_token" => config.secret_token,
- "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions
+ "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
+ "action_dispatch.logger" => Rails.logger
})
end
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index f356805d6e..f37a024a0b 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -524,6 +524,7 @@ module ApplicationTests
assert_equal app.env_config['action_dispatch.parameter_filter'], app.config.filter_parameters
assert_equal app.env_config['action_dispatch.secret_token'], app.config.secret_token
assert_equal app.env_config['action_dispatch.show_exceptions'], app.config.action_dispatch.show_exceptions
+ assert_equal app.env_config['action_dispatch.logger'], Rails.logger
end
end
end
--
cgit v1.2.3
From c9bb099318dd3bc293a6cb4672333147c1cce4b9 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Fri, 25 Nov 2011 12:42:11 +0100
Subject: Display mounted engines in `rake routes` by default
---
railties/CHANGELOG.md | 2 +-
railties/lib/rails/application/route_inspector.rb | 2 +-
railties/test/application/route_inspect_test.rb | 4 ----
3 files changed, 2 insertions(+), 6 deletions(-)
(limited to 'railties')
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 25d45d886c..1b89bfa6f9 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,6 +1,6 @@
## Rails 3.2.0 (unreleased) ##
-* Add displaying of mounted engine's routes with `rake routes ENGINES=true` *Piotr Sarnacki*
+* Display mounted engine's routes in `rake routes`. *Piotr Sarnacki*
* Allow to change the loading order of railties with `config.railties_order=` *Piotr Sarnacki*
diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb
index 8da7de2584..26652a8e5e 100644
--- a/railties/lib/rails/application/route_inspector.rb
+++ b/railties/lib/rails/application/route_inspector.rb
@@ -46,7 +46,7 @@ module Rails
end
def collect_engine_routes(name, rack_app)
- return unless rack_app && ENV["ENGINES"] && rack_app.respond_to?(:routes)
+ return unless rack_app && rack_app.respond_to?(:routes)
return if @engines[name]
routes = rack_app.routes
diff --git a/railties/test/application/route_inspect_test.rb b/railties/test/application/route_inspect_test.rb
index 130d4e52f8..2ad5ee6c4c 100644
--- a/railties/test/application/route_inspect_test.rb
+++ b/railties/test/application/route_inspect_test.rb
@@ -11,8 +11,6 @@ module ApplicationTests
end
def test_displaying_routes_for_engines
- ENV["ENGINES"] = "true"
-
engine = Class.new(Rails::Engine) do
def self.to_s
"Blog::Engine"
@@ -35,8 +33,6 @@ module ApplicationTests
"cart GET /cart(.:format) cart#show"
]
assert_equal expected, output
- ensure
- ENV["ENGINES"] = nil
end
def test_cart_inspect
--
cgit v1.2.3
From 8ff8fa5e5fd9a615f2c63f809a2747a55cd4da15 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Fri, 25 Nov 2011 12:54:39 +0100
Subject: I suck, forgot to also change rake's task description
---
railties/lib/rails/tasks/routes.rake | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties')
diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake
index df72baef67..7dc54144da 100644
--- a/railties/lib/rails/tasks/routes.rake
+++ b/railties/lib/rails/tasks/routes.rake
@@ -1,4 +1,4 @@
-desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x. Include engine\'s routes with ENGINES=true'
+desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
task :routes => :environment do
Rails.application.reload_routes!
all_routes = Rails.application.routes.routes
--
cgit v1.2.3
From 95e9b5fbfd87b81bf2d2b16a6df6d9ddbfdb686d Mon Sep 17 00:00:00 2001
From: John Donahue
Date: Fri, 25 Nov 2011 09:06:14 -0800
Subject: Updating newline fix to maintain existing linebreaks and indentation
and test for b/eol on inserts
---
railties/lib/rails/generators/actions.rb | 7 ++++---
railties/test/generators/actions_test.rb | 10 ++++++----
2 files changed, 10 insertions(+), 7 deletions(-)
(limited to 'railties')
diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb
index 184cb2866b..ca93f9ef9d 100644
--- a/railties/lib/rails/generators/actions.rb
+++ b/railties/lib/rails/generators/actions.rb
@@ -68,8 +68,9 @@ module Rails
end
in_root do
- str = "\ngem #{parts.join(", ")}\n"
+ str = "gem #{parts.join(", ")}"
str = " " + str if @in_group
+ str = "\n" + str
append_file "Gemfile", str, :verbose => false
end
end
@@ -87,13 +88,13 @@ module Rails
log :gemfile, "group #{name}"
in_root do
- append_file "Gemfile", "\ngroup #{name} do\n", :force => true
+ append_file "Gemfile", "\ngroup #{name} do", :force => true
@in_group = true
instance_eval(&block)
@in_group = false
- append_file "Gemfile", "end\n", :force => true
+ append_file "Gemfile", "\nend\n", :force => true
end
end
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb
index 917b196777..c1fd6a38f1 100644
--- a/railties/test/generators/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -95,11 +95,13 @@ class ActionsTest < Rails::Generators::TestCase
def test_gem_should_insert_on_separate_lines
run_generator
+ File.open('Gemfile', 'a') {|f| f.write('# Some content...') }
+
action :gem, 'rspec'
action :gem, 'rspec-rails'
- assert_file 'Gemfile', /gem "rspec"$/
- assert_file 'Gemfile', /gem "rspec-rails"$/
+ assert_file 'Gemfile', /^gem "rspec"$/
+ assert_file 'Gemfile', /^gem "rspec-rails"$/
end
def test_gem_group_should_wrap_gems_in_a_group
@@ -112,8 +114,8 @@ class ActionsTest < Rails::Generators::TestCase
action :gem_group, :test do
gem 'fakeweb'
end
-
- assert_file 'Gemfile', /\ngroup :development, :test do\n \ngem "rspec-rails"\nend\n\ngroup :test do\n \ngem "fakeweb"\nend/
+
+ assert_file 'Gemfile', /\ngroup :development, :test do\n gem "rspec-rails"\nend\n\ngroup :test do\n gem "fakeweb"\nend/
end
def test_environment_should_include_data_in_environment_initializer_block
--
cgit v1.2.3
From 0a4035b12a6c59253cb60f9e3456513c6a6a9d33 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Fri, 25 Nov 2011 19:29:39 +0000
Subject: Revert the serializers API as other alternatives are now also under
discussion
---
railties/CHANGELOG.md | 2 -
railties/guides/source/serializers.textile | 563 ---------------------
railties/lib/rails/generators.rb | 4 +-
.../rails/scaffold/scaffold_generator.rb | 1 -
.../lib/rails/generators/rails/serializer/USAGE | 9 -
.../rails/serializer/serializer_generator.rb | 39 --
.../rails/serializer/templates/serializer.rb | 9 -
.../test_unit/serializer/serializer_generator.rb | 13 -
.../test_unit/serializer/templates/unit_test.rb | 9 -
.../test/generators/scaffold_generator_test.rb | 9 -
.../test/generators/serializer_generator_test.rb | 63 ---
11 files changed, 1 insertion(+), 720 deletions(-)
delete mode 100644 railties/guides/source/serializers.textile
delete mode 100644 railties/lib/rails/generators/rails/serializer/USAGE
delete mode 100644 railties/lib/rails/generators/rails/serializer/serializer_generator.rb
delete mode 100644 railties/lib/rails/generators/rails/serializer/templates/serializer.rb
delete mode 100644 railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb
delete mode 100644 railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb
delete mode 100644 railties/test/generators/serializer_generator_test.rb
(limited to 'railties')
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 1b89bfa6f9..6b0be4c096 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -7,8 +7,6 @@
Example:
config.railties_order = [Blog::Engine, :main_app, :all]
-* Add a serializer generator and add a hook for it in the scaffold generators *José Valim*
-
* Scaffold returns 204 No Content for API requests without content. This makes scaffold work with jQuery out of the box. *José Valim*
* Update Rails::Rack::Logger middleware to apply any tags set in config.log_tags to the newly ActiveSupport::TaggedLogging Rails.logger. This makes it easy to tag log lines with debug information like subdomain and request id -- both very helpful in debugging multi-user production applications *DHH*
diff --git a/railties/guides/source/serializers.textile b/railties/guides/source/serializers.textile
deleted file mode 100644
index efc7cbf248..0000000000
--- a/railties/guides/source/serializers.textile
+++ /dev/null
@@ -1,563 +0,0 @@
-h2. Rails Serializers
-
-This guide describes how to use Active Model serializers to build non-trivial JSON services in Rails. By reading this guide, you will learn:
-
-* When to use the built-in Active Model serialization
-* When to use a custom serializer for your models
-* How to use serializers to encapsulate authorization concerns
-* How to create serializer templates to describe the application-wide structure of your serialized JSON
-* How to build resources not backed by a single database table for use with JSON services
-
-This guide covers an intermediate topic and assumes familiarity with Rails conventions. It is suitable for applications that expose a
-JSON API that may return different results based on the authorization status of the user.
-
-endprologue.
-
-h3. Serialization
-
-By default, Active Record objects can serialize themselves into JSON by using the `to_json` method. This method takes a series of additional
-parameter to control which properties and associations Rails should include in the serialized output.
-
-When building a web application that uses JavaScript to retrieve JSON data from the server, this mechanism has historically been the primary
-way that Rails developers prepared their responses. This works great for simple cases, as the logic for serializing an Active Record object
-is neatly encapsulated in Active Record itself.
-
-However, this solution quickly falls apart in the face of serialization requirements based on authorization. For instance, a web service
-may choose to expose additional information about a resource only if the user is entitled to access it. In addition, a JavaScript front-end
-may want information that is not neatly described in terms of serializing a single Active Record object, or in a different format than.
-
-In addition, neither the controller nor the model seems like the correct place for logic that describes how to serialize an model object
-*for the current user*.
-
-Serializers solve these problems by encapsulating serialization in an object designed for this purpose. If the default +to_json+ semantics,
-with at most a few configuration options serve your needs, by all means continue to use the built-in +to_json+. If you find yourself doing
-hash-driven-development in your controllers, juggling authorization logic and other concerns, serializers are for you!
-
-h3. The Most Basic Serializer
-
-A basic serializer is a simple Ruby object named after the model class it is serializing.
-
-
-class PostSerializer
- def initialize(post, scope)
- @post, @scope = post, scope
- end
-
- def as_json
- { post: { title: @post.name, body: @post.body } }
- end
-end
-
-
-A serializer is initialized with two parameters: the model object it should serialize and an authorization scope. By default, the
-authorization scope is the current user (+current_user+) but you can use a different object if you want. The serializer also
-implements an +as_json+ method, which returns a Hash that will be sent to the JSON encoder.
-
-Rails will transparently use your serializer when you use +render :json+ in your controller.
-
-
-class PostsController < ApplicationController
- def show
- @post = Post.find(params[:id])
- render json: @post
- end
-end
-
-
-Because +respond_with+ uses +render :json+ under the hood for JSON requests, Rails will automatically use your serializer when
-you use +respond_with+ as well.
-
-h4. +serializable_hash+
-
-In general, you will want to implement +serializable_hash+ and +as_json+ to allow serializers to embed associated content
-directly. The easiest way to implement these two methods is to have +as_json+ call +serializable_hash+ and insert the root.
-
-
-class PostSerializer
- def initialize(post, scope)
- @post, @scope = post, scope
- end
-
- def serializable_hash
- { title: @post.name, body: @post.body }
- end
-
- def as_json
- { post: serializable_hash }
- end
-end
-
-
-h4. Authorization
-
-Let's update our serializer to include the email address of the author of the post, but only if the current user has superuser
-access.
-
-
-class PostSerializer
- def initialize(post, scope)
- @post, @scope = post, scope
- end
-
- def as_json
- { post: serializable_hash }
- end
-
- def serializable_hash
- hash = post
- hash.merge!(super_data) if super?
- hash
- end
-
-private
- def post
- { title: @post.name, body: @post.body }
- end
-
- def super_data
- { email: @post.email }
- end
-
- def super?
- @scope.superuser?
- end
-end
-
-
-h4. Testing
-
-One benefit of encapsulating our objects this way is that it becomes extremely straight-forward to test the serialization
-logic in isolation.
-
-
-require "ostruct"
-
-class PostSerializerTest < ActiveSupport::TestCase
- # For now, we use a very simple authorization structure. These tests will need
- # refactoring if we change that.
- plebe = OpenStruct.new(super?: false)
- god = OpenStruct.new(super?: true)
-
- post = OpenStruct.new(title: "Welcome to my blog!", body: "Blah blah blah", email: "tenderlove@gmail.com")
-
- test "a regular user sees just the title and body" do
- json = PostSerializer.new(post, plebe).to_json
- hash = JSON.parse(json)
-
- assert_equal post.title, hash.delete("title")
- assert_equal post.body, hash.delete("body")
- assert_empty hash
- end
-
- test "a superuser sees the title, body and email" do
- json = PostSerializer.new(post, god).to_json
- hash = JSON.parse(json)
-
- assert_equal post.title, hash.delete("title")
- assert_equal post.body, hash.delete("body")
- assert_equal post.email, hash.delete("email")
- assert_empty hash
- end
-end
-
-
-It's important to note that serializer objects define a clear interface specifically for serializing an existing object.
-In this case, the serializer expects to receive a post object with +name+, +body+ and +email+ attributes and an authorization
-scope with a +super?+ method.
-
-By defining a clear interface, it's must easier to ensure that your authorization logic is behaving correctly. In this case,
-the serializer doesn't need to concern itself with how the authorization scope decides whether to set the +super?+ flag, just
-whether it is set. In general, you should document these requirements in your serializer files and programatically via tests.
-The documentation library +YARD+ provides excellent tools for describing this kind of requirement:
-
-
-class PostSerializer
- # @param [~body, ~title, ~email] post the post to serialize
- # @param [~super] scope the authorization scope for this serializer
- def initialize(post, scope)
- @post, @scope = post, scope
- end
-
- # ...
-end
-
-
-h3. Attribute Sugar
-
-To simplify this process for a number of common cases, Rails provides a default superclass named +ActiveModel::Serializer+
-that you can use to implement your serializers.
-
-For example, you will sometimes want to simply include a number of existing attributes from the source model into the outputted
-JSON. In the above example, the +title+ and +body+ attributes were always included in the JSON. Let's see how to use
-+ActiveModel::Serializer+ to simplify our post serializer.
-
-
-class PostSerializer < ActiveModel::Serializer
- attributes :title, :body
-
- def initialize(post, scope)
- @post, @scope = post, scope
- end
-
- def serializable_hash
- hash = attributes
- hash.merge!(super_data) if super?
- hash
- end
-
-private
- def super_data
- { email: @post.email }
- end
-
- def super?
- @scope.superuser?
- end
-end
-
-
-First, we specified the list of included attributes at the top of the class. This will create an instance method called
-+attributes+ that extracts those attributes from the post model.
-
-NOTE: Internally, +ActiveModel::Serializer+ uses +read_attribute_for_serialization+, which defaults to +read_attribute+, which defaults to +send+. So if you're rolling your own models for use with the serializer, you can use simple Ruby accessors for your attributes if you like.
-
-Next, we use the attributes methood in our +serializable_hash+ method, which allowed us to eliminate the +post+ method we hand-rolled
-earlier. We could also eliminate the +as_json+ method, as +ActiveModel::Serializer+ provides a default +as_json+ method for
-us that calls our +serializable_hash+ method and inserts a root. But we can go a step further!
-
-
-class PostSerializer < ActiveModel::Serializer
- attributes :title, :body
-
-private
- def attributes
- hash = super
- hash.merge!(email: post.email) if super?
- hash
- end
-
- def super?
- @scope.superuser?
- end
-end
-
-
-The superclass provides a default +initialize+ method as well as a default +serializable_hash+ method, which uses
-+attributes+. We can call +super+ to get the hash based on the attributes we declared, and then add in any additional
-attributes we want to use.
-
-NOTE: +ActiveModel::Serializer+ will create an accessor matching the name of the current class for the resource you pass in. In this case, because we have defined a PostSerializer, we can access the resource with the +post+ accessor.
-
-h3. Associations
-
-In most JSON APIs, you will want to include associated objects with your serialized object. In this case, let's include
-the comments with the current post.
-
-
-class PostSerializer < ActiveModel::Serializer
- attributes :title, :body
- has_many :comments
-
-private
- def attributes
- hash = super
- hash.merge!(email: post.email) if super?
- hash
- end
-
- def super?
- @scope.superuser?
- end
-end
-
-
-The default +serializable_hash+ method will include the comments as embedded objects inside the post.
-
-
-{
- post: {
- title: "Hello Blog!",
- body: "This is my first post. Isn't it fabulous!",
- comments: [
- {
- title: "Awesome",
- body: "Your first post is great"
- }
- ]
- }
-}
-
-
-Rails uses the same logic to generate embedded serializations as it does when you use +render :json+. In this case,
-because you didn't define a +CommentSerializer+, Rails used the default +as_json+ on your comment object.
-
-If you define a serializer, Rails will automatically instantiate it with the existing authorization scope.
-
-
-class CommentSerializer
- def initialize(comment, scope)
- @comment, @scope = comment, scope
- end
-
- def serializable_hash
- { title: @comment.title }
- end
-
- def as_json
- { comment: serializable_hash }
- end
-end
-
-
-If we define the above comment serializer, the outputted JSON will change to:
-
-
-{
- post: {
- title: "Hello Blog!",
- body: "This is my first post. Isn't it fabulous!",
- comments: [{ title: "Awesome" }]
- }
-}
-
-
-Let's imagine that our comment system allows an administrator to kill a comment, and we only want to allow
-users to see the comments they're entitled to see. By default, +has_many :comments+ will simply use the
-+comments+ accessor on the post object. We can override the +comments+ accessor to limit the comments used
-to just the comments we want to allow for the current user.
-
-
-class PostSerializer < ActiveModel::Serializer
- attributes :title. :body
- has_many :comments
-
-private
- def attributes
- hash = super
- hash.merge!(email: post.email) if super?
- hash
- end
-
- def comments
- post.comments_for(scope)
- end
-
- def super?
- @scope.superuser?
- end
-end
-
-
-+ActiveModel::Serializer+ will still embed the comments, but this time it will use just the comments
-for the current user.
-
-NOTE: The logic for deciding which comments a user should see still belongs in the model layer. In general, you should encapsulate concerns that require making direct Active Record queries in scopes or public methods on your models.
-
-h3. Customizing Associations
-
-Not all front-ends expect embedded documents in the same form. In these cases, you can override the
-default +serializable_hash+, and use conveniences provided by +ActiveModel::Serializer+ to avoid having to
-build up the hash manually.
-
-For example, let's say our front-end expects the posts and comments in the following format:
-
-
-{
- post: {
- id: 1
- title: "Hello Blog!",
- body: "This is my first post. Isn't it fabulous!",
- comments: [1,2]
- },
- comments: [
- {
- id: 1
- title: "Awesome",
- body: "Your first post is great"
- },
- {
- id: 2
- title: "Not so awesome",
- body: "Why is it so short!"
- }
- ]
-}
-
-
-We could achieve this with a custom +as_json+ method. We will also need to define a serializer for comments.
-
-
-class CommentSerializer < ActiveModel::Serializer
- attributes :id, :title, :body
-
- # define any logic for dealing with authorization-based attributes here
-end
-
-class PostSerializer < ActiveModel::Serializer
- attributes :title, :body
- has_many :comments
-
- def as_json
- { post: serializable_hash }.merge!(associations)
- end
-
- def serializable_hash
- post_hash = attributes
- post_hash.merge!(association_ids)
- post_hash
- end
-
-private
- def attributes
- hash = super
- hash.merge!(email: post.email) if super?
- hash
- end
-
- def comments
- post.comments_for(scope)
- end
-
- def super?
- @scope.superuser?
- end
-end
-
-
-Here, we used two convenience methods: +associations+ and +association_ids+. The first,
-+associations+, creates a hash of all of the define associations, using their defined
-serializers. The second, +association_ids+, generates a hash whose key is the association
-name and whose value is an Array of the association's keys.
-
-The +association_ids+ helper will use the overridden version of the association, so in
-this case, +association_ids+ will only include the ids of the comments provided by the
-+comments+ method.
-
-h3. Special Association Serializers
-
-So far, associations defined in serializers use either the +as_json+ method on the model
-or the defined serializer for the association type. Sometimes, you may want to serialize
-associated models differently when they are requested as part of another resource than
-when they are requested on their own.
-
-For instance, we might want to provide the full comment when it is requested directly,
-but only its title when requested as part of the post. To achieve this, you can define
-a serializer for associated objects nested inside the main serializer.
-
-
-class PostSerializer < ActiveModel::Serializer
- class CommentSerializer < ActiveModel::Serializer
- attributes :id, :title
- end
-
- # same as before
- # ...
-end
-
-
-In other words, if a +PostSerializer+ is trying to serialize comments, it will first
-look for +PostSerializer::CommentSerializer+ before falling back to +CommentSerializer+
-and finally +comment.as_json+.
-
-h3. Overriding the Defaults
-
-h4. Authorization Scope
-
-By default, the authorization scope for serializers is +:current_user+. This means
-that when you call +render json: @post+, the controller will automatically call
-its +current_user+ method and pass that along to the serializer's initializer.
-
-If you want to change that behavior, simply use the +serialization_scope+ class
-method.
-
-
-class PostsController < ApplicationController
- serialization_scope :current_app
-end
-
-
-You can also implement an instance method called (no surprise) +serialization_scope+,
-which allows you to define a dynamic authorization scope based on the current request.
-
-WARNING: If you use different objects as authorization scopes, make sure that they all implement whatever interface you use in your serializers to control what the outputted JSON looks like.
-
-h3. Using Serializers Outside of a Request
-
-The serialization API encapsulates the concern of generating a JSON representation of
-a particular model for a particular user. As a result, you should be able to easily use
-serializers, whether you define them yourself or whether you use +ActiveModel::Serializer+
-outside a request.
-
-For instance, if you want to generate the JSON representation of a post for a user outside
-of a request:
-
-
-user = get_user # some logic to get the user in question
-PostSerializer.new(post, user).to_json # reliably generate JSON output
-
-
-If you want to generate JSON for an anonymous user, you should be able to use whatever
-technique you use in your application to generate anonymous users outside of a request.
-Typically, that means creating a new user and not saving it to the database:
-
-
-user = User.new # create a new anonymous user
-PostSerializer.new(post, user).to_json
-
-
-In general, the better you encapsulate your authorization logic, the more easily you
-will be able to use the serializer outside of the context of a request. For instance,
-if you use an authorization library like Cancan, which uses a uniform +user.can?(action, model)+,
-the authorization interface can very easily be replaced by a plain Ruby object for
-testing or usage outside the context of a request.
-
-h3. Collections
-
-So far, we've talked about serializing individual model objects. By default, Rails
-will serialize collections, including when using the +associations+ helper, by
-looping over each element of the collection, calling +serializable_hash+ on the element,
-and then grouping them by their type (using the plural version of their class name
-as the root).
-
-For example, an Array of post objects would serialize as:
-
-
-{
- posts: [
- {
- title: "FIRST POST!",
- body: "It's my first pooooost"
- },
- { title: "Second post!",
- body: "Zomg I made it to my second post"
- }
- ]
-}
-
-
-If you want to change the behavior of serialized Arrays, you need to create
-a custom Array serializer.
-
-
-class ArraySerializer < ActiveModel::ArraySerializer
- def serializable_array
- serializers.map do |serializer|
- serializer.serializable_hash
- end
- end
-
- def as_json
- hash = { root => serializable_array }
- hash.merge!(associations)
- hash
- end
-end
-
-
-When generating embedded associations using the +associations+ helper inside a
-regular serializer, it will create a new ArraySerializer
with the
-associated content and call its +serializable_array+ method. In this case, those
-embedded associations will not recursively include associations.
-
-When generating an Array using +render json: posts+, the controller will invoke
-the +as_json+ method, which will include its associations and its root.
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index f1ca9080ff..27f8d13ce8 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -33,8 +33,7 @@ module Rails
:stylesheets => '-y',
:stylesheet_engine => '-se',
:template_engine => '-e',
- :test_framework => '-t',
- :serializer => '-z'
+ :test_framework => '-t'
},
:test_unit => {
@@ -59,7 +58,6 @@ module Rails
:performance_tool => nil,
:resource_controller => :controller,
:scaffold_controller => :scaffold_controller,
- :serializer => false,
:stylesheets => true,
:stylesheet_engine => :css,
:test_framework => false,
diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
index 7353a67c83..03a61a035e 100644
--- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
+++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
@@ -10,7 +10,6 @@ module Rails
class_option :stylesheet_engine, :desc => "Engine for Stylesheets"
hook_for :scaffold_controller, :required => true
- hook_for :serializer
hook_for :assets do |assets|
invoke assets, [controller_name]
diff --git a/railties/lib/rails/generators/rails/serializer/USAGE b/railties/lib/rails/generators/rails/serializer/USAGE
deleted file mode 100644
index a49f7ea1fb..0000000000
--- a/railties/lib/rails/generators/rails/serializer/USAGE
+++ /dev/null
@@ -1,9 +0,0 @@
-Description:
- Generates a serializer for the given resource with tests.
-
-Example:
- `rails generate serializer Account name created_at`
-
- For TestUnit it creates:
- Serializer: app/serializers/account_serializer.rb
- TestUnit: test/unit/account_serializer_test.rb
diff --git a/railties/lib/rails/generators/rails/serializer/serializer_generator.rb b/railties/lib/rails/generators/rails/serializer/serializer_generator.rb
deleted file mode 100644
index 2118906227..0000000000
--- a/railties/lib/rails/generators/rails/serializer/serializer_generator.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-module Rails
- module Generators
- class SerializerGenerator < NamedBase
- check_class_collision :suffix => "Serializer"
-
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
-
- class_option :parent, :type => :string, :desc => "The parent class for the generated serializer"
-
- def create_serializer_file
- template 'serializer.rb', File.join('app/serializers', class_path, "#{file_name}_serializer.rb")
- end
-
- hook_for :test_framework
-
- private
-
- def attributes_names
- attributes.select { |attr| !attr.reference? }.map { |a| a.name.to_sym }
- end
-
- def association_names
- attributes.select { |attr| attr.reference? }.map { |a| a.name.to_sym }
- end
-
- def parent_class_name
- if options[:parent]
- options[:parent]
- elsif (n = Rails::Generators.namespace) && n.const_defined?(:ApplicationSerializer)
- "ApplicationSerializer"
- elsif Object.const_defined?(:ApplicationSerializer)
- "ApplicationSerializer"
- else
- "ActiveModel::Serializer"
- end
- end
- end
- end
-end
diff --git a/railties/lib/rails/generators/rails/serializer/templates/serializer.rb b/railties/lib/rails/generators/rails/serializer/templates/serializer.rb
deleted file mode 100644
index 30c058c7e9..0000000000
--- a/railties/lib/rails/generators/rails/serializer/templates/serializer.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-<% module_namespacing do -%>
-class <%= class_name %>Serializer < <%= parent_class_name %>
-<% if attributes.any? -%> attributes <%= attributes_names.map(&:inspect).join(", ") %>
-<% end -%>
-<% association_names.each do |attribute| -%>
- has_one :<%= attribute %>
-<% end -%>
-end
-<% end -%>
\ No newline at end of file
diff --git a/railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb b/railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb
deleted file mode 100644
index 533c032c3b..0000000000
--- a/railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require 'rails/generators/test_unit'
-
-module TestUnit
- module Generators
- class SerializerGenerator < Base
- check_class_collision :suffix => "SerializerTest"
-
- def create_test_files
- template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_serializer_test.rb")
- end
- end
- end
-end
diff --git a/railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb b/railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb
deleted file mode 100644
index 0b1bbdcaa5..0000000000
--- a/railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require 'test_helper'
-
-<% module_namespacing do -%>
-class <%= class_name %>SerializerTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-end
-<% end -%>
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index 2e8b03fbef..2db8090621 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -264,15 +264,6 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
assert_file "app/assets/stylesheets/posts.css"
end
- def test_scaffold_also_generators_serializer
- run_generator [ "posts", "name:string", "author:references", "--serializer" ]
- assert_file "app/serializers/post_serializer.rb" do |serializer|
- assert_match /class PostSerializer < ActiveModel::Serializer/, serializer
- assert_match /^ attributes :name$/, serializer
- assert_match /^ has_one :author$/, serializer
- end
- end
-
def test_scaffold_generator_outputs_error_message_on_missing_attribute_type
run_generator ["post", "title", "body:text", "author"]
diff --git a/railties/test/generators/serializer_generator_test.rb b/railties/test/generators/serializer_generator_test.rb
deleted file mode 100644
index 2afaa65693..0000000000
--- a/railties/test/generators/serializer_generator_test.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-require 'generators/generators_test_helper'
-require 'rails/generators/rails/serializer/serializer_generator'
-
-class SerializerGeneratorTest < Rails::Generators::TestCase
- include GeneratorsTestHelper
- arguments %w(account name:string description:text business:references)
-
- def test_generates_a_serializer
- run_generator
- assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < ActiveModel::Serializer/
- end
-
- def test_generates_a_namespaced_serializer
- run_generator ["admin/account"]
- assert_file "app/serializers/admin/account_serializer.rb", /class Admin::AccountSerializer < ActiveModel::Serializer/
- end
-
- def test_uses_application_serializer_if_one_exists
- Object.const_set(:ApplicationSerializer, Class.new)
- run_generator
- assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < ApplicationSerializer/
- ensure
- Object.send :remove_const, :ApplicationSerializer
- end
-
- def test_uses_namespace_application_serializer_if_one_exists
- Object.const_set(:SerializerNamespace, Module.new)
- SerializerNamespace.const_set(:ApplicationSerializer, Class.new)
- Rails::Generators.namespace = SerializerNamespace
- run_generator
- assert_file "app/serializers/serializer_namespace/account_serializer.rb",
- /module SerializerNamespace\n class AccountSerializer < ApplicationSerializer/
- ensure
- Object.send :remove_const, :SerializerNamespace
- Rails::Generators.namespace = nil
- end
-
- def test_uses_given_parent
- Object.const_set(:ApplicationSerializer, Class.new)
- run_generator ["Account", "--parent=MySerializer"]
- assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < MySerializer/
- ensure
- Object.send :remove_const, :ApplicationSerializer
- end
-
- def test_generates_attributes_and_associations
- run_generator
- assert_file "app/serializers/account_serializer.rb" do |serializer|
- assert_match(/^ attributes :name, :description$/, serializer)
- assert_match(/^ has_one :business$/, serializer)
- end
- end
-
- def test_with_no_attributes_does_not_add_extra_space
- run_generator ["account"]
- assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < ActiveModel::Serializer\nend/
- end
-
- def test_invokes_default_test_framework
- run_generator
- assert_file "test/unit/account_serializer_test.rb", /class AccountSerializerTest < ActiveSupport::TestCase/
- end
-end
--
cgit v1.2.3
From 3f1a4c3415113f2d365eb1a5531757699afec605 Mon Sep 17 00:00:00 2001
From: gregolsen
Date: Sun, 6 Nov 2011 21:42:03 +0200
Subject: beginning_of_week extended in both Time and Date so that to return
week start based on start day that is monday by default
---
railties/guides/source/active_support_core_extensions.textile | 10 ++++++----
1 file changed, 6 insertions(+), 4 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 ff6c5f967f..c6130f4f62 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -3039,12 +3039,14 @@ Active Support defines these methods as well for Ruby 1.8.
h6. +beginning_of_week+, +end_of_week+
-The methods +beginning_of_week+ and +end_of_week+ return the dates for the beginning and end of week, assuming weeks start on Monday:
+The methods +beginning_of_week+ and +end_of_week+ receive a symbol with a day name in English (in lowercase, default is :monday) and return the dates for the beginning and end of week, assuming weeks start on day, passed as parameter:
-d = Date.new(2010, 5, 8) # => Sat, 08 May 2010
-d.beginning_of_week # => Mon, 03 May 2010
-d.end_of_week # => Sun, 09 May 2010
+d = Date.new(2010, 5, 8) # => Sat, 08 May 2010
+d.beginning_of_week # => Mon, 03 May 2010
+d.beginning_of_week(:sunday) # => Sun, 02 May 2010
+d.end_of_week # => Sun, 09 May 2010
+d.end_of_week(:sunday) # => Sat, 08 May 2010
+beginning_of_week+ is aliased to +monday+ and +at_beginning_of_week+. +end_of_week+ is aliased to +sunday+ and +at_end_of_week+.
--
cgit v1.2.3
From a5b362df567ed4a0167a83e9b8f00b9f614ac38b Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Fri, 25 Nov 2011 12:01:58 -0800
Subject: some tweaks to PR#3547. [Closes #3547]
---
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 c6130f4f62..09f931050d 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -3039,7 +3039,9 @@ Active Support defines these methods as well for Ruby 1.8.
h6. +beginning_of_week+, +end_of_week+
-The methods +beginning_of_week+ and +end_of_week+ receive a symbol with a day name in English (in lowercase, default is :monday) and return the dates for the beginning and end of week, assuming weeks start on day, passed as parameter:
+The methods +beginning_of_week+ and +end_of_week+ return the dates for the
+beginning and end of the week, respectively. Weeks are assumed to start on
+Monday, but that can be changed passing an argument, see examples:
d = Date.new(2010, 5, 8) # => Sat, 08 May 2010
--
cgit v1.2.3
From 1be9830d4d99e2bf56f1cadf74b843f22d66da35 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Fri, 25 Nov 2011 14:29:34 -0800
Subject: add the query to AR::Relation#explain output
Rationale: this is more readable if serveral queries
are involved in one call. Also, it will be possible
to let AR log EXPLAINs automatically in production
mode, where queries are not even around.
---
railties/guides/source/active_record_querying.textile | 5 +++++
1 file changed, 5 insertions(+)
(limited to 'railties')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index ad12dca7e8..0f1f6eba4c 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -1287,6 +1287,7 @@ User.where(:id => 1).joins(:posts).explain
may yield
+EXPLAIN for: SELECT `users`.* FROM `users` INNER JOIN `posts` ON `posts`.`user_id` = `users`.`id` WHERE `users`.`id` = 1
------------------------------------------------------------------------------------------
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
------------------------------------------------------------------------------------------
@@ -1302,6 +1303,7 @@ Active Record performs a pretty printing that emulates the one of the database
shells. So, the same query running with the PostgreSQL adapter would yield instead
+EXPLAIN for: SELECT "users".* FROM "users" INNER JOIN "posts" ON "posts"."user_id" = "users"."id" WHERE "users"."id" = 1
QUERY PLAN
------------------------------------------------------------------------------
Nested Loop Left Join (cost=0.00..37.24 rows=8 width=0)
@@ -1324,12 +1326,15 @@ User.where(:id => 1).includes(:posts).explain
yields
+EXPLAIN for: SELECT `users`.* FROM `users` WHERE `users`.`id` = 1
------------------------------------------------------------------------------------
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
------------------------------------------------------------------------------------
| 1 | SIMPLE | users | const | PRIMARY | PRIMARY | 4 | const | 1 | |
------------------------------------------------------------------------------------
1 row in set (0.00 sec)
+
+EXPLAIN for: SELECT `posts`.* FROM `posts` WHERE `posts`.`user_id` IN (1)
-------------------------------------------------------------------------------------
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
-------------------------------------------------------------------------------------
--
cgit v1.2.3
From b30b932447d3ae059c0dac2c5bf0a3a79e0fa54e Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Fri, 25 Nov 2011 14:58:43 -0800
Subject: finders guide: adds some pointers to help users interpret the output
of EXPLAIN
---
railties/guides/source/active_record_querying.textile | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'railties')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 0f1f6eba4c..c4724f182e 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -1344,3 +1344,14 @@ EXPLAIN for: SELECT `posts`.* FROM `posts` WHERE `posts`.`user_id` IN (1)
under MySQL.
+
+h4. Interpreting EXPLAIN
+
+Interpretation of the output of EXPLAIN is beyond the scope of this guide. The
+following pointers may be helpful:
+
+* SQLite3: "EXPLAIN QUERY PLAN":http://www.sqlite.org/eqp.html
+
+* MySQL: "EXPLAIN Output Format":http://dev.mysql.com/doc/refman/5.6/en/explain-output.html
+
+* PostgreSQL: "Using EXPLAIN":http://www.postgresql.org/docs/current/static/using-explain.html
--
cgit v1.2.3
From 5c2a2ee76e2af591a997b71eec0e35143c07f9e1 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 26 Nov 2011 19:06:53 +0530
Subject: rephrased ef38c3089e1269e2b315aff503e61c0b23c95f00 and mentioned
about OS X and windows usually having a JS runtime
---
railties/guides/source/getting_started.textile | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
(limited to 'railties')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 5774eba5ae..ca6a404212 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -450,11 +450,7 @@ start a web server on your development machine. You can do this by running:
$ rails server
-TIP: Some environments require that you install a JavaScript runtime to compile
-CoffeeScript to JavaScript and will give you an +execjs+ error the first time
-you run +rails server+. +therubyracer+ and +therubyrhino+ are commonly used
-runtimes for Ruby and JRuby respectively. You can also investigate a list
-of runtimes at "ExecJS":https://github.com/sstephenson/execjs.
+TIP: Compiling CoffeeScript to JavaScript requires a JavaScript runtime and the absence of a runtime will give you an +execjs+ error. Usually Mac OS X and Windows come with a JavaScript runtime installed. +therubyracer+ and +therubyrhino+ are the commonly used runtimes for Ruby and JRuby respectively. You can also investigate a list of runtimes at "ExecJS":https://github.com/sstephenson/execjs.
This will fire up an instance of the WEBrick web server by default (Rails can
also use several other web servers). To see your application in action, open a
--
cgit v1.2.3
From fc20d6b6815032935f02b53b4b928cd514ed66ac Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Sat, 26 Nov 2011 22:38:58 +0530
Subject: Let's say this 3.1.3 instead of 3.1.1 in docs
---
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 ca6a404212..fe43c9db36 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -248,7 +248,7 @@ the following:
$ rails --version
-If it says something like "Rails 3.1.1" you are ready to continue.
+If it says something like "Rails 3.1.3" you are ready to continue.
h4. Creating the Blog Application
--
cgit v1.2.3
From 0ce64ba9aa93c01ee69c45493ad8090e76f95ff4 Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Sun, 27 Nov 2011 12:34:14 +0530
Subject: Documentation about config.log_level config options
---
railties/guides/source/configuring.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index 809948b41e..beb623757b 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -88,6 +88,8 @@ NOTE. The +config.asset_path+ configuration is ignored if the asset pipeline is
* +config.log_level+ defines the verbosity of the Rails logger. This option defaults to +:debug+ for all modes except production, where it defaults to +:info+.
+* +config.log_tags+ accepts a list of methods that respond to +request+ object. This makes it easy to tag log lines with debug information like subdomain and request id -- both very helpful in debugging multi-user production applications.
+
* +config.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby +Logger+ class. Defaults to an instance of +ActiveSupport::BufferedLogger+, with auto flushing off in production mode.
* +config.middleware+ allows you to configure the application's middleware. This is covered in depth in the "Configuring Middleware":#configuring-middleware section below.
--
cgit v1.2.3
From 28e3935360c9392685c4954791cc320ed02e15c0 Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Sun, 27 Nov 2011 12:53:08 +0530
Subject: [Docs] Adding RequestId middleware in configuring middleware
---
railties/guides/source/configuring.textile | 1 +
1 file changed, 1 insertion(+)
(limited to 'railties')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index beb623757b..d91011c370 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -190,6 +190,7 @@ Every Rails application comes with a standard set of middleware which it uses in
* +Rack::Runtime+ sets an +X-Runtime+ header, containing the time (in seconds) taken to execute the request.
* +Rails::Rack::Logger+ notifies the logs that the request has began. After request is complete, flushes all the logs.
* +ActionDispatch::ShowExceptions+ rescues any exception returned by the application and renders nice exception pages if the request is local or if +config.consider_all_requests_local+ is set to +true+. If +config.action_dispatch.show_exceptions+ is set to +false+, exceptions will be raised regardless.
+* +ActionDispatch::RequestId+ makes a unique X-Request-Id header available to the response and enables the +ActionDispatch::Request#uuid+ method.
* +ActionDispatch::RemoteIp+ checks for IP spoofing attacks. Configurable with the +config.action_dispatch.ip_spoofing_check+ and +config.action_dispatch.trusted_proxies+ settings.
* +Rack::Sendfile+ intercepts responses whose body is being served from a file and replaces it with a server specific X-Sendfile header. Configurable with +config.action_dispatch.x_sendfile_header+.
* +ActionDispatch::Callbacks+ runs the prepare callbacks before serving the request.
--
cgit v1.2.3
From 9cf285599c1e99736f5dd9d01f986c19dcf3d4da Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tadas=20Tamo=C5=A1auskas?=
Date: Sun, 27 Nov 2011 12:44:14 +0000
Subject: Update Object#in? description for
https://github.com/rails/rails/pull/3767
---
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 d601e9ea29..c1046a3b63 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -440,14 +440,16 @@ NOTE: Defined in +active_support/core_ext/kernel/reporting.rb+.
h4. +in?+
-The predicate +in?+ tests if an object is included in another object. An +ArgumentError+ exception will be raised if the argument passed does not respond to +include?+.
+The predicate +in?+ tests if an object is included in another object or a list of objects. An +ArgumentError+ exception will be raised if a single argument is passed and it does not respond to +include?+.
Examples of +in?+:
+1.in?(1,2) # => true
1.in?([1,2]) # => true
"lo".in?("hello") # => true
25.in?(30..50) # => false
+1.in?(1) # => ArgumentError
NOTE: Defined in +active_support/core_ext/object/inclusion.rb+.
--
cgit v1.2.3
From 2f428a6245a18017c7942f8fef3da4a85bec8cc5 Mon Sep 17 00:00:00 2001
From: Tim Reischmann
Date: Mon, 28 Nov 2011 09:27:42 +0100
Subject: fixed typo in getting started form_for for 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 fe43c9db36..3ff6603a4c 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1297,7 +1297,7 @@ So first, we'll wire up the Post show template
Add a comment:
-<%= form_for([@post, @post.comments.build]) do |f| %>
+<%= form_for([@post, @post.comment.build]) do |f| %>
<%= f.label :commenter %>
<%= f.text_field :commenter %>
--
cgit v1.2.3
From e7dff9c1f1e3e8a73c1b5bc5fd4263126813489c Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Mon, 28 Nov 2011 14:10:23 +0530
Subject: Revert "fixed typo in getting started form_for for comments"
This reverts commit 2f428a6245a18017c7942f8fef3da4a85bec8cc5.
See comments here 2f428a6245a18017c7942f8fef3da4a85bec8cc5
---
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 3ff6603a4c..fe43c9db36 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1297,7 +1297,7 @@ So first, we'll wire up the Post show template
Add a comment:
-<%= form_for([@post, @post.comment.build]) do |f| %>
+<%= form_for([@post, @post.comments.build]) do |f| %>
<%= f.label :commenter %>
<%= f.text_field :commenter %>
--
cgit v1.2.3
From 6d05c793cafe79860bcbb469d6c46c83c531ab34 Mon Sep 17 00:00:00 2001
From: Rodrigo Rosenfeld Rosas
Date: Mon, 28 Nov 2011 13:15:07 -0200
Subject: Update information about foreign key plugins support in the guides
There is not "a number" of up-to-date maintained plugins for dealing with foreign keys.
The foreign_key_migrations does not have any update since 2009 and is also about to be removed:
Extracted from http://www.harukizaemon.com/2009/09/plugins-grab-em-while-theyre-stale.html,
referenced in the plugin reference of the old guide version:
"And so it is that I will very shortly (within the next month) delete most of the plugins from
my GitHub account (harukizaemon)"
---
railties/guides/source/migrations.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties')
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 5b52a93853..c63f2aa119 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -670,4 +670,4 @@ 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+).
+Although Active Record does not provide any tools for working directly with such features, the +execute+ method can be used to execute arbitrary SQL. You could also use some plugin like "foreigner":https://github.com/matthuhiggins/foreigner which add foreign key support to Active Record (including support for dumping foreign keys in +db/schema.rb+).
--
cgit v1.2.3