From 0f7a52d920319842d45351b2e489b281a76b682a Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Wed, 25 May 2011 20:03:06 -0300 Subject: Fix fixed-fonts stlye on rails_on_rack guide. --- railties/guides/source/initialization.textile | 14 +++++++------- railties/guides/source/rails_on_rack.textile | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 638830cd83..e4da77eee1 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -155,13 +155,13 @@ h4. +config/boot.rb+ In a standard Rails application, there's a +Gemfile+ which declares all dependencies of the application. +config/boot.rb+ sets +ENV["BUNDLE_GEMFILE"]+ to the location of this file, then requires Bundler and calls +Bundler.setup+ which adds the dependencies of the application (including all the Rails parts) to the load path, making them available for the application to load. The gems that a Rails 3.1 application depends on are as follows: * abstract (1.0.0) -* actionmailer (3.1.0.beta) -* actionpack (3.1.0.beta) -* activemodel (3.1.0.beta) -* activerecord (3.1.0.beta) -* activeresource (3.1.0.beta) -* activesupport (3.1.0.beta) -* arel (2.0.7) +* actionmailer (3.1.0.rc1) +* actionpack (3.1.0.rc1) +* activemodel (3.1.0.rc1) +* activerecord (3.1.0.rc1) +* activeresource (3.1.0.rc1) +* activesupport (3.1.0.rc1) +* arel (2.1.0) * builder (3.0.0) * bundler (1.0.6) * erubis (2.6.6) diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile index aa53aa6db6..8d5985dba8 100644 --- a/railties/guides/source/rails_on_rack.textile +++ b/railties/guides/source/rails_on_rack.textile @@ -111,11 +111,11 @@ h5. Adding a Middleware You can add a new middleware to the middleware stack using any of the following methods: -* +config.middleware.use(new_middleware, args)+ - Adds the new middleware at the bottom of the middleware stack. +* config.middleware.use(new_middleware, args) - Adds the new middleware at the bottom of the middleware stack. -* +config.middleware.insert_before(existing_middleware, new_middleware, args)+ - Adds the new middleware before the specified existing middleware in the middleware stack. +* config.middleware.insert_before(existing_middleware, new_middleware, args) - Adds the new middleware before the specified existing middleware in the middleware stack. -* +config.middleware.insert_after(existing_middleware, new_middleware, args)+ - Adds the new middleware after the specified existing middleware in the middleware stack. +* config.middleware.insert_after(existing_middleware, new_middleware, args) - Adds the new middleware after the specified existing middleware in the middleware stack. # config/environment.rb @@ -154,20 +154,20 @@ h4. Internal Middleware Stack Much of Action Controller's functionality is implemented as Middlewares. The following table explains the purpose of each of them: |_.Middleware|_.Purpose| -|+Rack::Lock+|Sets +env["rack.multithread"]+ flag to +true+ and wraps the application within a Mutex.| +|+Rack::Lock+|Sets env["rack.multithread"] flag to +true+ and wraps the application within a Mutex.| |+ActionController::Failsafe+|Returns HTTP Status +500+ to the client if an exception gets raised while dispatching.| |+ActiveRecord::QueryCache+|Enables the Active Record query cache.| |+ActionController::Session::CookieStore+|Uses the cookie based session store.| |+ActionController::Session::MemCacheStore+|Uses the memcached based session store.| |+ActiveRecord::SessionStore+|Uses the database based session store.| -|+Rack::MethodOverride+|Sets HTTP method based on +_method+ parameter or +env["HTTP_X_HTTP_METHOD_OVERRIDE"]+.| +|+Rack::MethodOverride+|Sets HTTP method based on +_method+ parameter or env["HTTP_X_HTTP_METHOD_OVERRIDE"].| |+Rack::Head+|Discards the response body if the client sends a +HEAD+ request.| TIP: It's possible to use any of the above middlewares in your custom Rack stack. h4. Customizing Internal Middleware Stack -It's possible to replace the entire middleware stack with a custom stack using +ActionController::Dispatcher.middleware=+. +It's possible to replace the entire middleware stack with a custom stack using ActionController::Dispatcher.middleware=. Put the following in an initializer: -- cgit v1.2.3 From 4c566940a42bbcff5c202460319b872a44c35140 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Wed, 25 May 2011 20:09:06 -0300 Subject: Fix grammar mistake. Lets vs let's. --- railties/guides/source/configuring.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index 135c849ec3..e5b7c3e338 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -52,7 +52,7 @@ end * +config.asset_host+ sets the host for the assets. Useful when CDNs are used for hosting assets, or when you want to work around the concurrency constraints builtin in browsers using different domain aliases. Shorter version of +config.action_controller.asset_host+. -* +config.asset_path+ can take a callable, a string, or be +nil+. Default is +nil+. If set, this configuration parameter let's you decorate asset paths. For example, the normal path for +blog.js+ would be +/javascripts/blog.js+, let that absolute path be +path+. If +config.asset_path+ is a callable, Rails calls it when generating asset paths passing +path+ as argument. If +config.asset_path+ is a string, it is expected to be a +sprintf+ format string with a +%s+ where +path+ will get inserted. In either case, Rails outputs the decorated path. *This option is ignored if the asset pipeline is enabled, which is by default*. Shorter version of +config.action_controller.asset_path+. +* +config.asset_path+ can take a callable, a string, or be +nil+. Default is +nil+. If set, this configuration parameter lets you decorate asset paths. For example, the normal path for +blog.js+ would be +/javascripts/blog.js+, let that absolute path be +path+. If +config.asset_path+ is a callable, Rails calls it when generating asset paths passing +path+ as argument. If +config.asset_path+ is a string, it is expected to be a +sprintf+ format string with a +%s+ where +path+ will get inserted. In either case, Rails outputs the decorated path. *This option is ignored if the asset pipeline is enabled, which is by default*. Shorter version of +config.action_controller.asset_path+. config.asset_path = proc { |path| "/blog/public#{path}" } -- cgit v1.2.3 From ab3c87a2d2a907e6e1e44e22def4ff2cc89f46ba Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Wed, 25 May 2011 20:13:49 -0300 Subject: Revert this, commited by mistake. --- railties/guides/source/initialization.textile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index e4da77eee1..638830cd83 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -155,13 +155,13 @@ h4. +config/boot.rb+ In a standard Rails application, there's a +Gemfile+ which declares all dependencies of the application. +config/boot.rb+ sets +ENV["BUNDLE_GEMFILE"]+ to the location of this file, then requires Bundler and calls +Bundler.setup+ which adds the dependencies of the application (including all the Rails parts) to the load path, making them available for the application to load. The gems that a Rails 3.1 application depends on are as follows: * abstract (1.0.0) -* actionmailer (3.1.0.rc1) -* actionpack (3.1.0.rc1) -* activemodel (3.1.0.rc1) -* activerecord (3.1.0.rc1) -* activeresource (3.1.0.rc1) -* activesupport (3.1.0.rc1) -* arel (2.1.0) +* actionmailer (3.1.0.beta) +* actionpack (3.1.0.beta) +* activemodel (3.1.0.beta) +* activerecord (3.1.0.beta) +* activeresource (3.1.0.beta) +* activesupport (3.1.0.beta) +* arel (2.0.7) * builder (3.0.0) * bundler (1.0.6) * erubis (2.6.6) -- cgit v1.2.3 From 2cd26b767900956c3d4d0f9740e5089479a8d28a Mon Sep 17 00:00:00 2001 From: Thais Camilo Date: Wed, 25 May 2011 20:18:58 -0400 Subject: On "contribute" guide: remove mention of LH --- railties/guides/source/contribute.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/contribute.textile b/railties/guides/source/contribute.textile index 4bd527d4c7..ff77bd9a5e 100644 --- a/railties/guides/source/contribute.textile +++ b/railties/guides/source/contribute.textile @@ -33,7 +33,7 @@ h3. What to Contribute? h3. How is the process? * The preferred way to contribute is to commit to docrails directly. -* A new guide is only edited by its author until finished though. In that case feedback can be given in its LH ticket. +* A new guide is only edited by its author until finished though. * If you are writing a new guide freely commit to docrails partial work and ping lifo or fxn when done with a first draft. * Guides reviewers will then provide feedback, some of it possibly in form of direct commits to agilize the process. * Eventually the guide will be approved and added to the index. -- cgit v1.2.3 From 4da4856f50d95746e5154e28c2154cfc52e7508a Mon Sep 17 00:00:00 2001 From: Thais Camilo Date: Wed, 25 May 2011 20:27:17 -0400 Subject: Stop linking API Guidelines to GitHub wiki --- railties/guides/source/contribute.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/contribute.textile b/railties/guides/source/contribute.textile index ff77bd9a5e..52f95675c4 100644 --- a/railties/guides/source/contribute.textile +++ b/railties/guides/source/contribute.textile @@ -53,7 +53,7 @@ h3. Rules * If the same guide writer wants to write multiple guides, that's ideally the situation we'd love to be in! However, that guide writer will only receive the cash prize for all the subsequent guides (and not the GitHub or RPM prizes). * Our review team will have the final say on whether the guide is complete and of good enough quality. -All authors should read and follow the "Rails Guides Conventions":https://wiki.github.com/lifo/docrails/rails-guides-conventions and the "Rails API Documentation Conventions":https://wiki.github.com/lifo/docrails/rails-api-documentation-conventions. +All authors should read and follow the "Rails Guides Conventions":https://wiki.github.com/lifo/docrails/rails-guides-conventions and the "Rails API Documentation Conventions":api_documentation_guidelines.html. h3. Translations -- cgit v1.2.3 From ec080f98a27d4c7c19c1d682c548b74474cb7a61 Mon Sep 17 00:00:00 2001 From: Thais Camilo Date: Wed, 25 May 2011 20:45:44 -0400 Subject: Stop linking Rails guidelines to GitHub wiki --- railties/guides/source/contribute.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/contribute.textile b/railties/guides/source/contribute.textile index 52f95675c4..3985cdeb2a 100644 --- a/railties/guides/source/contribute.textile +++ b/railties/guides/source/contribute.textile @@ -53,7 +53,7 @@ h3. Rules * If the same guide writer wants to write multiple guides, that's ideally the situation we'd love to be in! However, that guide writer will only receive the cash prize for all the subsequent guides (and not the GitHub or RPM prizes). * Our review team will have the final say on whether the guide is complete and of good enough quality. -All authors should read and follow the "Rails Guides Conventions":https://wiki.github.com/lifo/docrails/rails-guides-conventions and the "Rails API Documentation Conventions":api_documentation_guidelines.html. +All authors should read and follow the "Rails Guides Conventions":ruby_on_rails_guides_guidelines.html and the "Rails API Documentation Conventions":api_documentation_guidelines.html. h3. Translations -- cgit v1.2.3 From 4807088fda43b5858ada61e822c7598e17c83417 Mon Sep 17 00:00:00 2001 From: Ben Orenstein Date: Thu, 26 May 2011 20:52:22 -0400 Subject: Don't you lie to me! --- railties/guides/source/active_record_querying.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 579a323d57..6cba34c7cd 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -483,13 +483,13 @@ SQL uses the +HAVING+ clause to specify conditions on the +GROUP BY+ fields. You For example: -Order.group("date(created_at)").having("created_at > ?", 1.month.ago) +Order.group("date(created_at)").having("created_at < ?", 1.month.ago) The SQL that would be executed would be something like this: -SELECT * FROM orders GROUP BY date(created_at) HAVING created_at > '2009-01-15' +SELECT * FROM orders GROUP BY date(created_at) HAVING created_at < '2009-01-15' This will return single order objects for each day, but only for the last month. -- cgit v1.2.3 From 64148ab96b47a9904fdd839bc69971b4e156bb04 Mon Sep 17 00:00:00 2001 From: Ben Orenstein Date: Thu, 26 May 2011 22:19:10 -0400 Subject: Improve 'Joining Tables' section with additional examples and explanation. --- .../guides/source/active_record_querying.textile | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 6cba34c7cd..0690b5e169 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -675,7 +675,7 @@ class Post < ActiveRecord::Base has_many :tags end -class Comments < ActiveRecord::Base +class Comment < ActiveRecord::Base belongs_to :post has_one :guest end @@ -683,6 +683,10 @@ end class Guest < ActiveRecord::Base belongs_to :comment end + +class Tag < ActiveRecord::Base + belongs_to :post +end Now all of the following will produce the expected join queries using +INNER JOIN+: @@ -700,6 +704,8 @@ SELECT categories.* FROM categories INNER JOIN posts ON posts.category_id = categories.id +Or, in English: "return a category object for all categories with posts". (You will see duplicate categories if more than one post has the same category. If you want unique posts, you can use Category.joins(:post).select("distinct(categories.id)).) + h5. Joining Multiple Associations @@ -714,18 +720,40 @@ SELECT posts.* FROM posts INNER JOIN comments ON comments.post_id = posts.id +Or, in English: "return all posts that have a category and at least one comment". Note again that posts with multiple comments will show up multiple times. + h5. Joining Nested Associations (Single Level) Post.joins(:comments => :guest) +This produces: + + +SELECT posts.* FROM posts + INNER JOIN comments ON comments.post_id = posts.id + INNER JOIN guests ON guests.comment_id = comments.id + + +Or, in English: "return all posts that have a comment made by a guest." + h5. Joining Nested Associations (Multiple Level) Category.joins(:posts => [{:comments => :guest}, :tags]) +This produces: + + +SELECT categories.* FROM categories + INNER JOIN posts ON posts.category_id = categories.id + INNER JOIN comments ON comments.post_id = posts.id + INNER JOIN guests ON guests.comment_id = comments.id + INNER JOIN tags ON tags.post_id = posts.id + + h4. Specifying Conditions on the Joined Tables You can specify conditions on the joined tables using the regular "Array":#array-conditions and "String":#pure-string-conditions conditions. "Hash conditions":#hash-conditions provides a special syntax for specifying conditions for the joined tables: -- cgit v1.2.3 From 5b6a423d6bcbfd4142c47765794a4f93b8178562 Mon Sep 17 00:00:00 2001 From: Ben Orenstein Date: Thu, 26 May 2011 22:22:10 -0400 Subject: Copy edits 64148ab96b47a9904fdd839bc69971b4e156bb04 (previous commit). Please squash at will. --- railties/guides/source/active_record_querying.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 0690b5e169..d01e14fee7 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -704,7 +704,7 @@ SELECT categories.* FROM categories INNER JOIN posts ON posts.category_id = categories.id -Or, in English: "return a category object for all categories with posts". (You will see duplicate categories if more than one post has the same category. If you want unique posts, you can use Category.joins(:post).select("distinct(categories.id)).) +Or, in English: "return a Category object for all categories with posts". Note that you will see duplicate categories if more than one post has the same category. If you want unique categories, you can use Category.joins(:post).select("distinct(categories.id)"). h5. Joining Multiple Associations -- cgit v1.2.3 From 4a376e48b93060e61af6b5852995e2e55a3d1a04 Mon Sep 17 00:00:00 2001 From: Ben Orenstein Date: Fri, 27 May 2011 22:05:22 -0400 Subject: Fix incorrect description of the returned results. --- railties/guides/source/active_record_querying.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index d01e14fee7..b4ce60fcaa 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -489,10 +489,10 @@ Order.group("date(created_at)").having("created_at < ?", 1.month.ago) The SQL that would be executed would be something like this: -SELECT * FROM orders GROUP BY date(created_at) HAVING created_at < '2009-01-15' +SELECT * FROM orders GROUP BY date(created_at) HAVING created_at < '2011-04-27' -This will return single order objects for each day, but only for the last month. +This will return single order objects for each day, but only those that are at least one month old. h3. Overriding Conditions -- cgit v1.2.3 From 7d7b2009bbcb902ce2626456ae5ff56ca1da99f7 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 28 May 2011 23:18:08 +0530 Subject: document aliases for commands and update rails versions --- railties/guides/source/command_line.textile | 32 +++++++++++++++++------------ 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index ad36c6532e..5497445fcb 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -55,7 +55,7 @@ INFO: This output will seem very familiar when we get to the +generate+ command. h4. +rails server+ -Let's try it! The +rails server+ command launches a small web server named WEBrick which comes bundled with Ruby. You'll use this any time you want to view your work through a web browser. +The +rails server+ command launches a small web server named WEBrick which comes bundled with Ruby. You'll use this any time you want to view your work through a web browser. INFO: WEBrick isn't your only option for serving Rails. We'll get to that in a later section. @@ -65,7 +65,7 @@ Without any prodding of any kind, +rails server+ will run our new shiny Rails ap $ cd commandsapp $ rails server => Booting WEBrick -=> Rails 3.0.0 application starting in development on http://0.0.0.0:3000 +=> Rails 3.1.0 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2010-04-18 03:20:33] INFO WEBrick 1.3.1 @@ -75,6 +75,8 @@ $ rails server With just three commands we whipped up a Rails server listening on port 3000. Go to your browser and open "http://localhost:3000":http://localhost:3000, you will see a basic Rails app running. +You can also use the alias "s" to start the server: rails s. + h4. +rails generate+ The +rails generate+ command uses templates to create a whole lot of things. You can always find out what's available by running +rails generate+ by itself. Let's do that: @@ -237,7 +239,7 @@ dependency model create test/unit/high_score_test.rb create test/fixtures/high_scores.yml exists db/migrate - create db/migrate/20081217071914_create_high_scores.rb + create db/migrate/20100209025147_create_high_scores.rb The generator checks that there exist the directories for models, controllers, helpers, layouts, functional and unit tests, stylesheets, creates the views, controller, model and database migration for HighScore (creating the +high_scores+ table and fields), takes care of the route for the *resource*, and new tests for everything. @@ -267,11 +269,13 @@ h4. +rails console+ The +console+ command lets you interact with your Rails application from the command line. On the underside, +rails console+ uses IRB, so if you've ever used it, you'll be right at home. This is useful for testing out quick ideas with code and changing data server-side without touching the website. +You can also use the alias "c" to invoke the console: rails c. + If you wish to test out some code without changing any data, you can do that by invoking +rails console --sandbox+. $ rails console --sandbox -Loading development environment in sandbox (Rails 3.0.0) +Loading development environment in sandbox (Rails 3.1.0) Any modifications you make will be rolled back on exit irb(main):001:0> @@ -280,6 +284,8 @@ h4. +rails dbconsole+ +rails dbconsole+ figures out which database you're using and drops you into whichever command line interface you would use with it (and figures out the command line parameters to give to it, too!). It supports MySQL, PostgreSQL, SQLite and SQLite3. +You can also use the alias "db" to invoke the console: rails db. + h4. +rails plugin+ The +rails plugin+ command simplifies plugin management; think a miniature version of the Gem utility. Let's walk through installing a plugin. You can call the sub-command +discover+, which sifts through repositories looking for plugins, or call +source+ to add a specific repository of plugins, or you can specify the plugin location directly. @@ -306,7 +312,7 @@ $ rails runner "Model.long_running_method" h4. +rails destroy+ -Think of +destroy+ as the opposite of +generate+. It'll figure out what generate did, and undo it. Believe you-me, the creation of this tutorial used this command many times! +Think of +destroy+ as the opposite of +generate+. It'll figure out what generate did, and undo it. $ rails generate model Oops @@ -343,12 +349,12 @@ About your application's environment Ruby version 1.8.7 (x86_64-linux) RubyGems version 1.3.6 Rack version 1.1 -Rails version 3.0.0 -Active Record version 3.0.0 -Action Pack version 3.0.0 -Active Resource version 3.0.0 -Action Mailer version 3.0.0 -Active Support version 3.0.0 +Rails version 3.1.0 +Active Record version 3.1.0 +Action Pack version 3.1.0 +Active Resource version 3.1.0 +Action Mailer version 3.1.0 +Active Support version 3.1.0 Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, Rack::Sendfile, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head Application root /home/foobar/commandsapp Environment development @@ -437,7 +443,7 @@ Successfully installed mongrel-1.1.5 Installing RDoc documentation for mongrel-1.1.5... $ rails server mongrel => Booting Mongrel (use 'rails server webrick' to force WEBrick) -=> Rails 3.0.0 application starting on http://0.0.0.0:3000 +=> Rails 3.1.0 application starting on http://0.0.0.0:3000 ... @@ -581,7 +587,7 @@ You can list all the timezones Rails knows about with +rake time:zones:all+, whi h5. +tmp:+ Temporary files -The tmp directory is, like in the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for files), process id files, and cached actions. The +tmp:+ namespace tasks will help you clear them if you need to if they've become overgrown, or create them in case of deletions gone awry. +The tmp directory is, like the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for files), process id files, and cached actions. The +tmp:+ namespace tasks will help you clear them if you need to if they've become overgrown, or create them in case of deletions gone awry. h5. Miscellaneous Tasks -- cgit v1.2.3 From fc381a3a42267898865838f216f7715fb4dbaa16 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 29 May 2011 01:33:30 +0530 Subject: fix typo --- railties/guides/source/command_line.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 5497445fcb..1796c2fb78 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -284,7 +284,7 @@ h4. +rails dbconsole+ +rails dbconsole+ figures out which database you're using and drops you into whichever command line interface you would use with it (and figures out the command line parameters to give to it, too!). It supports MySQL, PostgreSQL, SQLite and SQLite3. -You can also use the alias "db" to invoke the console: rails db. +You can also use the alias "db" to invoke the dbconsole: rails db. h4. +rails plugin+ -- cgit v1.2.3 From 4967b35e00318d4f3ba3fdf9b7778eec387d64f2 Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Sun, 29 May 2011 06:37:08 -0400 Subject: Why should you use the asset pipeline? --- railties/guides/source/asset_pipeline.textile | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 9ea1aa9e01..d1b33055f2 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -14,6 +14,8 @@ h3. What Is The Asset Pipeline? h4. Why Should I Use it? +Using the asset pipeline allows you to package javascript, CSS, or images with your Rails application, library, or plugin. It also makes it easy to create dynamic CSS with LESS and clean JavaScript with CoffeeScript to name a few of the popular preprocessors. The big difference is that they are now housed in app/assets, treating them like first-class citizens instead of just throughing them into their public folders. + h3. How to Use the Asset Pipeline h4. Asset Organization @@ -27,3 +29,5 @@ h4. Stacking Preproccessors h3. Packaging Assets with Your Plugin h3. More on Sprockets + +Sprockets is the engine that handles the asset pipeline in Rails 3.1 and above. Their offical website is avaialbe at "http://getsprockets.org/":http://getsprockets.org/ and the source code is "on github":https://github.com/sstephenson/sprockets. -- cgit v1.2.3 From 9342ad67486f96357e518becb71ec225e0bd216e Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Sun, 29 May 2011 06:43:35 -0400 Subject: Changes wording to make it a bit eaiser to understand --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index d1b33055f2..ee8deaaad1 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -14,7 +14,7 @@ h3. What Is The Asset Pipeline? h4. Why Should I Use it? -Using the asset pipeline allows you to package javascript, CSS, or images with your Rails application, library, or plugin. It also makes it easy to create dynamic CSS with LESS and clean JavaScript with CoffeeScript to name a few of the popular preprocessors. The big difference is that they are now housed in app/assets, treating them like first-class citizens instead of just throughing them into their public folders. +Using the asset pipeline allows you to package javascript, CSS, or images with your Rails application, library, or plugin. It also makes it easy to create dynamic CSS with LESS and clean JavaScript with CoffeeScript to name a few of the popular preprocessors. The big difference is that they are now categorized in app/assets, treating them like first-class citizens instead of just throughing them into categorized folders in the public directory. h3. How to Use the Asset Pipeline -- cgit v1.2.3 From 07dcae093b0cd6fbe80e361ca0f603cd143a079b Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Sun, 29 May 2011 06:45:57 -0400 Subject: Fixes spelling mistakes pointed out by @vijaydev --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index ee8deaaad1..74e26ccc71 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -14,7 +14,7 @@ h3. What Is The Asset Pipeline? h4. Why Should I Use it? -Using the asset pipeline allows you to package javascript, CSS, or images with your Rails application, library, or plugin. It also makes it easy to create dynamic CSS with LESS and clean JavaScript with CoffeeScript to name a few of the popular preprocessors. The big difference is that they are now categorized in app/assets, treating them like first-class citizens instead of just throughing them into categorized folders in the public directory. +Using the asset pipeline allows you to package JavaScript, CSS, or images with your Rails application, library, or plugin. It also makes it easy to create dynamic CSS with LESS and clean JavaScript with CoffeeScript to name a few of the popular preprocessors. The big difference is that they are now categorized in app/assets, treating them like first-class citizens instead of just throwing them into categorized folders in the public directory. h3. How to Use the Asset Pipeline -- cgit v1.2.3 From 1962217e42319d70250d017397849990c5b981e0 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 29 May 2011 18:35:42 +0530 Subject: removed references to old remote_* helpers; add info about 3.1 adding multipart option to a form with file_field automatically --- .../guides/source/action_view_overview.textile | 107 +-------------------- 1 file changed, 5 insertions(+), 102 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile index b064851312..8c6a82d50c 100644 --- a/railties/guides/source/action_view_overview.textile +++ b/railties/guides/source/action_view_overview.textile @@ -1037,7 +1037,7 @@ Sample usage (selecting the associated Author for an instance of Post, +@post+): collection_select(:post, :author_id, Author.all, :id, :name_with_initial, {:prompt => true}) -If @post.author_id is already 1, this would return: +If @post.author_id is 1, this would return: @@ -1189,7 +1187,7 @@ h5. file_field_tag Creates a file upload field. -If you are using file uploads then you will also need to set the multipart option for the form tag: +Prior to Rails 3.1, if you are using file uploads, then you will need to set the multipart option for the form tag. Rails 3.1+ does this automatically. <%= form_tag { :action => "post" }, { :multipart => true } do %> @@ -1400,102 +1398,6 @@ number_with_precision(111.2345) # => 111.235 number_with_precision(111.2345, 2) # => 111.23 -h5. evaluate_remote_response - -Returns +eval(request.responseText)+ which is the JavaScript function that form_remote_tag can call in +:complete+ to evaluate a multiple update return document using +update_element_function+ calls. - -h5. form_remote_tag - -Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement. Even though it‘s using JavaScript to serialize the form elements, the form submission will work just like a regular submission as viewed by the receiving side. - -For example, this: - - -form_remote_tag :html => { :action => url_for(:controller => "some", :action => "place") } - - -would generate the following: - - -
- - -h5. link_to_remote - -Returns a link to a remote action that's called in the background using XMLHttpRequest. You can generate a link that uses AJAX in the general case, while degrading gracefully to plain link behavior in the absence of JavaScript. For example: - - -link_to_remote "Delete this post", - { :update => "posts", :url => { :action => "destroy", :id => post.id } }, - :href => url_for(:action => "destroy", :id => post.id) - - -h5. observe_field - -Observes the field specified and calls a callback when its contents have changed. - - -observe_field("my_field", :function => "alert('Field changed')") - - -h5. observe_form - -Observes the form specified and calls a callback when its contents have changed. The options for observe_form are the same as the options for observe_field. - - -observe_field("my_form", :function => "alert('Form changed')") - - -h5. periodically_call_remote - -Periodically calls the specified url as often as specified. Usually used to update a specified div with the results of the remote call. The following example will call update every 20 seconds and update the news_block div: - - -periodically_call_remote(:url => 'update', :frequency => '20', :update => 'news_block') -# => PeriodicalExecuter(function() {new Ajax.Updater('news_block', 'update', {asynchronous:true, evalScripts:true})}, 20) - - -h5. remote_form_for - -Creates a form that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement and a scope around a specific resource that is used as a base for questioning about values for the fields. - - -<%= remote_form_for(@post) do |f| %> - ... -<% end %> - - -h5. remote_function - -Returns the JavaScript needed for a remote function. Takes the same arguments as +link_to_remote+. - - - -# => - - h3. Localized Views Action View has the ability render different templates depending on the current locale. @@ -1520,6 +1422,7 @@ You can read more about the Rails Internationalization (I18n) API "here":i18n.ht h3. Changelog +* May 29, 2011: Removed references to remote_* helpers - Vijay Dev * April 16, 2011: Added 'Using Action View with Rails', 'Templates' and 'Partials' sections. "Sebastian Martinez":http://wyeworks.com * September 3, 2009: Continuing work by Trevor Turk, leveraging the Action Pack docs and "What's new in Edge Rails":http://ryandaigle.com/articles/2007/8/3/what-s-new-in-edge-rails-partials-get-layouts * April 5, 2009: Starting work by Trevor Turk, leveraging Mike Gunderloy's docs -- cgit v1.2.3 From 8314c8ebb9f1d85fccb6c305ad1d868f98ea84f7 Mon Sep 17 00:00:00 2001 From: Evan Farrar Date: Sun, 29 May 2011 10:37:07 -0400 Subject: Typo in the asset pipeline guide. --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 74e26ccc71..ffe6bd9529 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -30,4 +30,4 @@ h3. Packaging Assets with Your Plugin h3. More on Sprockets -Sprockets is the engine that handles the asset pipeline in Rails 3.1 and above. Their offical website is avaialbe at "http://getsprockets.org/":http://getsprockets.org/ and the source code is "on github":https://github.com/sstephenson/sprockets. +Sprockets is the engine that handles the asset pipeline in Rails 3.1 and above. Their offical website is available at "http://getsprockets.org/":http://getsprockets.org/ and the source code is "on github":https://github.com/sstephenson/sprockets. -- cgit v1.2.3 From bfce2a4cd3843226db92fb43314ef4af1afa536f Mon Sep 17 00:00:00 2001 From: Evan Farrar Date: Sun, 29 May 2011 11:25:37 -0400 Subject: Typo and sentence restructuring --- railties/guides/source/active_support_core_extensions.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 43aa6dfbbb..12c2f2413b 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -3024,7 +3024,7 @@ Date.new(2010, 1, 31).change(:month => 2) h5(#date-durations). Durations -Durations can be added and substracted to dates: +Durations can be added to and subtracted from dates: d = Date.current @@ -3232,7 +3232,7 @@ DateTime.current.change(:month => 2, :day => 30) h5(#datetime-durations). Durations -Durations can be added and substracted to datetimes: +Durations can be added to and subtracted from datetimes: now = DateTime.current @@ -3353,7 +3353,7 @@ If the time to be constructed lies beyond the range supported by +Time+ in the r h5(#time-durations). Durations -Durations can be added and substracted to time objects: +Durations can be added to and subtracted from time objects: now = Time.current -- cgit v1.2.3 From ace750871527a54bab434aaf31b1e7d80f25aaea Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Sun, 29 May 2011 20:39:33 -0400 Subject: Adding assets to a gem --- railties/guides/source/asset_pipeline.textile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index ffe6bd9529..1b2cc39f00 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -6,7 +6,7 @@ By referring to this guide you will be able to: * Properly organize your application assets * Understand the benefits of the asset pipline * Adding a preproccessor to the pipeline -* Package assets with your plugin +* Package assets with a gem endprologue. @@ -26,7 +26,9 @@ h4. Directives h4. Stacking Preproccessors -h3. Packaging Assets with Your Plugin +h3. Packaging Assets with Your Gems + +You may find it useful to package certain assets with your gem. A simple example would be the "pjax_rails":https://github.com/rails/pjax_rails/ gem. This gem bundles the latest "PJAX":https://github.com/defunkt/jquery-pjax library and some helper methods. If you take a look at the source of pjax_rails, you'll see that it bundles the assets in +lib/assets+ just the same way as you would in +app/assets+. This allows pjax_rails to update the PJAX file without forcing you to copy it to your public folder like you had to pre Rails 3.1. But if you want the user to load your JavaScript files in their template, you will have to ask them to add a directive to do so. Also avoid any common names such as +form_check.js+ instead try using +mygem/form_check.js+ so it's clear where it's coming from. This will also make it unlikely that your users will create a file with the same name causing the asset pipeline to choose the user's file over yours. h3. More on Sprockets -- cgit v1.2.3 From 91b19186f7161bc2114613b15460fb29d632aff7 Mon Sep 17 00:00:00 2001 From: Evan Farrar Date: Sun, 29 May 2011 22:06:15 -0400 Subject: Spelling corrections in the guides. --- railties/guides/source/ajax_on_rails.textile | 2 +- railties/guides/source/asset_pipeline.textile | 8 ++++---- railties/guides/source/contribute.textile | 2 +- railties/guides/source/contributing_to_ruby_on_rails.textile | 2 +- railties/guides/source/form_helpers.textile | 2 +- railties/guides/source/initialization.textile | 2 +- railties/guides/source/layouts_and_rendering.textile | 2 +- railties/guides/source/performance_testing.textile | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile index 1566c23414..8b72e20c33 100644 --- a/railties/guides/source/ajax_on_rails.textile +++ b/railties/guides/source/ajax_on_rails.textile @@ -72,7 +72,7 @@ link_to_remote "Add to cart", If the server returns 200, the output of the above example is equivalent to our first, simple one. However, in case of error, the element with the DOM id +error+ is updated rather than the +cart+ element. -** *position* By default (i.e. when not specifying this option, like in the examples before) the repsonse is injected into the element with the specified DOM id, replacing the original content of the element (if there was any). You might want to alter this behavior by keeping the original content - the only question is where to place the new content? This can specified by the +position+ parameter, with four possibilities: +** *position* By default (i.e. when not specifying this option, like in the examples before) the response is injected into the element with the specified DOM id, replacing the original content of the element (if there was any). You might want to alter this behavior by keeping the original content - the only question is where to place the new content? This can specified by the +position+ parameter, with four possibilities: *** +:before+ Inserts the response text just before the target element. More precisely, it creates a text node from the response and inserts it as the left sibling of the target element. *** +:after+ Similar behavior to +:before+, but in this case the response is inserted after the target element. *** +:top+ Inserts the text into the target element, before it's original content. If the target element was empty, this is equivalent with not specifying +:position+ at all. diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 1b2cc39f00..d34f078fc6 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -4,8 +4,8 @@ This guide will cover the ideology of the asset pipeline introduced in Rails 3.1 By referring to this guide you will be able to: * Properly organize your application assets -* Understand the benefits of the asset pipline -* Adding a preproccessor to the pipeline +* Understand the benefits of the asset pipeline +* Adding a preprocessor to the pipeline * Package assets with a gem endprologue. @@ -24,7 +24,7 @@ h4. Default Files Loaded h4. Directives -h4. Stacking Preproccessors +h4. Stacking Preprocessors h3. Packaging Assets with Your Gems @@ -32,4 +32,4 @@ You may find it useful to package certain assets with your gem. A simple example h3. More on Sprockets -Sprockets is the engine that handles the asset pipeline in Rails 3.1 and above. Their offical website is available at "http://getsprockets.org/":http://getsprockets.org/ and the source code is "on github":https://github.com/sstephenson/sprockets. +Sprockets is the engine that handles the asset pipeline in Rails 3.1 and above. Their official website is available at "http://getsprockets.org/":http://getsprockets.org/ and the source code is "on github":https://github.com/sstephenson/sprockets. diff --git a/railties/guides/source/contribute.textile b/railties/guides/source/contribute.textile index 3985cdeb2a..f9bb80861c 100644 --- a/railties/guides/source/contribute.textile +++ b/railties/guides/source/contribute.textile @@ -14,7 +14,7 @@ h3. How to Contribute? * Sample format : "Active Record Associations":https://github.com/lifo/docrails/blob/3e56a3832415476fdd1cb963980d0ae390ac1ed3/railties/guides/source/association_basics.textile. * Sample output : "Active Record Associations":association_basics.html. * You can build the Guides during testing by running +bundle exec rake generate_guides+ in the +railties+ directory. -* You're encouraged to validate XHTML for the generated guides before commiting your changes by running +bundle exec rake validate_guides+ in the +railties+ directory. +* You're encouraged to validate XHTML for the generated guides before committing your changes by running +bundle exec rake validate_guides+ in the +railties+ directory. * Edge guides "can be consulted online":http://edgeguides.rubyonrails.org/. That website is generated periodically from docrails. h3. What to Contribute? diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index 5eb925d7d2..f4d2caf7f1 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -309,7 +309,7 @@ Rails follows a simple set of coding style conventions. * a = b and not a=b. * Follow the conventions you see used in the source already. -These are some guidelines and please use your best judgement in using them. +These are some guidelines and please use your best judgment in using them. h4. Sanity Check diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index 4134c9f8ed..c7e45c0a23 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -545,7 +545,7 @@ NOTE: In many cases the built-in date pickers are clumsy as they do not aid the h4. Individual Components -Occasionally you need to display just a single date component such as a year or a month. Rails provides a series of helpers for this, one for each component +select_year+, +select_month+, +select_day+, +select_hour+, +select_minute+, +select_second+. These helpers are fairly straightforward. By default they will generate an input field named after the time component (for example "year" for +select_year+, "month" for +select_month+ etc.) although this can be overriden with the +:field_name+ option. The +:prefix+ option works in the same way that it does for +select_date+ and +select_time+ and has the same default value. +Occasionally you need to display just a single date component such as a year or a month. Rails provides a series of helpers for this, one for each component +select_year+, +select_month+, +select_day+, +select_hour+, +select_minute+, +select_second+. These helpers are fairly straightforward. By default they will generate an input field named after the time component (for example "year" for +select_year+, "month" for +select_month+ etc.) although this can be overridden with the +:field_name+ option. The +:prefix+ option works in the same way that it does for +select_date+ and +select_time+ and has the same default value. The first parameter specifies which value should be selected and can either be an instance of a Date, Time or DateTime, in which case the relevant component will be extracted, or a numerical value. For example diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 638830cd83..62b4f338ae 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -865,7 +865,7 @@ This method collects the initializers from the ancestors of this class and adds end -So this + method is overriden to return a new collection comprising of the existing collection as an array and then using the Array#+ method combines these two collections, returning a "super" +Collection+ object. In this case, the only initializer that's going to be in this new +Collection+ object is the +i18n.callbacks+ initializer. +So this + method is overridden to return a new collection comprising of the existing collection as an array and then using the Array#+ method combines these two collections, returning a "super" +Collection+ object. In this case, the only initializer that's going to be in this new +Collection+ object is the +i18n.callbacks+ initializer. The next method to be called after this +initializer+ method is the +after_initialize+ method on the +config+ object, which is defined like this: diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index d67668df91..ba45b84242 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -123,7 +123,7 @@ Cache-Control: no-cache $ -We see there is an empty response (no data after the +Cache-Control+ line), but the request was successful because Rails has set the response to 200 OK. You can set the +:status+ option on render to change this response. Rendering nothing can be useful for AJAX requests where all you want to send back to the browser is an acknowledgement that the request was completed. +We see there is an empty response (no data after the +Cache-Control+ line), but the request was successful because Rails has set the response to 200 OK. You can set the +:status+ option on render to change this response. Rendering nothing can be useful for AJAX requests where all you want to send back to the browser is an acknowledgment that the request was completed. TIP: You should probably be using the +head+ method, discussed later in this guide, instead of +render :nothing+. This provides additional flexibility and makes it explicit that you're only generating HTTP headers. diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile index 2b79237c59..83db7eee59 100644 --- a/railties/guides/source/performance_testing.textile +++ b/railties/guides/source/performance_testing.textile @@ -276,7 +276,7 @@ measurement,created_at,app,rails,ruby,platform h5(#output-profiling). Profiling -In profiling mode, performance tests can generate multiple types of outputs. The command line output is always presented but support for the others is dependant on the interpreter in use. A brief description of each type and their availability across interpreters is given below. +In profiling mode, performance tests can generate multiple types of outputs. The command line output is always presented but support for the others is dependent on the interpreter in use. A brief description of each type and their availability across interpreters is given below. h6. Command Line -- cgit v1.2.3 From d0082bfa87c5c68c8df9a962c3c6869c2abc4205 Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Mon, 30 May 2011 08:12:27 -0400 Subject: What is the asset pipeline? --- railties/guides/source/asset_pipeline.textile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index d34f078fc6..1d79284a3b 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -12,6 +12,8 @@ endprologue. h3. What Is The Asset Pipeline? +The asset pipeline is a new feature introduced in Rails 3.1 using the "Sprockets":http://getsprockets.org/ engine. It allows developers to place design elements in +app/assets+ instead of +public+, there are many advantages to this. A big one is that they are now processed by Rails instead of your webserver, allowing you to use preprocessors like CoffeeScript or SCSS. Another advantage is that your CSS and JavaScript is compiled into one file by default, this allows users to cache all the CSS and JavaScript data so your pages render faster. + h4. Why Should I Use it? Using the asset pipeline allows you to package JavaScript, CSS, or images with your Rails application, library, or plugin. It also makes it easy to create dynamic CSS with LESS and clean JavaScript with CoffeeScript to name a few of the popular preprocessors. The big difference is that they are now categorized in app/assets, treating them like first-class citizens instead of just throwing them into categorized folders in the public directory. @@ -32,4 +34,4 @@ You may find it useful to package certain assets with your gem. A simple example h3. More on Sprockets -Sprockets is the engine that handles the asset pipeline in Rails 3.1 and above. Their official website is available at "http://getsprockets.org/":http://getsprockets.org/ and the source code is "on github":https://github.com/sstephenson/sprockets. +Sprockets is the engine that handles the asset pipeline in Rails 3.1 and above. Their official website is available at "http://getsprockets.org/":http://getsprockets.org/ and the source code is "available on github":https://github.com/sstephenson/sprockets. -- cgit v1.2.3 From 910ebe1193d412cd7a08eb91e9e7692629b8b0d5 Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Mon, 30 May 2011 08:38:11 -0400 Subject: Stubbing and some content addition and changes --- railties/guides/source/asset_pipeline.textile | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 1d79284a3b..7ebc10b384 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -12,25 +12,33 @@ endprologue. h3. What Is The Asset Pipeline? -The asset pipeline is a new feature introduced in Rails 3.1 using the "Sprockets":http://getsprockets.org/ engine. It allows developers to place design elements in +app/assets+ instead of +public+, there are many advantages to this. A big one is that they are now processed by Rails instead of your webserver, allowing you to use preprocessors like CoffeeScript or SCSS. Another advantage is that your CSS and JavaScript is compiled into one file by default, this allows users to cache all the CSS and JavaScript data so your pages render faster. - -h4. Why Should I Use it? - -Using the asset pipeline allows you to package JavaScript, CSS, or images with your Rails application, library, or plugin. It also makes it easy to create dynamic CSS with LESS and clean JavaScript with CoffeeScript to name a few of the popular preprocessors. The big difference is that they are now categorized in app/assets, treating them like first-class citizens instead of just throwing them into categorized folders in the public directory. +The asset pipeline is a new feature introduced in Rails 3.1 using the "Sprockets":http://getsprockets.org/ engine. It allows developers to place design elements in +app/assets+ instead of +public+, there are many advantages to this. A big one is that they are now processed by Rails instead of your webserver, allowing you to use preprocessors like CoffeeScript, SCSS, or ERB. Another advantage is that your CSS and JavaScript is compiled into one file by default, this allows users to cache all the CSS and JavaScript data so your pages render faster. Not to mention how much cleaner your application will become. h3. How to Use the Asset Pipeline +The asset pipeline is easy to migrate to and use. There are a few things that you'll need to learn first, like where to place your files, how to create a manifest, and how to add any preproccesors if you desire. + h4. Asset Organization -h4. Default Files Loaded +Loads from /app/assets, /lib/assets, /vendor/assets, and your gem's assets h4. Directives +require_tree, require, require_self + h4. Stacking Preprocessors +filename.css.scss not filename.scss.css, how and why + +h4. Adding a Preproccessor + +https://github.com/rtomayko/tilt for gems or config.register_processor('text/css', MyAwesomeProccessor) for local stuff + h3. Packaging Assets with Your Gems -You may find it useful to package certain assets with your gem. A simple example would be the "pjax_rails":https://github.com/rails/pjax_rails/ gem. This gem bundles the latest "PJAX":https://github.com/defunkt/jquery-pjax library and some helper methods. If you take a look at the source of pjax_rails, you'll see that it bundles the assets in +lib/assets+ just the same way as you would in +app/assets+. This allows pjax_rails to update the PJAX file without forcing you to copy it to your public folder like you had to pre Rails 3.1. But if you want the user to load your JavaScript files in their template, you will have to ask them to add a directive to do so. Also avoid any common names such as +form_check.js+ instead try using +mygem/form_check.js+ so it's clear where it's coming from. This will also make it unlikely that your users will create a file with the same name causing the asset pipeline to choose the user's file over yours. +You may find it useful to package certain assets with your gem. A good example would be the "pjax_rails":https://github.com/rails/pjax_rails/ gem. This gem bundles the latest "PJAX":https://github.com/defunkt/jquery-pjax library and some helper methods. If you take a look at the source of pjax_rails, you'll see that it bundles the assets in +lib/assets+ just the same way as you would in +app/assets+. Doing so allows pjax_rails to update JavaScripts without asking users to copy them into their public folder + +If you want the user to load your JavaScript files in their template, you will have to ask them to add a directive to do so. Also avoid any common names such as +form_check.js+ instead try using +mygem/form_check.js+ so it's clear where it's coming from. This will also make it unlikely that your users will create a file with the same name causing the asset pipeline to choose the user's file over yours. h3. More on Sprockets -- cgit v1.2.3 From bdd7ecb34e5adf62b4e433454f8818f3ec6c42bf Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Tue, 31 May 2011 16:51:55 +0800 Subject: Update Rails coding conventions link. --- railties/guides/source/api_documentation_guidelines.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/api_documentation_guidelines.textile b/railties/guides/source/api_documentation_guidelines.textile index e22ffa4c04..48f6f04b21 100644 --- a/railties/guides/source/api_documentation_guidelines.textile +++ b/railties/guides/source/api_documentation_guidelines.textile @@ -38,7 +38,7 @@ h3. Example Code Choose meaningful examples that depict and cover the basics as well as interesting points or gotchas. Use two spaces to indent chunks of code.—that is two spaces with respect to the left margin; the examples -themselves should use "Rails code conventions":http://rails.lighthouseapp.com/projects/8994/source-style. +themselves should use "Rails coding conventions":contributing_to_ruby_on_rails.html#follow-the-coding-conventions. Short docs do not need an explicit "Examples" label to introduce snippets, they just follow paragraphs: -- cgit v1.2.3 From b13a0ceb5f1ff52d0a1519986e04f8fe5b30c4aa Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Tue, 31 May 2011 17:04:16 +0800 Subject: Fix punctuation. --- railties/guides/source/api_documentation_guidelines.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/api_documentation_guidelines.textile b/railties/guides/source/api_documentation_guidelines.textile index 48f6f04b21..b17f800702 100644 --- a/railties/guides/source/api_documentation_guidelines.textile +++ b/railties/guides/source/api_documentation_guidelines.textile @@ -37,7 +37,7 @@ h3. Example Code Choose meaningful examples that depict and cover the basics as well as interesting points or gotchas. -Use two spaces to indent chunks of code.—that is two spaces with respect to the left margin; the examples +Use two spaces to indent chunks of code--that is two spaces with respect to the left margin; the examples themselves should use "Rails coding conventions":contributing_to_ruby_on_rails.html#follow-the-coding-conventions. Short docs do not need an explicit "Examples" label to introduce snippets, they just follow paragraphs: -- cgit v1.2.3 From 6014e1d3258baef4e5b08a29876b7758363c2c22 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 1 Jun 2011 17:19:23 +0900 Subject: s/an/a/ --- railties/guides/source/action_view_overview.textile | 2 +- railties/guides/source/active_record_validations_callbacks.textile | 2 +- railties/guides/source/contributing_to_ruby_on_rails.textile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile index 8c6a82d50c..a3454579ad 100644 --- a/railties/guides/source/action_view_overview.textile +++ b/railties/guides/source/action_view_overview.textile @@ -929,7 +929,7 @@ Creates a scope around a specific model object like form_for, but doesn‘t crea h5. file_field -Returns an file upload input tag tailored for accessing a specified attribute. +Returns a file upload input tag tailored for accessing a specified attribute. file_field(:user, :avatar) diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 9f59397d7d..353779ef7d 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -429,7 +429,7 @@ end The +validates_with+ helper takes a class, or a list of classes to use for validation. There is no default error message for +validates_with+. You must manually add errors to the record's errors collection in the validator class. -To implement the validate method, you must have an +record+ parameter defined, which is the record to be validated. +To implement the validate method, you must have a +record+ parameter defined, which is the record to be validated. Like all other validations, +validates_with+ takes the +:if+, +:unless+ and +:on+ options. If you pass any other options, it will send those options to the validator class as +options+: diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index f4d2caf7f1..1e9a77bcb6 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -90,7 +90,7 @@ This command will install all dependencies except the MySQL and PostgreSQL Ruby $ rake test -You can also run tests for an specific framework, like Action Pack, by going into its directory and executing the same command: +You can also run tests for a specific framework, like Action Pack, by going into its directory and executing the same command: $ cd actionpack -- cgit v1.2.3 From 90887cbb355f583931cba70adc460b88fca7395f Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 1 Jun 2011 17:48:09 +0900 Subject: s/a/an/ --- railties/guides/source/active_support_core_extensions.textile | 2 +- railties/guides/source/contributing_to_ruby_on_rails.textile | 2 +- railties/guides/source/generators.textile | 2 +- railties/guides/source/getting_started.textile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 12c2f2413b..7512f7bcb9 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -868,7 +868,7 @@ The macro accepts several methods: delegate :name, :age, :address, :twitter, :to => :profile -When interpolated into a string, the +:to+ option should become an expression that evaluates to the object the method is delegated to. Typically a string or symbol. Such a expression is evaluated in the context of the receiver: +When interpolated into a string, the +:to+ option should become an expression that evaluates to the object the method is delegated to. Typically a string or symbol. Such an expression is evaluated in the context of the receiver: # delegates to the Rails constant diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index 1e9a77bcb6..45a0254cbe 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -24,7 +24,7 @@ If you've found a problem in Ruby on Rails which is not a security risk do a sea At the minimum, your issue report needs a title and descriptive text. But that's only a minimum. You should include as much relevant information as possible. You need to at least post the code sample that has the issue. Even better is to include a unit test that shows how the expected behavior is not occurring. Your goal should be to make it easy for yourself - and others - to replicate the bug and figure out a fix. -Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kind of bug, you're creating this issue report in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the issue report will automatically see any activity or that others will jump to fix it. Creating a issue like this is mostly to help yourself start on the path of fixing the problem and for others to confirm it with a "I'm having this problem too" comment. +Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kind of bug, you're creating this issue report in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the issue report will automatically see any activity or that others will jump to fix it. Creating an issue like this is mostly to help yourself start on the path of fixing the problem and for others to confirm it with a "I'm having this problem too" comment. h4. Special Treatment for Security Issues diff --git a/railties/guides/source/generators.textile b/railties/guides/source/generators.textile index a3181b9ac5..54b3785bf7 100644 --- a/railties/guides/source/generators.textile +++ b/railties/guides/source/generators.textile @@ -131,7 +131,7 @@ And let's execute our generator: $ rails generate initializer core_extensions -We can see that now a initializer named core_extensions was created at +config/initializers/core_extensions.rb+ with the contents of our template. That means that +copy_file+ copied a file in our source root to the destination path we gave. The method +file_name+ is automatically created when we inherit from +Rails::Generators::NamedBase+. +We can see that now an initializer named core_extensions was created at +config/initializers/core_extensions.rb+ with the contents of our template. That means that +copy_file+ copied a file in our source root to the destination path we gave. The method +file_name+ is automatically created when we inherit from +Rails::Generators::NamedBase+. The methods that are available for generators are covered in the "final section":#generator-methods of this guide. diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 8a9086f416..670979c3c2 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -503,7 +503,7 @@ def index end -+Post.all+ calls the +Post+ model to return all of the posts currently in the database. The result of this call is an array of posts that we store in a instance variable called +@posts+. ++Post.all+ calls the +Post+ model to return all of the posts currently in the database. The result of this call is an array of posts that we store in an instance variable called +@posts+. TIP: For more information on finding records with Active Record, see "Active Record Query Interface":active_record_querying.html. -- cgit v1.2.3 From a632746a6aad26bcd1f4e54c2fde30495cb6236e Mon Sep 17 00:00:00 2001 From: brianp Date: Thu, 2 Jun 2011 15:03:36 -0700 Subject: Fixed sections regarding validations and callbacks to mention the touch method does not fire either validations or callbacks as stated in the docs. --- railties/guides/source/active_record_validations_callbacks.textile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 353779ef7d..7140353a15 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -82,6 +82,7 @@ The following methods skip validations, and will save the object to the database * +increment!+ * +increment_counter+ * +toggle!+ +* +touch+ * +update_all+ * +update_attribute+ * +update_column+ @@ -1007,6 +1008,7 @@ Just as with validations, it's also possible to skip callbacks. These methods sh * +increment+ * +increment_counter+ * +toggle+ +* +touch+ * +update_column+ * +update_all+ * +update_counters+ -- cgit v1.2.3 From b4af5b9d490506f2a1f8e2be37b9fec547aa7e97 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 3 Jun 2011 14:13:04 +0530 Subject: fix indentation, fixed-width for nils --- railties/guides/source/configuring.textile | 36 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index e5b7c3e338..7ddd06da3b 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -121,10 +121,10 @@ h4. Configuring Generators Rails 3 allows you to alter what generators are used with the +config.generators+ method. This method takes a block: - config.generators do |g| - g.orm :active_record - g.test_framework :test_unit - end +config.generators do |g| + g.orm :active_record + g.test_framework :test_unit +end The full set of methods that can be used in this block are as follows: @@ -167,31 +167,31 @@ Every Rails application comes with a standard set of middleware which it uses in Besides these usual middleware, you can add your own by using the +config.middleware.use+ method: - config.middleware.use Magical::Unicorns +config.middleware.use Magical::Unicorns This will put the +Magical::Unicorns+ middleware on the end of the stack. If you wish to put this middleware before another use +insert_before+: - config.middleware.insert_before ActionDispatch::Head, Magical::Unicorns +config.middleware.insert_before ActionDispatch::Head, Magical::Unicorns There's also +insert_after+ which will insert a middleware _after_ another: - config.middleware.insert_after ActionDispatch::Head, Magical::Unicorns +config.middleware.insert_after ActionDispatch::Head, Magical::Unicorns Middlewares can also be completely swapped out and replaced with others: - config.middleware.swap ActionDispatch::BestStandardsSupport, Magical::Unicorns +config.middleware.swap ActionDispatch::BestStandardsSupport, Magical::Unicorns They can also be removed from the stack completely: - config.middleware.delete ActionDispatch::BestStandardsSupport +config.middleware.delete ActionDispatch::BestStandardsSupport h4. Configuring i18n @@ -204,7 +204,7 @@ h4. Configuring Active Record config.active_record includes a variety of configuration options: -* +config.active_record.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8.x Logger class, which is then passed on to any new database connections made. You can retrieve this logger by calling +logger+ on either an Active Record model class or an Active Record model instance. Set to nil to disable logging. +* +config.active_record.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8.x Logger class, which is then passed on to any new database connections made. You can retrieve this logger by calling +logger+ on either an Active Record model class or an Active Record model instance. Set to +nil+ to disable logging. * +config.active_record.primary_key_prefix_type+ lets you adjust the naming for primary key columns. By default, Rails assumes that primary key columns are named +id+ (and this configuration option doesn't need to be set.) There are two other choices: ** +:table_name+ would make the primary key for the Customer class +customerid+ @@ -250,7 +250,7 @@ h4. Configuring Action Controller * +config.action_controller.default_charset+ specifies the default character set for all renders. The default is "utf-8". -* +config.action_controller.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Action Controller. Set to nil to disable logging. +* +config.action_controller.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Action Controller. Set to +nil+ to disable logging. * +config.action_controller.request_forgery_protection_token+ sets the token parameter name for RequestForgery. Calling +protect_from_forgery+ sets it to +:authenticity_token+ by default. @@ -292,7 +292,7 @@ There are only a few configuration options for Action View, starting with four o * +config.action_view.default_form_builder+ tells Rails which form builder to use by default. The default is +ActionView::Helpers::FormBuilder+. -* +config.action_view.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Action Mailer. Set to nil to disable logging. +* +config.action_view.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Action Mailer. Set to +nil+ to disable logging. * +config.action_view.erb_trim_mode+ gives the trim mode to be used by ERB. It defaults to +'-'+. See the "ERB documentation":http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/ for more information. @@ -326,7 +326,7 @@ h4. Configuring Action Mailer There are a number of settings available on +config.action_mailer+: -* +config.action_mailer.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Action Mailer. Set to nil to disable logging. +* +config.action_mailer.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Action Mailer. Set to +nil+ to disable logging. * +config.action_mailer.smtp_settings+ allows detailed configuration for the +:smtp+ delivery method. It accepts a hash of options, which can include any of these options: ** +:address+ - Allows you to use a remote mail server. Just change it from its default "localhost" setting. @@ -348,17 +348,17 @@ There are a number of settings available on +config.action_mailer+: * +config.action_mailer.default+ configures Action Mailer defaults. These default to: - :mime_version => "1.0", - :charset => "UTF-8", - :content_type => "text/plain", - :parts_order => [ "text/plain", "text/enriched", "text/html" ] +:mime_version => "1.0", +:charset => "UTF-8", +:content_type => "text/plain", +:parts_order => [ "text/plain", "text/enriched", "text/html" ] h4. Configuring Active Resource There is a single configuration setting available on +config.active_resource+: -* +config.active_resource.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Active Resource. Set to nil to disable logging. +* +config.active_resource.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Active Resource. Set to +nil+ to disable logging. h4. Configuring Active Support -- cgit v1.2.3 From b688f44390733cbe4b78373dec7c96e4cddec148 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 3 Jun 2011 14:14:23 +0530 Subject: use 'bundle exec rake' --- railties/guides/source/ruby_on_rails_guides_guidelines.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/ruby_on_rails_guides_guidelines.textile b/railties/guides/source/ruby_on_rails_guides_guidelines.textile index 9ae360a73b..5989191b5c 100644 --- a/railties/guides/source/ruby_on_rails_guides_guidelines.textile +++ b/railties/guides/source/ruby_on_rails_guides_guidelines.textile @@ -65,7 +65,7 @@ It is also recommended that you work with +WARNINGS=1+. This detects duplicate I If you want to generate guides in languages other than English, you can keep them in a separate directory under +source+ (eg. source/es) and use the +GUIDES_LANGUAGE+ environment variable: -rake generate_guides GUIDES_LANGUAGE=es +bundle exec rake generate_guides GUIDES_LANGUAGE=es h3. HTML Validation @@ -73,7 +73,7 @@ h3. HTML Validation Please validate the generated HTML with: -rake validate_guides +bundle exec rake validate_guides Particularly, titles get an ID generated from their content and this often leads to duplicates. Please set +WARNINGS=1+ when generating guides to detect them. The warning messages suggest a way to fix them. -- cgit v1.2.3 From 72f51990b72482df41c1711b43e77f94177224be Mon Sep 17 00:00:00 2001 From: Linux on Rails Date: Fri, 3 Jun 2011 03:01:41 -0700 Subject: FIXED: error with url_for & link_to when we have nested resources. --- railties/guides/source/routing.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 08615bed4e..1cbc5c8f6e 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -288,7 +288,7 @@ When using +magazine_ad_path+, you can pass in instances of +Magazine+ and +Ad+ You can also use +url_for+ with a set of objects, and Rails will automatically determine which route you want: -<%= link_to "Ad details", url_for(@magazine, @ad) %> +<%= link_to "Ad details", url_for([@magazine, @ad]) %> In this case, Rails will see that +@magazine+ is a +Magazine+ and +@ad+ is an +Ad+ and will therefore use the +magazine_ad_path+ helper. In helpers like +link_to+, you can specify just the object in place of the full +url_for+ call: -- cgit v1.2.3 From 2eac4e2e2ff3a740c71268bfb78ebf0b72efc48d Mon Sep 17 00:00:00 2001 From: Alberto Perdomo Date: Sat, 4 Jun 2011 14:26:40 +0100 Subject: Fixed order of parameters in assert_equal call examples, first expected, then actual object. --- railties/guides/source/testing.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index 7a93c3a1e6..db9c7545c8 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -929,8 +929,8 @@ class UserControllerTest < ActionController::TestCase end invite_email = ActionMailer::Base.deliveries.first - assert_equal invite_email.subject, "You have been invited by me@example.com" - assert_equal invite_email.to[0], 'friend@example.com' + assert_equal "You have been invited by me@example.com", invite_email.subject + assert_equal 'friend@example.com', invite_email.to[0] assert_match /Hi friend@example.com/, invite_email.body end end -- cgit v1.2.3 From 9d15a35981ccce30ffbf363de1a56944c8da4e52 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 4 Jun 2011 20:44:11 +0530 Subject: minor corrections in generators guide --- railties/guides/source/generators.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/generators.textile b/railties/guides/source/generators.textile index 54b3785bf7..2fa1d6e21d 100644 --- a/railties/guides/source/generators.textile +++ b/railties/guides/source/generators.textile @@ -46,7 +46,7 @@ class InitializerGenerator < Rails::Generators::Base end -NOTE: +create_file+ is a method provided by +Thor::Actions+ and the documentation for it and its brethren can be found at "rdoc.info":http://rdoc.info/github/wycats/thor/master/Thor/Actions. +NOTE: +create_file+ is a method provided by +Thor::Actions+. Documentation for +create_file+ and other Thor methods can be found in "Thor's documentation":http://rdoc.info/github/wycats/thor/master/Thor/Actions.html Our new generator is quite simple: it inherits from +Rails::Generators::Base+ and has one method definition. Each public method in the generator is executed when a generator is invoked. Finally, we invoke the +create_file+ method that will create a file at the given destination with the given content. If you are familiar with the Rails Application Templates API, you'll feel right at home with the new generators API. @@ -365,7 +365,7 @@ $ rails generate scaffold Comment body:text Fallbacks allow your generators to have a single responsibility, increasing code reuse and reducing the amount of duplication. -h3. Application templates +h3. Application Templates Now that you've seen how generators can be used _inside_ an application, did you know they can also be used to _generate_ applications too? This kind of generator is referred as a "template". -- cgit v1.2.3 From 087f8e16a6aa889cea2262d8f5dff2578b605c68 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 4 Jun 2011 23:51:00 +0530 Subject: s/ActiveRecord/Active Record according to api guidelines --- railties/guides/source/caching_with_rails.textile | 2 +- railties/guides/source/configuring.textile | 6 +++--- railties/guides/source/i18n.textile | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile index 91827fd493..cebf49573d 100644 --- a/railties/guides/source/caching_with_rails.textile +++ b/railties/guides/source/caching_with_rails.textile @@ -345,7 +345,7 @@ ActionController::Base.cache_store = MyCacheStore.new h4. Cache Keys -The keys used in a cache can be any object that responds to either +:cache_key+ or to +:to_param+. You can implement the +:cache_key+ method on your classes if you need to generate custom keys. ActiveRecord will generate keys based on the class name and record id. +The keys used in a cache can be any object that responds to either +:cache_key+ or to +:to_param+. You can implement the +:cache_key+ method on your classes if you need to generate custom keys. Active Record will generate keys based on the class name and record id. You can use Hashes and Arrays of values as cache keys. diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index 7ddd06da3b..dd66fd15bb 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -216,19 +216,19 @@ h4. Configuring Active Record * +config.active_record.pluralize_table_names+ specifies whether Rails will look for singular or plural table names in the database. If set to +true+ (the default), then the Customer class will use the +customers+ table. If set to +false+, then the Customers class will use the +customer+ table. -* +config.active_record.default_timezone+ determines whether to use +Time.local+ (if set to +:local+) or +Time.utc+ (if set to +:utc+) when pulling dates and times from the database. The default is +:utc+ for Rails, although ActiveRecord defaults to +:local+ when used outside of Rails. +* +config.active_record.default_timezone+ determines whether to use +Time.local+ (if set to +:local+) or +Time.utc+ (if set to +:utc+) when pulling dates and times from the database. The default is +:utc+ for Rails, although Active Record defaults to +:local+ when used outside of Rails. * +config.active_record.schema_format+ controls the format for dumping the database schema to a file. The options are +:ruby+ (the default) for a database-independent version that depends on migrations, or +:sql+ for a set of (potentially database-dependent) SQL statements. * +config.active_record.timestamped_migrations+ controls whether migrations are numbered with serial integers or with timestamps. The default is +true+, to use timestamps, which are preferred if there are multiple developers working on the same application. -* +config.active_record.lock_optimistically+ controls whether ActiveRecord will use optimistic locking. By default this is +true+. +* +config.active_record.lock_optimistically+ controls whether Active Record will use optimistic locking. By default this is +true+. * +config.active_record.whitelist_attributes+ will create an empty whitelist of attributes available for mass-assignment security for all models in your app. The MySQL adapter adds one additional configuration option: -* +ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans+ controls whether ActiveRecord will consider all +tinyint(1)+ columns in a MySQL database to be booleans. By default this is +true+. +* +ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans+ controls whether Active Record will consider all +tinyint(1)+ columns in a MySQL database to be booleans. By default this is +true+. The schema dumper adds one additional configuration option: diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index 608643b3d3..0c8e4e974d 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -809,7 +809,7 @@ That does not mean you're stuck with these limitations, though. The Ruby I18n ge I18n.backend = Globalize::Backend::Static.new -You can also use the Chain backend to chain multiple backends together. This is useful when you want to use standard translations with a Simple backend but store custom application translations in a database or other backends. For example, you could use the ActiveRecord backend and fall back to the (default) Simple backend: +You can also use the Chain backend to chain multiple backends together. This is useful when you want to use standard translations with a Simple backend but store custom application translations in a database or other backends. For example, you could use the Active Record backend and fall back to the (default) Simple backend: I18n.backend = I18n::Backend::Chain.new(I18n::Backend::ActiveRecord.new, I18n.backend) -- cgit v1.2.3 From 9f19322b1f9eee99b5f8f5a2e85b1e3a27f82c64 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 5 Jun 2011 00:58:21 +0530 Subject: correct code indendation in the initialization guide --- railties/guides/source/initialization.textile | 621 +++++++++++++------------- 1 file changed, 311 insertions(+), 310 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 62b4f338ae..1d5b0c0c11 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -20,15 +20,15 @@ h4. +bin/rails+ The actual +rails+ command is kept in _bin/rails_ at the and goes like this: - #!/usr/bin/env ruby - - begin - require "rails/cli" - rescue LoadError - railties_path = File.expand_path('../../railties/lib', __FILE__) - $:.unshift(railties_path) - require "rails/cli" - end +#!/usr/bin/env ruby + +begin + require "rails/cli" +rescue LoadError + railties_path = File.expand_path('../../railties/lib', __FILE__) + $:.unshift(railties_path) + require "rails/cli" +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. @@ -38,22 +38,22 @@ h4. +railites/lib/rails/cli.rb+ This file looks like this: - require 'rbconfig' - require 'rails/script_rails_loader' +require 'rbconfig' +require 'rails/script_rails_loader' - # If we are inside a Rails application this method performs an exec and thus - # the rest of this script is not run. - Rails::ScriptRailsLoader.exec_script_rails! +# If we are inside a Rails application this method performs an exec and thus +# the rest of this script is not run. +Rails::ScriptRailsLoader.exec_script_rails! - require 'rails/ruby_version_check' - Signal.trap("INT") { puts; exit } +require 'rails/ruby_version_check' +Signal.trap("INT") { puts; exit } - if ARGV.first == 'plugin' - ARGV.shift - require 'rails/commands/plugin_new' - else - require 'rails/commands/application' - end +if ARGV.first == 'plugin' + ARGV.shift + require 'rails/commands/plugin_new' +else + require 'rails/commands/application' +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+. @@ -76,46 +76,46 @@ The +rails/script_rails_loader+ file uses +RbConfig::Config+ to gather up the +b Back in +rails/cli+, the next line is this: - Rails::ScriptRailsLoader.exec_script_rails! +Rails::ScriptRailsLoader.exec_script_rails! This method is defined in +rails/script_rails_loader+ like this: - def self.exec_script_rails! - cwd = Dir.pwd - return unless in_rails_application? || in_rails_application_subdirectory? - exec RUBY, SCRIPT_RAILS, *ARGV if in_rails_application? - Dir.chdir("..") do - # Recurse in a chdir block: if the search fails we want to be sure - # the application is generated in the original working directory. - exec_script_rails! unless cwd == Dir.pwd - end - rescue SystemCallError - # could not chdir, no problem just return +def self.exec_script_rails! + cwd = Dir.pwd + return unless in_rails_application? || in_rails_application_subdirectory? + exec RUBY, SCRIPT_RAILS, *ARGV if in_rails_application? + Dir.chdir("..") do + # Recurse in a chdir block: if the search fails we want to be sure + # the application is generated in the original working directory. + exec_script_rails! unless cwd == Dir.pwd end +rescue SystemCallError + # could not chdir, no problem just return +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: - def self.in_rails_application? - File.exists?(SCRIPT_RAILS) - end +def self.in_rails_application? + File.exists?(SCRIPT_RAILS) +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: - def self.in_rails_application_subdirectory?(path = Pathname.new(Dir.pwd)) - File.exists?(File.join(path, SCRIPT_RAILS)) || !path.root? && in_rails_application_subdirectory?(path.parent) - end +def self.in_rails_application_subdirectory?(path = Pathname.new(Dir.pwd)) + File.exists?(File.join(path, SCRIPT_RAILS)) || !path.root? && in_rails_application_subdirectory?(path.parent) +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: - exec RUBY, SCRIPT_RAILS, *ARGV if in_rails_application? +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". @@ -125,9 +125,9 @@ h4. +script/rails+ This file looks like this: - APP_PATH = File.expand_path('../../config/application', __FILE__) - require File.expand_path('../../config/boot', __FILE__) - require 'rails/commands' +APP_PATH = File.expand_path('../../config/application', __FILE__) +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. @@ -137,19 +137,19 @@ h4. +config/boot.rb+ +config/boot.rb+ contains this: - require 'rubygems' +require 'rubygems' - # Set up gems listed in the Gemfile. - gemfile = File.expand_path('../../Gemfile', __FILE__) - begin - ENV['BUNDLE_GEMFILE'] = gemfile - require 'bundler' - Bundler.setup - rescue Bundler::GemNotFound => e - STDERR.puts e.message - STDERR.puts "Try running `bundle install`." - exit! - end if File.exist?(gemfile) +# Set up gems listed in the Gemfile. +gemfile = File.expand_path('../../Gemfile', __FILE__) +begin + ENV['BUNDLE_GEMFILE'] = gemfile + require 'bundler' + Bundler.setup +rescue Bundler::GemNotFound => e + STDERR.puts e.message + STDERR.puts "Try running `bundle install`." + exit! +end if File.exist?(gemfile) In a standard Rails application, there's a +Gemfile+ which declares all dependencies of the application. +config/boot.rb+ sets +ENV["BUNDLE_GEMFILE"]+ to the location of this file, then requires Bundler and calls +Bundler.setup+ which adds the dependencies of the application (including all the Rails parts) to the load path, making them available for the application to load. The gems that a Rails 3.1 application depends on are as follows: @@ -186,34 +186,34 @@ h4. +rails/commands.rb+ Once +config/boot.rb+ has finished, the next file that is required is +rails/commands+ which will execute a command based on the arguments passed in. In this case, the +ARGV+ array simply contains +server+ which is extracted into the +command+ variable using these lines: - aliases = { - "g" => "generate", - "c" => "console", - "s" => "server", - "db" => "dbconsole" - } +aliases = { + "g" => "generate", + "c" => "console", + "s" => "server", + "db" => "dbconsole" +} - command = ARGV.shift - command = aliases[command] || command +command = ARGV.shift +command = aliases[command] || command If we used s rather than +server+, Rails will use the +aliases+ defined in the file and match them to their respective commands. With the +server+ command, Rails will run this code: - when 'server' - # Change to the application's path if there is no config.ru file in current dir. - # This allows us to run script/rails server from other directories, but still get - # the main config.ru and properly set the tmp directory. - Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exists?(File.expand_path("config.ru")) - - require 'rails/commands/server' - Rails::Server.new.tap { |server| - # We need to require application after the server sets environment, - # otherwise the --environment option given to the server won't propagate. - require APP_PATH - Dir.chdir(Rails.application.root) - server.start - } +when 'server' + # Change to the application's path if there is no config.ru file in current dir. + # This allows us to run script/rails server from other directories, but still get + # the main config.ru and properly set the tmp directory. + Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exists?(File.expand_path("config.ru")) + + require 'rails/commands/server' + Rails::Server.new.tap { |server| + # We need to require application after the server sets environment, + # otherwise the --environment option given to the server won't propagate. + require APP_PATH + Dir.chdir(Rails.application.root) + server.start + } This file will change into the root of the directory (a path two directories back from +APP_PATH+ which points at +config/application.rb+), but only if the +config.ru+ file isn't found. This then requires +rails/commands/server+ which requires +action_dispatch+ and sets up the +Rails::Server+ class. @@ -239,7 +239,7 @@ The +methods.rb+ file is responsible for defining methods such as +camelize+, +u In this file there are a lot of lines such as this inside the +ActiveSupport+ module: - autoload :Inflector +autoload :Inflector Due to the overriding of the +autoload+ method, Ruby will know to look for this file at +activesupport/lib/active_support/inflector.rb+ when the +Inflector+ class is first referenced. @@ -263,10 +263,10 @@ h4. +rails/commands/server.rb+ The +Rails::Server+ class is defined in this file as inheriting from +Rack::Server+. When +Rails::Server.new+ is called, this calls the +initialize+ method in +rails/commands/server.rb+: - def initialize(*) - super - set_environment - end +def initialize(*) + super + set_environment +end Firstly, +super+ is called which calls the +initialize+ method on +Rack::Server+. @@ -278,10 +278,10 @@ h4. Rack: +lib/rack/server.rb+ The +initialize+ method in +Rack::Server+ simply sets a couple of variables: - def initialize(options = nil) - @options = options - @app = options[:app] if options && options[:app] - end +def initialize(options = nil) + @options = options + @app = options[:app] if options && options[:app] +end In this case, +options+ will be +nil+ so nothing happens in this method. @@ -289,64 +289,64 @@ In this case, +options+ will be +nil+ so nothing happens in this method. After +super+ has finished in +Rack::Server+, we jump back to +rails/commands/server.rb+. At this point, +set_environment+ is called within the context of the +Rails::Server+ object and this method doesn't appear to do much at first glance: - def set_environment - ENV["RAILS_ENV"] ||= options[:environment] - end +def set_environment + ENV["RAILS_ENV"] ||= options[:environment] +end In fact, the +options+ method here does quite a lot. This method is defined in +Rack::Server+ like this: - def options - @options ||= parse_options(ARGV) - end +def options + @options ||= parse_options(ARGV) +end Then +parse_options+ is defined like this: - def parse_options(args) - options = default_options +def parse_options(args) + options = default_options - # Don't evaluate CGI ISINDEX parameters. - # http://hoohoo.ncsa.uiuc.edu/cgi/cl.html - args.clear if ENV.include?("REQUEST_METHOD") + # Don't evaluate CGI ISINDEX parameters. + # http://hoohoo.ncsa.uiuc.edu/cgi/cl.html + args.clear if ENV.include?("REQUEST_METHOD") - options.merge! opt_parser.parse! args - options[:config] = ::File.expand_path(options[:config]) - ENV["RACK_ENV"] = options[:environment] - options - end + options.merge! opt_parser.parse! args + options[:config] = ::File.expand_path(options[:config]) + ENV["RACK_ENV"] = options[:environment] + options +end With the +default_options+ set to this: - def default_options - { - :environment => ENV['RACK_ENV'] || "development", - :pid => nil, - :Port => 9292, - :Host => "0.0.0.0", - :AccessLog => [], - :config => "config.ru" - } - end +def default_options + { + :environment => ENV['RACK_ENV'] || "development", + :pid => nil, + :Port => 9292, + :Host => "0.0.0.0", + :AccessLog => [], + :config => "config.ru" + } +end There is no +REQUEST_METHOD+ key in +ENV+ so we can skip over that line. The next line merges in the options from +opt_parser+ which is defined plainly in +Rack::Server+ - def opt_parser - Options.new - end +def opt_parser + Options.new +end The class *is* defined in +Rack::Server+, but is overwritten in +Rails::Server+ to take different arguments. Its +parse!+ method begins like this: - def parse!(args) - args, options = args.dup, {} +def parse!(args) + args, options = args.dup, {} opt_parser = OptionParser.new do |opts| opts.banner = "Usage: rails server [mongrel, thin, etc] [options]" @@ -362,100 +362,101 @@ h4. +Rails::Server#start+ This method is defined like this: - def start - puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}" - puts "=> Rails #{Rails.version} application starting in #{Rails.env} on http://#{options[:Host]}:#{options[:Port]}" - puts "=> Call with -d to detach" unless options[:daemonize] - trap(:INT) { exit } - puts "=> Ctrl-C to shutdown server" unless options[:daemonize] - - #Create required tmp directories if not found - %w(cache pids sessions sockets).each do |dir_to_make| - FileUtils.mkdir_p(Rails.root.join('tmp', dir_to_make)) - end - - super - ensure - # The '-h' option calls exit before @options is set. - # If we call 'options' with it unset, we get double help banners. - puts 'Exiting' unless @options && options[:daemonize] +def start + puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}" + puts "=> Rails #{Rails.version} application starting in #{Rails.env} on http://#{options[:Host]}:#{options[:Port]}" + puts "=> Call with -d to detach" unless options[:daemonize] + trap(:INT) { exit } + puts "=> Ctrl-C to shutdown server" unless options[:daemonize] + + #Create required tmp directories if not found + %w(cache pids sessions sockets).each do |dir_to_make| + FileUtils.mkdir_p(Rails.root.join('tmp', dir_to_make)) end + + super +ensure + # The '-h' option calls exit before @options is set. + # If we call 'options' with it unset, we get double help banners. + puts 'Exiting' unless @options && options[:daemonize] +end This is where the first output of the Rails initialization happens. This method creates a trap for +INT+ signals, so if you +CTRL+C+ the server, it will exit the process. As we can see from the code here, it will create the +tmp/cache+, +tmp/pids+, +tmp/sessions+ and +tmp/sockets+ directories if they don't already exist prior to calling +super+. The +super+ method will call +Rack::Server.start+ which begins its definition like this: - def start - if options[:warn] - $-w = true - end +def start + if options[:warn] + $-w = true + end - if includes = options[:include] - $LOAD_PATH.unshift(*includes) - end + if includes = options[:include] + $LOAD_PATH.unshift(*includes) + end - if library = options[:require] - require library - end + if library = options[:require] + require library + end - if options[:debug] - $DEBUG = true - require 'pp' - p options[:server] - pp wrapped_app - pp app - end + if options[:debug] + $DEBUG = true + require 'pp' + p options[:server] + pp wrapped_app + pp app + end +end In a Rails application, these options are not set at all and therefore aren't used at all. The first line of code that's executed in this method is a call to this method: - wrapped_app +wrapped_app This method calls another method: - @wrapped_app ||= build_app app +@wrapped_app ||= build_app app Then the +app+ method here is defined like so: - def app - @app ||= begin - if !::File.exist? options[:config] - abort "configuration #{options[:config]} not found" - end - - app, options = Rack::Builder.parse_file(self.options[:config], opt_parser) - self.options.merge! options - app +def app + @app ||= begin + if !::File.exist? options[:config] + abort "configuration #{options[:config]} not found" end + + app, options = Rack::Builder.parse_file(self.options[:config], opt_parser) + self.options.merge! options + app end +end The +options[:config]+ value defaults to +config.ru+ which contains this: - # This file is used by Rack-based servers to start the application. +# This file is used by Rack-based servers to start the application. - require ::File.expand_path('../config/environment', __FILE__) - run YourApp::Application +require ::File.expand_path('../config/environment', __FILE__) +run YourApp::Application The +Rack::Builder.parse_file+ method here takes the content from this +config.ru+ file and parses it using this code: - app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app", +app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app", TOPLEVEL_BINDING, config The initialize method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run: - require ::File.expand_path('../config/environment', __FILE__) +require ::File.expand_path('../config/environment', __FILE__) h4. +config/environment.rb+ @@ -475,7 +476,7 @@ h3. Loading Rails The next line in +config/application.rb+ is: - require 'rails/all' +require 'rails/all' h4. +railties/lib/rails/all.rb+ @@ -483,20 +484,20 @@ h4. +railties/lib/rails/all.rb+ This file is responsible for requiring all the individual parts of Rails like so: - require "rails" +require "rails" - %w( +%w( active_record action_controller action_mailer active_resource rails/test_unit - ).each do |framework| - begin - require "#{framework}/railtie" - rescue LoadError - end +).each do |framework| + begin + require "#{framework}/railtie" + rescue LoadError end +end First off the line is the +rails+ require itself. @@ -518,9 +519,9 @@ h4. +active_support/core_ext/kernel/reporting.rb+ This is the first of the many Active Support core extensions that come with Rails. This one in particular defines methods in the +Kernel+ module which is mixed in to the +Object+ class so the methods are available on +main+ and can therefore be called like this: - silence_warnings do - # some code - end +silence_warnings do + # some code +end These methods can be used to silence STDERR responses and the +silence_stream+ allows you to also silence other streams. Additionally, this mixin allows you to suppress exceptions and capture streams. For more information see the "Silencing Warnings, Streams, and Exceptions":http://guides.rubyonrails.org/active_support_core_extensions.html#silencing-warnings-streams-and-exceptions section from the Active Support Core Extensions Guide. @@ -635,14 +636,14 @@ h4. +railties/lib/rails/rack.rb+ The final file to be loaded by +railties/lib/rails/configuration.rb+ is +rails/rack+ which defines some simple autoloads: - module Rails - module Rack - autoload :Debugger, "rails/rack/debugger" - autoload :Logger, "rails/rack/logger" - autoload :LogTailer, "rails/rack/log_tailer" - autoload :Static, "rails/rack/static" - end +module Rails + module Rack + autoload :Debugger, "rails/rack/debugger" + autoload :Logger, "rails/rack/logger" + autoload :LogTailer, "rails/rack/log_tailer" + autoload :Static, "rails/rack/static" end +end Once this file is finished loading, then the +Rails::Configuration+ class is initialized. This completes the loading of +railties/lib/rails/configuration.rb+ and now we jump back to the loading of +railties/lib/rails/railtie.rb+, where the next file loaded is +active_support/inflector+. @@ -652,12 +653,12 @@ h4. +activesupport/lib/active_support/inflector.rb+ +active_support/inflector.rb+ requires a series of file which are responsible for setting up the basics for knowing how to pluralize and singularize words. These files are: - require 'active_support/inflector/inflections' - require 'active_support/inflector/transliterate' - require 'active_support/inflector/methods' +require 'active_support/inflector/inflections' +require 'active_support/inflector/transliterate' +require 'active_support/inflector/methods' - require 'active_support/inflections' - require 'active_support/core_ext/string/inflections' +require 'active_support/inflections' +require 'active_support/core_ext/string/inflections' The +active_support/inflector/methods+ file has already been required by +active_support/autoload+ and so won't be loaded again here. @@ -721,22 +722,22 @@ h4. +activesupport/lib/active_support/i18n_railtie.rb+ This file is the first file that sets up configuration with these lines inside the class: - class Railtie < Rails::Railtie - config.i18n = ActiveSupport::OrderedOptions.new - config.i18n.railties_load_path = [] - config.i18n.load_path = [] - config.i18n.fallbacks = ActiveSupport::OrderedOptions.new +class Railtie < Rails::Railtie + config.i18n = ActiveSupport::OrderedOptions.new + config.i18n.railties_load_path = [] + config.i18n.load_path = [] + config.i18n.fallbacks = ActiveSupport::OrderedOptions.new By inheriting from +Rails::Railtie+ the +Rails::Railtie#inherited+ method is called: - def inherited(base) - unless base.abstract_railtie? - base.send(:include, Railtie::Configurable) - subclasses << base - end +def inherited(base) + unless base.abstract_railtie? + base.send(:include, Railtie::Configurable) + subclasses << base end +end This first checks if the Railtie that's inheriting it is a component of Rails itself: @@ -763,15 +764,15 @@ end The +config+ method used at the top of +I18n::Railtie+ is defined on +Rails::Railtie+ and is defined like this: - def config - @config ||= Railtie::Configuration.new - end +def config + @config ||= Railtie::Configuration.new +end At this point, that +Railtie::Configuration+ constant is automatically loaded which causes the +rails/railties/configuration+ file to be loaded. The line for this is this particular line in +railties/lib/rails/railtie.rb+: - autoload :Configuration, "rails/railtie/configuration" +autoload :Configuration, "rails/railtie/configuration" h4. +railties/lib/rails/railtie/configuration.rb+ @@ -781,15 +782,15 @@ This file begins with a require out to +rails/configuration+ which has already b This file defines the +Rails::Railtie::Configuration+ class which is responsible for providing a way to easily configure railties and it's the +initialize+ method here which is called by the +config+ method back in the +i18n_railtie.rb+ file. The methods on this object don't exist, and so are rescued by the +method_missing+ defined further down in +configuration.rb+: - def method_missing(name, *args, &blk) - if name.to_s =~ /=$/ - @@options[$`.to_sym] = args.first - elsif @@options.key?(name) - @@options[name] - else - super - end +def method_missing(name, *args, &blk) + if name.to_s =~ /=$/ + @@options[$`.to_sym] = args.first + elsif @@options.key?(name) + @@options[name] + else + super end +end So therefore when an option is referred to it simply stores the value as the key if it's used in a setter context, or retrieves it if used in a getter context. Nothing fancy going on there. @@ -799,21 +800,21 @@ h4. Back to +activesupport/lib/active_support/i18n_railtie.rb+ After the configuration method the +reloader+ method is defined, and then the first of of Railties' initializers is defined: +i18n.callbacks+. - initializer "i18n.callbacks" do - ActionDispatch::Reloader.to_prepare do - I18n::Railtie.reloader.execute_if_updated - end +initializer "i18n.callbacks" do + ActionDispatch::Reloader.to_prepare do + I18n::Railtie.reloader.execute_if_updated end +end The +initializer+ method (from the +Rails::Initializable+ module) here doesn't run the block, but rather stores it to be run later on: - def initializer(name, opts = {}, &blk) - raise ArgumentError, "A block must be passed when defining an initializer" unless blk - opts[:after] ||= initializers.last.name unless initializers.empty? || initializers.find { |i| i.name == opts[:before] } - initializers << Initializer.new(name, nil, opts, &blk) - end +def initializer(name, opts = {}, &blk) + raise ArgumentError, "A block must be passed when defining an initializer" unless blk + opts[:after] ||= initializers.last.name unless initializers.empty? || initializers.find { |i| i.name == opts[:before] } + initializers << Initializer.new(name, nil, opts, &blk) +end An initializer can be configured to run before or after another initializer, which we'll see a couple of times throughout this initialization process. Anything that inherits from +Rails::Railtie+ may also make use of the +initializer+ method, something which is covered in the "Configuration guide":[http://ryanbigg.com/guides/configuring.html#rails-railtie-initializer]. @@ -821,25 +822,25 @@ An initializer can be configured to run before or after another initializer, whi The +Initializer+ class here is defined within the +Rails::Initializable+ module and its +initialize+ method is defined to just set up a couple of variables: - def initialize(name, context, options, &block) - @name, @context, @options, @block = name, context, options, block - end +def initialize(name, context, options, &block) + @name, @context, @options, @block = name, context, options, block +end Once this +initialize+ method is finished, the object is added to the object the +initializers+ method returns: - def initializers - @initializers ||= self.class.initializers_for(self) - end +def initializers + @initializers ||= self.class.initializers_for(self) +end If +@initializers+ isn't set (which it won't be at this point), the +intializers_for+ method will be called for this class. - def initializers_for(binding) - Collection.new(initializers_chain.map { |i| i.bind(binding) }) - end +def initializers_for(binding) + Collection.new(initializers_chain.map { |i| i.bind(binding) }) +end The +Collection+ class in +railties/lib/rails/initializable.rb+ inherits from +Array+ and includes the +TSort+ module which is used to sort out the order of the initializers based on the order they are placed in. @@ -847,22 +848,22 @@ The +Collection+ class in +railties/lib/rails/initializable.rb+ inherits from +A The +initializers_chain+ method referenced in the +initializers_for+ method is defined like this: - def initializers_chain - initializers = Collection.new - ancestors.reverse_each do | klass | - next unless klass.respond_to?(:initializers) - initializers = initializers + klass.initializers - end - initializers +def initializers_chain + initializers = Collection.new + ancestors.reverse_each do | klass | + next unless klass.respond_to?(:initializers) + initializers = initializers + klass.initializers end + initializers +end This method collects the initializers from the ancestors of this class and adds them to a new +Collection+ object using the + method which is defined like this for the Collection class: - def +(other) - Collection.new(to_a + other.to_a) - end +def +(other) + Collection.new(to_a + other.to_a) +end So this + method is overridden to return a new collection comprising of the existing collection as an array and then using the Array#+ method combines these two collections, returning a "super" +Collection+ object. In this case, the only initializer that's going to be in this new +Collection+ object is the +i18n.callbacks+ initializer. @@ -870,34 +871,34 @@ So this + method is overridden to return a new collection comprising of The next method to be called after this +initializer+ method is the +after_initialize+ method on the +config+ object, which is defined like this: - def after_initialize(&block) - ActiveSupport.on_load(:after_initialize, :yield => true, &block) - end +def after_initialize(&block) + ActiveSupport.on_load(:after_initialize, :yield => true, &block) +end The +on_load+ method here is provided by the +active_support/lazy_load_hooks+ file which was required earlier and is defined like this: - def self.on_load(name, options = {}, &block) - if base = @loaded[name] - execute_hook(base, options, block) - else - @load_hooks[name] << [block, options] - end +def self.on_load(name, options = {}, &block) + if base = @loaded[name] + execute_hook(base, options, block) + else + @load_hooks[name] << [block, options] end +end The +@loaded+ variable here is a hash containing elements representing the different components of Rails that have been loaded at this stage. Currently, this hash is empty. So the +else+ is executed here, using the +@load_hooks+ variable defined in +active_support/lazy_load_hooks+: - @load_hooks = Hash.new {|h,k| h[k] = [] } +@load_hooks = Hash.new {|h,k| h[k] = [] } This defines a new hash which has keys that default to empty arrays. This saves Rails from having to do something like this instead: - @load_hooks[name] = [] - @load_hooks[name] << [block, options] +@load_hooks[name] = [] +@load_hooks[name] << [block, options] The value added to this array here consists of the block and options passed to +after_initialize+. @@ -929,11 +930,11 @@ h4. +activesupport/lib/action_dispatch.rb+ This file attempts to locate the +active_support+ and +active_model+ libraries by looking a couple of directories back from the current file and then adds the +active_support+ and +active_model+ +lib+ directories to the load path, but only if they aren't already, which they are. - activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__) - $:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path) +activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__) +$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path) - activemodel_path = File.expand_path('../../../activemodel/lib', __FILE__) - $:.unshift(activemodel_path) if File.directory?(activemodel_path) && !$:.include?(activemodel_path) +activemodel_path = File.expand_path('../../../activemodel/lib', __FILE__) +$:.unshift(activemodel_path) if File.directory?(activemodel_path) && !$:.include?(activemodel_path) In effect, these lines only define the +activesupport_path+ and +activemodel_path+ variables and nothing more. @@ -941,23 +942,23 @@ In effect, these lines only define the +activesupport_path+ and +activemodel_pat The next two requires in this file are already done, so they are not run: - require 'active_support' - require 'active_support/dependencies/autoload' +require 'active_support' +require 'active_support/dependencies/autoload' The following require is to +action_pack+ (+activesupport/lib/action_pack.rb+) which has a 22-line copyright notice at the top of it and ends in a simple require to +action_pack/version+. This file, like other +version.rb+ files before it, defines the +ActionPack::VERSION+ constant: - module ActionPack - module VERSION #:nodoc: - MAJOR = 3 - MINOR = 1 - TINY = 0 - PRE = "beta" - - STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') - end +module ActionPack + module VERSION #:nodoc: + MAJOR = 3 + MINOR = 1 + TINY = 0 + PRE = "beta" + + STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end +end Once +action_pack+ is finished, then +active_model+ is required. @@ -967,16 +968,16 @@ h4. +activemodel/lib/active_model.rb+ This file makes a require to +active_model/version+ which defines the version for Active Model: - module ActiveModel - module VERSION #:nodoc: - MAJOR = 3 - MINOR = 1 - TINY = 0 - PRE = "beta" - - STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') - end +module ActiveModel + module VERSION #:nodoc: + MAJOR = 3 + MINOR = 1 + TINY = 0 + PRE = "beta" + + STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end +end Once the +version.rb+ file is loaded, the +ActiveModel+ module has its autoloaded constants defined as well as a sub-module called +ActiveModel::Serializers+ which has autoloads of its own. When the +ActiveModel+ module is closed the +active_support/i18n+ file is required. @@ -986,15 +987,15 @@ h4. +activesupport/lib/active_support/i18n.rb+ This is where the +i18n+ gem is required and first configured: - begin - require 'i18n' - require 'active_support/lazy_load_hooks' - rescue LoadError => e - $stderr.puts "You don't have i18n installed in your application. Please add it to your Gemfile and run bundle install" - raise e - end +begin + require 'i18n' + require 'active_support/lazy_load_hooks' +rescue LoadError => e + $stderr.puts "You don't have i18n installed in your application. Please add it to your Gemfile and run bundle install" + raise e +end - I18n.load_path << "#{File.dirname(__FILE__)}/locale/en.yml" +I18n.load_path << "#{File.dirname(__FILE__)}/locale/en.yml" In effect, the +I18n+ module first defined by +i18n_railtie+ is extended by the +i18n+ gem, rather than the other way around. This has no ill effect. They both work on the same way. @@ -1012,9 +1013,9 @@ h4. Back to +activesupport/lib/action_dispatch.rb+ The remainder of this file requires the +rack+ file from the Rack gem which defines the +Rack+ module. After +rack+, there's autoloads defined for the +Rack+, +ActionDispatch+, +ActionDispatch::Http+, +ActionDispatch::Session+. A new method called +autoload_under+ is used here, and this simply prefixes the files where the modules are autoloaded from with the path specified. For example here: - autoload_under 'testing' do - autoload :Assertions - ... +autoload_under 'testing' do + autoload :Assertions +... The +Assertions+ module is in the +action_dispatch/testing+ folder rather than simply +action_dispatch+. @@ -1046,25 +1047,25 @@ This file begins by detecting if the +lib+ directories of +active_support+ and + The first three requires have already been done by other files and so aren't loaded here, but the 4th require, the one to +arel+ will require the file provided by the Arel gem, which defines the +Arel+ module. - require 'active_support' - require 'active_support/i18n' - require 'active_model' - require 'arel' +require 'active_support' +require 'active_support/i18n' +require 'active_model' +require 'arel' The 5th require in this file is one to +active_record/version+ which defines the +ActiveRecord::VERSION+ constant: - module ActiveRecord - module VERSION #:nodoc: - MAJOR = 3 - MINOR = 1 - TINY = 0 - PRE = "beta" - - STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') - end +module ActiveRecord + module VERSION #:nodoc: + MAJOR = 3 + MINOR = 1 + TINY = 0 + PRE = "beta" + + STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end +end Once these requires are finished, the base for the +ActiveRecord+ module is defined along with its autoloads. @@ -1072,9 +1073,9 @@ Once these requires are finished, the base for the +ActiveRecord+ module is defi Near the end of the file, we see this line: - ActiveSupport.on_load(:active_record) do - Arel::Table.engine = self - end +ActiveSupport.on_load(:active_record) do + Arel::Table.engine = self +end This will set the engine for +Arel::Table+ to be +ActiveRecord::Base+. @@ -1082,7 +1083,7 @@ This will set the engine for +Arel::Table+ to be +ActiveRecord::Base+. The file then finishes with this line: - I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en.yml' +I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en.yml' This will add the translations from +activerecord/lib/active_record/locale/en.yml+ to the load path for +I18n+, with this file being parsed when all the translations are loaded. @@ -1092,8 +1093,8 @@ h4. Back to +activerecord/lib/active_record/railtie.rb+ The next two requires in this file aren't run because their files are already required, with +rails+ being required by +rails/all+ and +active_model/railtie+ being required from +action_dispatch+. - require "rails" - require "active_model/railtie" +require "rails" +require "active_model/railtie" The next +require+ in this file is to +action_controller/railtie+. @@ -1103,9 +1104,9 @@ h4. +actionpack/lib/action_controller/railtie.rb+ This file begins with a couple more requires to files that have already been loaded: - require "rails" - require "action_controller" - require "action_dispatch/railtie" +require "rails" +require "action_controller" +require "action_dispatch/railtie" However the require after these is to a file that hasn't yet been loaded, +action_view/railtie+, which begins by requiring +action_view+. -- cgit v1.2.3 From a2cf91a1a4382869aaff7d7b0fbbb60336a3c830 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 6 Jun 2011 02:10:31 +0530 Subject: minor edits in migrations guide --- railties/guides/source/migrations.textile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index d60b68ec7f..f17f686d47 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -55,6 +55,8 @@ class AddReceiveNewsletterToUsers < ActiveRecord::Migration end +NOTE: Some "caveats":#using-models-in-your-migrations apply to using models in your migrations. + This migration adds a +receive_newsletter+ column to the +users+ table. We want it to default to +false+ for new users, but existing users are considered to have already opted in, so we use the User model to set the flag to +true+ for existing users. @@ -73,11 +75,9 @@ class CreateProducts < ActiveRecord::Migration end -NOTE: Some "caveats":#using-models-in-your-migrations apply to using models in your migrations. - h4. Migrations are Classes -A migration is a subclass of ActiveRecord::Migration that implements two class methods: +up+ (perform the required transformations) and +down+ (revert them). +A migration is a subclass of ActiveRecord::Migration that implements two methods: +up+ (perform the required transformations) and +down+ (revert them). Active Record provides methods that perform common data definition tasks in a database independent way (you'll read about them in detail later): @@ -115,7 +115,7 @@ h4. Changing Migrations Occasionally you will make a mistake when writing a migration. If you have already run the migration then you cannot just edit the migration and run the migration again: Rails thinks it has already run the migration and so will do nothing when you run +rake db:migrate+. You must rollback the migration (for example with +rake db:rollback+), edit your migration and then run +rake db:migrate+ to run the corrected version. -In general editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or more generally which has not been propagated beyond your development machine) is relatively harmless. Just use some common sense. +In general editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or more generally which has not been propagated beyond your development machine) is relatively harmless. h3. Creating a Migration -- cgit v1.2.3 From a620e65053b1fc613590bee60b4297489f2d35bc Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Sun, 5 Jun 2011 14:49:50 -0700 Subject: Edited railties/guides/source/asset_pipeline.textile via GitHub --- railties/guides/source/asset_pipeline.textile | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 7ebc10b384..5d0dfee41c 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -20,18 +20,30 @@ The asset pipeline is easy to migrate to and use. There are a few things that yo h4. Asset Organization -Loads from /app/assets, /lib/assets, /vendor/assets, and your gem's assets +WIP + +Sprockets will automatically load manifest files by searching directories in app/assets and including the first file with a basename of index. (Confirm and add: does it load app/assets/index?) h4. Directives -require_tree, require, require_self +WIP + +Sprockets, the rails tie that powers the asset pipeline, provides three directives which are like Ruby's methods. They are: +require+, +require_tree+, and +require_self+. These directives must be called at the top of a file in a comment with an equal sign before it. (note: CSS directives need *= if in a continuous comment -- confirm please) + +The require directive loads a file with the supplied basename from the following paths: app/assets/*, lib/assets/*, vendor/assets/*, as well as any of your gem's asset files. + +Require tree does... + +Require self does... h4. Stacking Preprocessors -filename.css.scss not filename.scss.css, how and why +Sprockets allows you to stack preprocessors. The stack is ran off the file extensions in a last in, first out method (like popping an array). For example if we want to make a JavaScript asset with both CoffeeScript and ERB the file would be named: +name.js.coffee.erb+. If it were named +name.js.erb.coffee+ CoffeeScript would raise an error because it doesn't understand ERB tags. h4. Adding a Preproccessor +WIP + https://github.com/rtomayko/tilt for gems or config.register_processor('text/css', MyAwesomeProccessor) for local stuff h3. Packaging Assets with Your Gems -- cgit v1.2.3 From d3d5b048f9036da941b8164dc8aa85d857059e47 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sun, 5 Jun 2011 20:36:09 -0700 Subject: Change http://api.rubyonrails.com to http://api.rubyonrails.org --- railties/guides/source/active_record_basics.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_record_basics.textile b/railties/guides/source/active_record_basics.textile index b7926f3a3b..3e46e7df9f 100644 --- a/railties/guides/source/active_record_basics.textile +++ b/railties/guides/source/active_record_basics.textile @@ -64,8 +64,8 @@ There are also some optional column names that will create additional features t * *created_on* - Automatically gets set to the current date when the record is first created. * *updated_at* - Automatically gets set to the current date and time whenever the record is updated. * *updated_on* - Automatically gets set to the current date whenever the record is updated. -* *lock_version* - Adds "optimistic locking":http://api.rubyonrails.com/classes/ActiveRecord/Locking.html to a model. -* *type* - Specifies that the model uses "Single Table Inheritance":http://api.rubyonrails.com/classes/ActiveRecord/Base.html +* *lock_version* - Adds "optimistic locking":http://api.rubyonrails.org/classes/ActiveRecord/Locking.html to a model. +* *type* - Specifies that the model uses "Single Table Inheritance":http://api.rubyonrails.org/classes/ActiveRecord/Base.html * *(table_name)_count* - Used to cache the number of belonging objects on associations. For example, a +comments_count+ column in a +Post+ class that has many instances of +Comment+ will cache the number of existent comments for each post. NOTE: While these column names are optional they are in fact reserved by Active Record. Steer clear of reserved keywords unless you want the extra functionality. For example, "type" is a reserved keyword used to designate a table using Single Table Inheritance. If you are not using STI, try an analogous keyword like "context", that may still accurately describe the data you are modeling. -- cgit v1.2.3 From c0c0a64ce652a6471ed1f9c72b3f5bc94164c0e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20P=C4=99kala?= Date: Mon, 6 Jun 2011 11:51:18 +0200 Subject: Validations guide: order of :after_save callback was incorrect. The guide was contracting itself. First it stated that 'there is a list of callbacks in order of execution', on the list 'after_save' was placed before 'after_create', and then there was a warning that 'after_save' runs after them. I am not sure about 'around_' callbacks, but let's leave that for another patch. --- railties/guides/source/active_record_validations_callbacks.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 7140353a15..36094dcddc 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -912,20 +912,20 @@ h4. Creating an Object * +before_validation+ * +after_validation+ * +before_save+ -* +after_save+ * +before_create+ * +around_create+ * +after_create+ +* +after_save+ h4. Updating an Object * +before_validation+ * +after_validation+ * +before_save+ -* +after_save+ * +before_update+ * +around_update+ * +after_update+ +* +after_save+ h4. Destroying an Object -- cgit v1.2.3 From 660fb143fb42527d7686c95416698b84de5c33ab Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 7 Jun 2011 00:16:43 +0530 Subject: document assets related rake tasks --- railties/guides/source/command_line.textile | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 1796c2fb78..0498f802e7 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -561,6 +561,10 @@ rake tmp:sessions:clear # Clears all files in tmp/sessions rake tmp:sockets:clear # Clears all files in tmp/sockets +h5. +assets:+ Assets + +You can precompile the assets in app/assets using rake assets:precompile and remove compiled assets using rake assets:clean. + h5. +db:+ Database The most common tasks of the +db:+ Rake namespace are +migrate+ and +create+, and it will pay off to try out all of the migration rake tasks (+up+, +down+, +redo+, +reset+). +rake db:version+ is useful when troubleshooting, telling you the current version of the database. -- cgit v1.2.3 From c5786a951ea4b42f38f1862f2322b7b3f5085241 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 7 Jun 2011 01:00:07 +0530 Subject: rearrange sections of the commandline guide giving more importance to rake tasks --- railties/guides/source/command_line.textile | 123 ++++++++++++++-------------- 1 file changed, 60 insertions(+), 63 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 0498f802e7..5fe9ad101b 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -339,9 +339,29 @@ $ rails destroy model Oops notempty app -h4. +rake about+ +h3. Rake -Check it: Version numbers for Ruby, RubyGems, Rails, the Rails subcomponents, your application's folder, the current Rails environment name, your app's database adapter, and schema version! +about+ is useful when you need to ask for help, check if a security patch might affect you, or when you need some stats for an existing Rails installation. +Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility 'make', and uses a 'Rakefile' and +.rake+ files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other. + +You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing +rake --tasks+. Each task has a description, and should help you find the thing you need. + + +$ rake --tasks +(in /home/foobar/commandsapp) +rake db:abort_if_pending_migrations # Raises an error if there are pending migrations +rake db:charset # Retrieves the charset for the current environment's database +rake db:collation # Retrieves the collation for the current environment's database +rake db:create # Create the database defined in config/database.yml for the current Rails.env +... +... +rake tmp:pids:clear # Clears all files in tmp/pids +rake tmp:sessions:clear # Clears all files in tmp/sessions +rake tmp:sockets:clear # Clears all files in tmp/sockets + + +h4. +about+ + +rake about gives information about version numbers for Ruby, RubyGems, Rails, the Rails subcomponents, your application's folder, the current Rails environment name, your app's database adapter, and schema version. It is useful when you need to ask for help, check if a security patch might affect you, or when you need some stats for an existing Rails installation. $ rake about @@ -360,6 +380,44 @@ Application root /home/foobar/commandsapp Environment development +h4. +assets+ + +You can precompile the assets in app/assets using rake assets:precompile and remove compiled assets using rake assets:clean. + +h4. +db+ + +The most common tasks of the +db:+ Rake namespace are +migrate+ and +create+, and it will pay off to try out all of the migration rake tasks (+up+, +down+, +redo+, +reset+). +rake db:version+ is useful when troubleshooting, telling you the current version of the database. + +h4. +doc+ + +If you want to strip out or rebuild any of the Rails documentation (including this guide!), the +doc:+ namespace has the tools. Stripping documentation is mainly useful for slimming your codebase, like if you're writing a Rails application for an embedded platform. + +h4. +notes+ + +These tasks will search through your code for commented lines beginning with "FIXME", "OPTIMIZE", "TODO", or any custom annotation (like XXX) and show you them. + +h4. +routes+ + ++rake routes+ will list all of your defined routes, which is useful for tracking down routing problems in your app, or giving you a good overview of the URLs in an app you're trying to get familiar with. + +h4. +test+ + +INFO: A good description of unit testing in Rails is given in "A Guide to Testing Rails Applications":testing.html + +Rails comes with a test suite called Test::Unit. It is through the use of tests that Rails itself is so stable, and the slew of people working on Rails can prove that everything works as it should. + +The +test:+ namespace helps in running the different tests you will (hopefully!) write. + +h4. +tmp+ + +The Rails.root/tmp directory is, like the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for files), process id files, and cached actions. The +tmp:+ namespace tasks will help you clear them if you need to if they've become overgrown, or create them in case of deletions gone awry. + +h4. Miscellaneous + +* +rake stats+ is great for looking at statistics on your code, displaying things like KLOCs (thousands of lines of code) and your code to test ratio. +* +rake secret+ will give you a pseudo-random key to use for your session secret. +* rake time:zones:all lists all the timezones Rails knows about. + h3. The Rails Advanced Command Line More advanced use of the command line is focused around finding useful (even surprising at times) options in the utilities, and fitting those to your needs and specific work flow. Listed here are some tricks up Rails' sleeve. @@ -540,64 +598,3 @@ I got assigned some args: Tada! - -h4. Rake is Ruby Make - -Rake is a standalone Ruby utility that replaces the Unix utility 'make', and uses a 'Rakefile' and +.rake+ files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other. - -You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing +rake --tasks+. Each task has a description, and should help you find the thing you need. - - -$ rake --tasks -(in /home/foobar/commandsapp) -rake db:abort_if_pending_migrations # Raises an error if there are pending migrations -rake db:charset # Retrieves the charset for the current environment's database -rake db:collation # Retrieves the collation for the current environment's database -rake db:create # Create the database defined in config/database.yml for the current Rails.env -... -... -rake tmp:pids:clear # Clears all files in tmp/pids -rake tmp:sessions:clear # Clears all files in tmp/sessions -rake tmp:sockets:clear # Clears all files in tmp/sockets - - -h5. +assets:+ Assets - -You can precompile the assets in app/assets using rake assets:precompile and remove compiled assets using rake assets:clean. - -h5. +db:+ Database - -The most common tasks of the +db:+ Rake namespace are +migrate+ and +create+, and it will pay off to try out all of the migration rake tasks (+up+, +down+, +redo+, +reset+). +rake db:version+ is useful when troubleshooting, telling you the current version of the database. - -h5. +doc:+ Documentation - -If you want to strip out or rebuild any of the Rails documentation (including this guide!), the +doc:+ namespace has the tools. Stripping documentation is mainly useful for slimming your codebase, like if you're writing a Rails application for an embedded platform. - -h5. +notes:+ Code note enumeration - -These tasks will search through your code for commented lines beginning with "FIXME", "OPTIMIZE", "TODO", or any custom annotation (like XXX) and show you them. - -h5. +test:+ Rails tests - -INFO: A good description of unit testing in Rails is given in "A Guide to Testing Rails Applications":testing.html - -Rails comes with a test suite called Test::Unit. It is through the use of tests that Rails itself is so stable, and the slew of people working on Rails can prove that everything works as it should. - -The +test:+ namespace helps in running the different tests you will (hopefully!) write. - -h5. +time:+ Timezones - -You can list all the timezones Rails knows about with +rake time:zones:all+, which is useful just in day-to-day life. - -h5. +tmp:+ Temporary files - -The tmp directory is, like the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for files), process id files, and cached actions. The +tmp:+ namespace tasks will help you clear them if you need to if they've become overgrown, or create them in case of deletions gone awry. - -h5. Miscellaneous Tasks - - +rake stats+ is great for looking at statistics on your code, displaying things like KLOCs (thousands of lines of code) and your code to test ratio. - - +rake secret+ will give you a pseudo-random key to use for your session secret. - - +rake routes+ will list all of your defined routes, which is useful for tracking down routing problems in your app, or giving you a good overview of the URLs in an app you're trying to get familiar with. - -- cgit v1.2.3