From 7fd8f71ce0b8e0bf30b416d5b6425bb5b636ed76 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 8 Jun 2011 04:48:03 +0530 Subject: fix incorrect validation examples --- .../guides/source/active_record_validations_callbacks.textile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 36094dcddc..50ff1c9ff7 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -182,7 +182,7 @@ It can receive an +:accept+ option, which determines the value that will be cons class Person < ActiveRecord::Base - validates :terms_of_service, :acceptance => true, :accept => 'yes' + validates :terms_of_service, :acceptance => { :accept => 'yes' } end @@ -338,7 +338,7 @@ WARNING. Note that the regular expression above allows a trailing newline charac class Player < ActiveRecord::Base validates :points, :numericality => true - validates :games_played, :numericality => true, :only_integer => true + validates :games_played, :numericality => { :only_integer => true } end @@ -393,8 +393,8 @@ There is a +:scope+ option that you can use to specify other attributes that are class Holiday < ActiveRecord::Base - validates :name, :uniqueness => true, :scope => :year, - :message => "should happen once per year" + validates :name, :uniqueness => { :scope => :year, + :message => "should happen once per year" } end @@ -402,7 +402,7 @@ There is also a +:case_sensitive+ option that you can use to define whether the class Person < ActiveRecord::Base - validates :name, :uniqueness => true, :case_sensitive => false + validates :name, :uniqueness => { :case_sensitive => false } end -- cgit v1.2.3 From e89a25370529cb5dcf507f71675e6dd5aa6ec188 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 8 Jun 2011 04:53:09 +0530 Subject: minor fixes from 5acf76d --- railties/guides/source/configuring.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index da951a0833..c53fa3c3f2 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -366,12 +366,12 @@ There are a number of settings available on +config.action_mailer+: * +config.action_mailer.observers+ registers observers which will be notified when mail is delivered. -config.active_record.observers = ["MailObserver"] +config.action_mailer.observers = ["MailObserver"] * +config.action_mailer.interceptors+ registers interceptors which will be called before mail is sent. -config.active_record.interceptors = ["MailInterceptor"] +config.action_mailer.interceptors = ["MailInterceptor"] h4. Configuring Active Resource -- cgit v1.2.3 From 18d84e50a209bfb54bdd4621bfa3a9ec62afeac8 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 8 Jun 2011 05:06:58 +0530 Subject: use git: rather than https: in git remote urls; else, github asks for passwords everytime we push --- railties/guides/source/contributing_to_ruby_on_rails.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index 2ce8ddc702..564fe56603 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -350,7 +350,7 @@ Navigate to the Rails "GitHub repository":https://github.com/rails/rails and pre Add the new remote to your local repository on your local machine: -$ git remote add mine https://@github.com//rails.git +$ git remote add mine git@github.com:/rails.git Push to your remote: -- cgit v1.2.3 From 5c53754f330219bd32d5793e71f516fba62f32bf Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 8 Jun 2011 06:47:22 +0530 Subject: fix generators guide url --- railties/guides/source/command_line.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 5fe9ad101b..2fe5be43b1 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -5,7 +5,7 @@ Rails comes with every command line tool you'll need to * Create a Rails application * Generate models, controllers, database migrations, and unit tests * Start a development server -* Mess with objects through an interactive shell +* Experiment with objects through an interactive shell * Profile and benchmark your new creation endprologue. @@ -507,7 +507,7 @@ $ rails server mongrel h4. The Rails Generation: Generators -INFO: For a good rundown on generators, see "Understanding Generators":http://wiki.rubyonrails.org/rails/pages/UnderstandingGenerators. A lot of its material is presented here. +INFO: For a good rundown on generators, see "Understanding Generators":generators.html. A lot of its material is presented here. Generators are code that generates code. Let's experiment by building one. Our generator will generate a text file. -- cgit v1.2.3 From def4a538cc56760365d1fc0840dc33c09def0db8 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 8 Jun 2011 15:01:19 +0530 Subject: remove generators section from command line guide in favor of the separate generator guide --- railties/guides/source/command_line.textile | 94 ----------------------------- 1 file changed, 94 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 2fe5be43b1..026c15feba 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -504,97 +504,3 @@ $ rails server mongrel => Rails 3.1.0 application starting on http://0.0.0.0:3000 ... - -h4. The Rails Generation: Generators - -INFO: For a good rundown on generators, see "Understanding Generators":generators.html. A lot of its material is presented here. - -Generators are code that generates code. Let's experiment by building one. Our generator will generate a text file. - -The Rails generator by default looks in these places for available generators, where Rails.root is the root of your Rails application, like /home/foobar/commandsapp: - -* Rails.root/lib/generators -* Rails.root/vendor/generators -* Inside any plugin with a directory like "generators" or "rails_generators" -* ~/.rails/generators -* Inside any Gem you have installed with a name ending in "_generator" -* Inside any Gem installed with a "rails_generators" path, and a file ending in "_generator.rb" -* Finally, the builtin Rails generators (controller, model, mailer, etc.) - -Let's try the fourth option (in our home directory), which will be easy to clean up later: - - -$ mkdir -p ~/.rails/generators/tutorial_test/templates -$ touch ~/.rails/generators/tutorial_test/templates/tutorial.erb -$ touch ~/.rails/generators/tutorial_test/tutorial_test_generator.rb - - -We'll fill +tutorial_test_generator.rb+ out with: - - -class TutorialTestGenerator < Rails::Generator::Base - def initialize(*runtime_args) - super(*runtime_args) - @tut_args = runtime_args - end - - def manifest - record do |m| - m.directory "public" - m.template "tutorial.erb", File.join("public", "tutorial.txt"), - :assigns => { :args => @tut_args } - end - end -end - - -We take whatever args are supplied, save them to an instance variable, and literally copying from the Rails source, implement a +manifest+ method, which calls +record+ with a block, and we: - -* Check there's a *public* directory. You bet there is. -* Run the ERB template called "tutorial.erb". -* Save it into "Rails.root/public/tutorial.txt". -* Pass in the arguments we saved through the +:assigns+ parameter. - -Next we'll build the template: - - -$ cat ~/.rails/generators/tutorial_test/templates/tutorial.erb -I'm a template! - -I got assigned some args: -<%= require 'pp'; PP.pp(args, "") %> - - -Then we'll make sure it got included in the list of available generators: - - -$ rails generate -... -... -Installed Generators - User: tutorial_test - - -SWEET! Now let's generate some text, yeah! - - -$ rails generate tutorial_test arg1 arg2 arg3 - exists public - create public/tutorial.txt - - -And the result: - - -$ cat public/tutorial.txt -I'm a template! - -I got assigned some args: -[["arg1", "arg2", "arg3"], - {:collision=>:ask, - :quiet=>false, - :generator=>"tutorial_test", - :command=>:create}] - - -Tada! -- cgit v1.2.3 From 3dacc8527882689d3ddc2b787de3c71e927400cc Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 8 Jun 2011 19:42:18 +0530 Subject: minor corrections in configuring guide --- railties/guides/source/configuring.textile | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index c53fa3c3f2..a4cc62c117 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -220,21 +220,21 @@ h4. Configuring Active Record * +config.active_record.table_name_suffix+ lets you set a global string to be appended to table names. If you set this to +_northwest+, then the Customer class will look for +customers_northwest+ as its table. The default is an empty string. -* +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 Customer class will use the +customer+ table. +* +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 Customer 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 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.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 Active Record will use optimistic locking. By default this is +true+. +* +config.active_record.lock_optimistically+ controls whether Active Record will use optimistic locking and is true by default. * +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 Active Record 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 and is true by default. The schema dumper adds one additional configuration option: @@ -260,7 +260,7 @@ h4. Configuring Action Controller * +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. -* +config.action_controller.allow_forgery_protection+ enables or disables CSRF protection. By default this is +false+ in test mode and +true+ in all other modes. +* +config.action_controller.allow_forgery_protection+ enables or disables CSRF protection. By default this is false in test mode and true in all other modes. * +config.action_controller.relative_url_root+ can be used to tell Rails that you are deploying to a subdirectory. The default is +ENV['RAILS_RELATIVE_URL_ROOT']+. @@ -350,11 +350,11 @@ There are a number of settings available on +config.action_mailer+: ** +:location+ - The location of the sendmail executable. Defaults to +/usr/sbin/sendmail+. ** +:arguments+ - The command line arguments. Defaults to +-i -t+. -* +config.action_mailer.raise_delivery_errors+ specifies whether to raise an error if email delivery cannot be completed. It defaults to +true+. +* +config.action_mailer.raise_delivery_errors+ specifies whether to raise an error if email delivery cannot be completed. It defaults to true. * +config.action_mailer.delivery_method+ defines the delivery method. The allowed values are +:smtp+ (default), +:sendmail+, and +:test+. -* +config.action_mailer.perform_deliveries+ specifies whether mail will actually be delivered. By default this is +true+; it can be convenient to set it to +false+ for testing. +* +config.action_mailer.perform_deliveries+ specifies whether mail will actually be delivered and is true by default. It can be convenient to set it to false for testing. * +config.action_mailer.default+ configures Action Mailer defaults. These default to: @@ -478,13 +478,13 @@ Serves as a placeholder so that +:load_environment_config+ can be defined to run *+set_clear_dependencies_hook+* Provides a hook for +active_record.set_dispatch_hooks+ to use, which will run before this initializer. This initializer -- which runs only if +cache_classes+ is set to +false+ -- uses +ActionDispatch::Callbacks.after+ to remove the constants which have been referenced during the request from the object space so that they will be reloaded during the following request. -*+initialize_dependency_mechanism+* If +config.cache_classes+ is set to +true+, configures +ActiveSupport::Dependencies.mechanism+ to +require+ dependencies rather than +load+ them. +*+initialize_dependency_mechanism+* If +config.cache_classes+ is true, configures +ActiveSupport::Dependencies.mechanism+ to +require+ dependencies rather than +load+ them. *+bootstrap_hook+* Runs all configured +before_initialize+ blocks. *+i18n.callbacks+* In the development environment, sets up a +to_prepare+ callback which will call +I18n.reload!+ if any of the locales have changed since the last request. In production mode this callback will only run on the first request. -*+active_support.initialize_whiny_nils+* Requires +active_support/whiny_nil+ if +config.whiny_nils+ is set to +true+. This file will output errors such as: +*+active_support.initialize_whiny_nils+* Requires +active_support/whiny_nil+ if +config.whiny_nils+ is true. This file will output errors such as: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id @@ -568,13 +568,13 @@ The error occurred while evaluating nil.each *+build_middleware_stack+* Builds the middleware stack for the application, returning an object which has a +call+ method which takes a Rack environment object for the request. -*+eager_load!+* If +config.cache_classes+ is +true+, runs the +config.before_eager_load+ hooks and then calls +eager_load!+ which will load all the Ruby files from +config.eager_load_paths+. +*+eager_load!+* If +config.cache_classes+ is true, runs the +config.before_eager_load+ hooks and then calls +eager_load!+ which will load all the Ruby files from +config.eager_load_paths+. *+finisher_hook+* Provides a hook for after the initialization of process of the application is complete, as well as running all the +config.after_initialize+ blocks for the application, railties and engines. *+set_routes_reloader+* Configures Action Dispatch to reload the routes file using +ActionDispatch::Callbacks.to_prepare+. -*+disable_dependency_loading+* Disables the automatic dependency loading if the +config.cache_classes+ is set to +true+ and +config.dependency_loading+ is set to +false+. +*+disable_dependency_loading+* Disables the automatic dependency loading if the +config.cache_classes+ is set to true and +config.dependency_loading+ is set to false. h3. Changelog -- cgit v1.2.3 From fe2482e50b1eebc12025d4c39c94e33dca8e95a8 Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Wed, 8 Jun 2011 18:50:55 -0400 Subject: require_tree is pretty simple --- railties/guides/source/asset_pipeline.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 5d0dfee41c..a8373087d9 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -32,9 +32,9 @@ Sprockets, the rails tie that powers the asset pipeline, provides three directiv 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... +Using the +require_tree+ directive you can easily include an entire folder of assets. The paths must be relative, so begin them with either a forward slash or dots. For example to include a folder in the same directory I would do +require_tree ./folder_name+ -Require self does... +Require self does... something h4. Stacking Preprocessors -- cgit v1.2.3 From 4f9e2425216653649d4b4b6d73eeca3c1f9f312d Mon Sep 17 00:00:00 2001 From: Ben Orenstein Date: Wed, 8 Jun 2011 23:20:13 -0400 Subject: Describe the user name 'variable' in a way that doesn't confuse the textile parser. --- railties/guides/source/contributing_to_ruby_on_rails.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index 564fe56603..e6ec061c9a 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -361,7 +361,7 @@ $ git push mine my_new_branch h4. Issue a Pull Request -Navigate to the Rails repository you just pushed to (e.g. https://github.com//rails) and press "Pull Request" in the upper right hand corner. +Navigate to the Rails repository you just pushed to (e.g. https://github.com/your-user-name/rails) and press "Pull Request" in the upper right hand corner. Write your branch name in branch field (is filled with master by default) and press "Update Commit Range" -- cgit v1.2.3 From 45a5201b8697e3af13450e2672faf2daae5e5756 Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Thu, 9 Jun 2011 03:57:55 -0400 Subject: Match tone already established --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index a8373087d9..c12bc3d1dc 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -32,7 +32,7 @@ Sprockets, the rails tie that powers the asset pipeline, provides three directiv 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. -Using the +require_tree+ directive you can easily include an entire folder of assets. The paths must be relative, so begin them with either a forward slash or dots. For example to include a folder in the same directory I would do +require_tree ./folder_name+ +Using the +require_tree+ directive you can easily include an entire folder of assets. The paths must be relative, so begin them with either a forward slash or dots. For example to include a folder in the same directory you would do +require_tree ./folder_name+ Require self does... something -- cgit v1.2.3 From 1395b30803527bccd1f5c248092b54424176eca8 Mon Sep 17 00:00:00 2001 From: John Hinnegan Date: Thu, 9 Jun 2011 10:22:44 -0700 Subject: update palmist link on performance_testing --- railties/guides/source/performance_testing.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile index 83db7eee59..fe0915bfea 100644 --- a/railties/guides/source/performance_testing.textile +++ b/railties/guides/source/performance_testing.textile @@ -573,7 +573,7 @@ h3. Useful Links h4. Rails Plugins and Gems * "Rails Analyzer":http://rails-analyzer.rubyforge.org -* "Palmist":http://www.flyingmachinestudios.com/projects/ +* "Palmist":http://www.flyingmachinestudios.com/programming/announcing-palmist * "Rails Footnotes":https://github.com/josevalim/rails-footnotes/tree/master * "Query Reviewer":https://github.com/dsboulder/query_reviewer/tree/master -- cgit v1.2.3 From fa3fc520698092a002562107731b0d3b97e203d4 Mon Sep 17 00:00:00 2001 From: David Lee Date: Mon, 9 May 2011 16:16:55 -0700 Subject: Make utf8 enforcer param customizeable --- railties/guides/source/configuring.textile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index a4cc62c117..923de8b7c0 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -330,7 +330,9 @@ And can reference in the view with the following code: <%= stylesheet_link_tag :special %> -* +ActionView::Helpers::AssetTagHelper::AssetPaths.cache_asset_ids+ With the cache enabled, the asset tag helper methods will make fewer expensive file system calls (the default implementation checks the file system timestamp). However this prevents you from modifying any asset files while the server is running. +* +config.action_view.utf8_enforcer_param+ tells Rails what the +name+ attribute should be for the hidden tag that's used for enforcing UTF8 encoding in form submissions. The default is +'utf8'+. + +* +config.action_view.cache_asset_ids+ With the cache enabled, the asset tag helper methods will make fewer expensive file system calls (the default implementation checks the file system timestamp). However this prevents you from modifying any asset files while the server is running. h4. Configuring Action Mailer -- cgit v1.2.3 From 9b305983e3518093f3b393a254f296ca2be29968 Mon Sep 17 00:00:00 2001 From: David Lee Date: Fri, 20 May 2011 18:40:59 -0700 Subject: Remove utf8_enforcer_param config option --- railties/guides/source/configuring.textile | 2 -- 1 file changed, 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index 923de8b7c0..80de36070d 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -330,8 +330,6 @@ And can reference in the view with the following code: <%= stylesheet_link_tag :special %> -* +config.action_view.utf8_enforcer_param+ tells Rails what the +name+ attribute should be for the hidden tag that's used for enforcing UTF8 encoding in form submissions. The default is +'utf8'+. - * +config.action_view.cache_asset_ids+ With the cache enabled, the asset tag helper methods will make fewer expensive file system calls (the default implementation checks the file system timestamp). However this prevents you from modifying any asset files while the server is running. h4. Configuring Action Mailer -- cgit v1.2.3 From 94c52e8bd7ce39ed36c75b6af5ac636f58a63263 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 10 Jun 2011 17:06:21 +0530 Subject: minor fixes in action view guide --- railties/guides/source/action_view_overview.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile index a3454579ad..7703d6c720 100644 --- a/railties/guides/source/action_view_overview.textile +++ b/railties/guides/source/action_view_overview.textile @@ -165,7 +165,7 @@ will produce emphasized emph & bold A link - + Any method with a block will be treated as an XML markup tag with nested markup in the block. For example, the following: @@ -211,7 +211,7 @@ xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do end -h5. Template caching +h5. Template Caching By default, Rails will compile each template to a method in order to render it. When you alter a template, Rails will check the file's modification time and recompile it in development mode. @@ -235,7 +235,7 @@ This will render a file named +_menu.html.erb+ at that point within the view is That code will pull in the partial from +app/views/shared/_menu.html.erb+. -h5. Using Partials to Simplify Views +h5. Using Partials to simplify Views One way to use partials is to treat them as the equivalent of subroutines: as a way to move details out of a view so that you can grasp what's going on more easily. For example, you might have a view that looked like this: -- cgit v1.2.3 From 83289bedddd488e3b3bdd7ff58cd9dd2334d9623 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 10 Jun 2011 17:17:51 +0530 Subject: fixed incorrect command usage. (This section needs to be updated in any case). --- railties/guides/source/performance_testing.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile index fe0915bfea..d3b0f84a86 100644 --- a/railties/guides/source/performance_testing.textile +++ b/railties/guides/source/performance_testing.textile @@ -481,7 +481,7 @@ h4. +profiler+ Usage: -Usage: rails benchmarker 'Ruby.code' 'Ruby.more_code' ... [OPTS] +Usage: rails profiler 'Ruby.code' 'Ruby.more_code' ... [OPTS] -r, --runs N Number of runs. Default: 1 -o, --output PATH Directory to use when writing the results. -- cgit v1.2.3 From 3c06d25cf948bd7325454b1d4a843b5178221494 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 10 Jun 2011 17:18:57 +0530 Subject: favor includes over old AR way --- railties/guides/source/performance_testing.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile index d3b0f84a86..a4187a3135 100644 --- a/railties/guides/source/performance_testing.textile +++ b/railties/guides/source/performance_testing.textile @@ -66,7 +66,7 @@ resources :posts # home_controller.rb class HomeController < ApplicationController def dashboard - @users = User.last_ten(:include => :avatars) + @users = User.last_ten.includes(:avatars) @posts = Post.all_today end end -- cgit v1.2.3 From 53a9849551f64f0c60fe10a2037268eea9b46341 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 10 Jun 2011 17:27:46 +0530 Subject: add missing end in example --- railties/guides/source/caching_with_rails.textile | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile index f058dce42b..252003edd0 100644 --- a/railties/guides/source/caching_with_rails.textile +++ b/railties/guides/source/caching_with_rails.textile @@ -382,6 +382,7 @@ class ProductsController < ApplicationController # anything. The default render checks for this using the parameters # used in the previous call to stale? and will automatically send a # :not_modified. So that's it, you're done. + end end -- cgit v1.2.3 From db027aa47e94d125be029ca72e21b44e6a937ee1 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 11 Jun 2011 21:31:45 +0530 Subject: minor changes in templates guide --- railties/guides/source/rails_application_templates.textile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/rails_application_templates.textile b/railties/guides/source/rails_application_templates.textile index 388d8eea3e..3db47a70e8 100644 --- a/railties/guides/source/rails_application_templates.textile +++ b/railties/guides/source/rails_application_templates.textile @@ -1,6 +1,6 @@ h2. Rails Application Templates -Application templates are simple ruby files containing DSL for adding plugins/gems/initializers etc. to your freshly created Rails project or an existing Rails project. +Application templates are simple Ruby files containing DSL for adding plugins/gems/initializers etc. to your freshly created Rails project or an existing Rails project. By referring to this guide, you will be able to: @@ -58,14 +58,12 @@ gem "bj" gem "nokogiri" -Please note that this will NOT install the gems for you. So you may want to run the +rake gems:install+ task too: +Please note that this will NOT install the gems for you and you will have to run +bundle install+ to do that. -rake "gems:install" +bundle install -And let Rails take care of installing the required gems if they’re not already installed. - h4. add_source(source, options = {}) Adds the given source to the generated application's +Gemfile+. @@ -229,7 +227,7 @@ rake("rails:freeze:gems") if yes?("Freeze rails gems ?") no?(question) acts just the opposite. -h4. git(:must => "-a love") +h4. git(:command) Rails templates let you run any git command: -- cgit v1.2.3 From 940552ef42e1761fa3a6502d388f533a952ffe54 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 11 Jun 2011 22:11:16 +0530 Subject: make some changes to the command line guide --- railties/guides/source/command_line.textile | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 026c15feba..8de7101030 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -51,7 +51,7 @@ $ rails new commandsapp Rails will set you up with what seems like a huge amount of stuff for such a tiny command! You've got the entire Rails directory structure now with all the code you need to run our simple application right out of the box. -INFO: This output will seem very familiar when we get to the +generate+ command. Creepy foreshadowing! +INFO: This output will seem very familiar when we get to the +generate+ command. h4. +rails server+ @@ -288,11 +288,7 @@ You can also use the alias "db" to invoke the dbconsole: 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. - -Let's say you're creating a website for a client who wants a small accounting system. Every event having to do with money must be logged, and must never be deleted. Wouldn't it be great if we could override the behavior of a model to never actually take its record out of the database, but instead, just set a field? - -There is such a thing! The plugin we're installing is called +acts_as_paranoid+, and it lets models implement a +deleted_at+ column that gets set when you call destroy. Later, when calling find, the plugin will tack on a database check to filter out "deleted" things. +The +rails plugin+ command simplifies plugin management; think a miniature version of the Gem utility. $ rails plugin install https://github.com/technoweenie/acts_as_paranoid.git @@ -310,6 +306,12 @@ h4. +rails runner+ $ rails runner "Model.long_running_method" +You can specify the environment in which the +runner+ command should operate using the +-e+ switch. + + +$ rails runner -e staging "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. @@ -388,6 +390,8 @@ 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. +More information about migrations can be found in the "Migrations":migrations.html guide. + 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. @@ -478,7 +482,9 @@ development: ... -It also generated some lines in our database.yml configuration corresponding to our choice of PostgreSQL for database. The only catch with using the SCM options is that you have to make your application's directory first, then initialize your SCM, then you can run the +rails new+ command to generate the basis of your app. +It also generated some lines in our database.yml configuration corresponding to our choice of PostgreSQL for database. + +NOTE. The only catch with using the SCM options is that you have to make your application's directory first, then initialize your SCM, then you can run the +rails new+ command to generate the basis of your app. h4. +server+ with Different Backends -- cgit v1.2.3 From d91ee6cba43b474df47751c130da781f9febeb90 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 12 Jun 2011 01:30:40 +0530 Subject: more command guide changes --- railties/guides/source/command_line.textile | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 8de7101030..013476a4dd 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -51,15 +51,13 @@ $ rails new commandsapp Rails will set you up with what seems like a huge amount of stuff for such a tiny command! You've got the entire Rails directory structure now with all the code you need to run our simple application right out of the box. -INFO: This output will seem very familiar when we get to the +generate+ command. - h4. +rails server+ -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 access your application through a web browser. -INFO: WEBrick isn't your only option for serving Rails. We'll get to that in a later section. +INFO: WEBrick isn't your only option for serving Rails. We'll get to that "later":#different-servers. -Without any prodding of any kind, +rails server+ will run our new shiny Rails app: +With no further work, +rails server+ will run our new shiny Rails app: $ cd commandsapp @@ -83,7 +81,7 @@ The +rails generate+ command uses templates to create a whole lot of things. You $ rails generate -Usage: rails generate generator [args] [options] +Usage: rails generate GENERATOR [args] [options] ... ... @@ -171,7 +169,7 @@ Then the view, to display our message (in +app/views/greetings/hello.html.erb+):

<%= @message %>

-Deal. Go check it out in your browser. Fire up your server using +rails server+. +Fire up your server using +rails server+. $ rails server @@ -486,7 +484,7 @@ It also generated some lines in our database.yml configuration corresponding to NOTE. The only catch with using the SCM options is that you have to make your application's directory first, then initialize your SCM, then you can run the +rails new+ command to generate the basis of your app. -h4. +server+ with Different Backends +h4(#different-servers). +server+ with Different Backends Many people have created a large number different web servers in Ruby, and many of them can be used to run Rails. Since version 2.3, Rails uses Rack to serve its webpages, which means that any webserver that implements a Rack handler can be used. This includes WEBrick, Mongrel, Thin, and Phusion Passenger (to name a few!). -- cgit v1.2.3 From 07bf60864474ba2217636ca1d2216fe7b89a6628 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 12 Jun 2011 02:16:08 +0530 Subject: document server options --- railties/guides/source/command_line.textile | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 013476a4dd..57c71eee09 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -75,6 +75,12 @@ With just three commands we whipped up a Rails server listening on port 3000. Go You can also use the alias "s" to start the server: rails s. +The server can be run on a different port using the +-p+ option. The default development environment can be changed using +-e+. + + +$ rails server -e production + + 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: -- cgit v1.2.3 From d48bbc895f08efd9b98e79986d1e9aeb43c1baef Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Sat, 11 Jun 2011 19:32:01 -0300 Subject: Add example for rails server port option. --- railties/guides/source/command_line.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 57c71eee09..6110846b19 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -78,7 +78,7 @@ You can also use the alias "s" to start the server: rails s. The server can be run on a different port using the +-p+ option. The default development environment can be changed using +-e+. -$ rails server -e production +$ rails server -e production -p 4000 h4. +rails generate+ -- cgit v1.2.3 From 00b4756790b04272da3e1ce821a35cc5a9ab1c77 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 12 Jun 2011 16:17:34 +0530 Subject: assets are in app now and not in public --- railties/guides/source/getting_started.textile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 670979c3c2..7ae3da560e 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -177,14 +177,14 @@ In any case, Rails will create a folder in your working directory called blo |Gemfile|This file allows you to specify what gem dependencies are needed for your Rails application.| |README|This is a brief instruction manual for your application. Use it to tell others what your application does, how to set it up, and so on.| |Rakefile|This file contains batch jobs that can be run from the terminal.| -|app/|Contains the controllers, models, and views for your application. You'll focus on this folder for the remainder of this guide.| +|app/|Contains the controllers, models, views and assets for your application. You'll focus on this folder for the remainder of this guide.| |config/|Configure your application's runtime rules, routes, database, and more.| |config.ru|Rack configuration for Rack based servers used to start the application.| |db/|Shows your current database schema, as well as the database migrations. You'll learn about migrations shortly.| |doc/|In-depth documentation for your application.| |lib/|Extended modules for your application (not covered in this guide).| |log/|Application log files.| -|public/|The only folder seen to the world as-is. This is where your images, JavaScript files, stylesheets (CSS), and other static files go.| +|public/|The only folder seen to the world as-is. Contains the static files and compiled assets.| |script/|Contains the rails script that starts your app and can contain other scripts you use to deploy or run your application.| |test/|Unit tests, fixtures, and other test apparatus. These are covered in "Testing Rails Applications":testing.html| |tmp/|Temporary files| @@ -290,7 +290,7 @@ This will fire up an instance of the WEBrick web server by default (Rails can al TIP: To stop the web server, hit Ctrl+C in the terminal window where it's running. In development mode, Rails does not generally require you to stop the server; changes you make in files will be automatically picked up by the server. -The "Welcome Aboard" page is the _smoke test_ for a new Rails application: it makes sure that you have your software configured correctly enough to serve a page. You can also click on the _About your application’s environment_ link to see a summary of your Application's environment. +The "Welcome Aboard" page is the _smoke test_ for a new Rails application: it makes sure that you have your software configured correctly enough to serve a page. You can also click on the _About your application’s environment_ link to see a summary of your application's environment. h4. Say "Hello", Rails @@ -364,11 +364,11 @@ The scaffold generator will build 15 files in your application, along with some |app/views/posts/new.html.erb |A view to create a new post| |app/views/posts/_form.html.erb |A partial to control the overall look and feel of the form used in edit and new views| |app/helpers/posts_helper.rb |Helper functions to be used from the post views| +|app/assets/stylesheets/scaffold.css.scss |Cascading style sheet to make the scaffolded views look better| |test/unit/post_test.rb |Unit testing harness for the posts model| |test/functional/posts_controller_test.rb |Functional testing harness for the posts controller| |test/unit/helpers/posts_helper_test.rb |Unit testing harness for the posts helper| |config/routes.rb |Edited to include routing information for posts| -|app/assets/stylesheets/scaffold.css.scss |Cascading style sheet to make the scaffolded views look better| h4. Running a Migration -- cgit v1.2.3 From 67a705f95241e447b996487e5c42f2245f83aca2 Mon Sep 17 00:00:00 2001 From: Lukas Stejskal Date: Mon, 13 Jun 2011 14:21:17 +0200 Subject: fix two typos: and array -> an array --- railties/guides/source/active_support_core_extensions.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 7512f7bcb9..16cacc9928 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -2282,7 +2282,7 @@ NOTE: Defined in +active_support/core_ext/array/grouping.rb+. h5. +in_groups(number, fill_with = nil)+ -The method +in_groups+ splits an array into a certain number of groups. The method returns and array with the groups: +The method +in_groups+ splits an array into a certain number of groups. The method returns an array with the groups: %w(1 2 3 4 5 6 7).in_groups(3) @@ -2714,7 +2714,7 @@ Active Support extends the method +Range#step+ so that it can be invoked without (1..10).step(2) # => [1, 3, 5, 7, 9] -As the example shows, in that case the method returns and array with the corresponding elements. +As the example shows, in that case the method returns an array with the corresponding elements. NOTE: Defined in +active_support/core_ext/range/blockless_step.rb+. -- cgit v1.2.3 From 3b4f04ab832b00806b2de78f1947d6438dd13f59 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 13 Jun 2011 23:14:15 +0530 Subject: document the instance_accessor option for cattr_accessor --- .../source/active_support_core_extensions.textile | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 16cacc9928..f9f7f2d83c 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1036,18 +1036,24 @@ module ActionView end -we can access +field_error_proc+ in views. The generation of the writer instance method can be prevented by setting +:instance_writer+ to +false+ (not any false value, but exactly +false+): +we can access +field_error_proc+ in views. + +The generation of the reader instance method can be prevented by setting +:instance_reader+ to +false+ and the generation of the writer instance method can be prevented by setting +:instance_writer+ to +false+. Generation of both methods can be prevented by setting +:instance_accessor+ to +false+. In all cases, the value must be exactly +false+ and not any false value. -module ActiveRecord - class Base - # No pluralize_table_names= instance writer is generated. - cattr_accessor :pluralize_table_names, :instance_writer => false +module A + class B + # No first_name instance reader is generated. + cattr_accessor :first_name, :instance_reader => false + # No last_name= instance writer is generated. + cattr_accessor :last_name, :instance_writer => false + # No surname instance reader or surname= writer is generated. + cattr_accessor :surname, :instance_accessor => false end end -A model may find that option useful as a way to prevent mass-assignment from setting the attribute. +A model may find it useful to set +:instance_accessor+ to +false+ as a way to prevent mass-assignment from setting the attribute. NOTE: Defined in +active_support/core_ext/class/attribute_accessors.rb+. -- cgit v1.2.3 From 9db268db651bcd4d8a2ee5af7e37b4d2aeab98ec Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 14 Jun 2011 00:30:13 +0530 Subject: fix minor errors in nested model guide --- railties/guides/source/nested_model_forms.textile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/nested_model_forms.textile b/railties/guides/source/nested_model_forms.textile index 55694c0eb4..4b1fd2e0ac 100644 --- a/railties/guides/source/nested_model_forms.textile +++ b/railties/guides/source/nested_model_forms.textile @@ -90,7 +90,7 @@ h3. Views h4. Controller code -A nested model form will _only_ be build if the associated object(s) exist. This means that for a new model instance you would probably want to build the associated object(s) first. +A nested model form will _only_ be built if the associated object(s) exist. This means that for a new model instance you would probably want to build the associated object(s) first. Consider the following typical RESTful controller which will prepare a new Person instance and its +address+ and +projects+ associations before rendering the +new+ template: @@ -144,7 +144,7 @@ Now add a nested form for the +address+ association: <%= f.text_field :name %> <%= f.fields_for :address do |af| %> - <%= f.text_field :street %> + <%= af.text_field :street %> <% end %> <% end %> @@ -159,7 +159,7 @@ This generates: -Notice that +fields_for+ recognized the +address+ as an association for which a nested model form should be build by the way it has namespaced the +name+ attribute. +Notice that +fields_for+ recognized the +address+ as an association for which a nested model form should be built by the way it has namespaced the +name+ attribute. When this form is posted the Rails parameter parser will construct a hash like the following: @@ -185,7 +185,7 @@ The form code for an association collection is pretty similar to that of a singl <%= f.text_field :name %> <%= f.fields_for :projects do |pf| %> - <%= f.text_field :name %> + <%= pf.text_field :name %> <% end %> <% end %> @@ -201,7 +201,7 @@ Which generates: -As you can see it has generated 2 +project name+ inputs, one for each new +project+ that’s build in the controllers +new+ action. Only this time the +name+ attribute of the input contains a digit as an extra namespace. This will be parsed by the Rails parameter parser as: +As you can see it has generated 2 +project name+ inputs, one for each new +project+ that was built in the controller's +new+ action. Only this time the +name+ attribute of the input contains a digit as an extra namespace. This will be parsed by the Rails parameter parser as: { @@ -215,7 +215,7 @@ As you can see it has generated 2 +project name+ inputs, one for each new +proje } -You can basically see the +projects_attributes+ hash as an array of attribute hashes. One for each model instance. +You can basically see the +projects_attributes+ hash as an array of attribute hashes, one for each model instance. NOTE: The reason that +fields_for+ constructed a form which would result in a hash instead of an array is that it won't work for any forms nested deeper than one level deep. -- cgit v1.2.3 From 10c203508415767eb0a15f9da3a48e56f552c1ce Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Tue, 14 Jun 2011 10:53:38 -0300 Subject: Add Time#all_* to AS guides. --- .../source/active_support_core_extensions.textile | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index f9f7f2d83c..763e0d585b 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -3322,6 +3322,32 @@ Active Support defines +Time.current+ to be today in the current time zone. That When making Time comparisons using methods which honor the user time zone, make sure to use +Time.current+ and not +Time.now+. There are cases where the user time zone might be in the future compared to the system time zone, which +Time.today+ uses by default. This means +Time.now+ may equal +Time.yesterday+. +h5. +all_day+, +all_week+, +all_month+, +all_quarter+ and +all_year+ + +The method +all_day+ returns a range representing the whole day of the current time. + + +now = Time.now +# => Mon, 09 Aug 2010 23:20:05 UTC +00:00 +now.all_day +# => Mon, 09 Aug 2010 00:00:00 UTC +00:00..Mon, 09 Aug 2010 23:59:59 UTC +00:00 + + +Analogously, +all_week+, +all_month+, +all_quarter+ and +all_year+ all serve the purpose of generating time ranges. + + +now = Time.now +# => Mon, 09 Aug 2010 23:20:05 UTC +00:00 +now.all_week +# => Mon, 09 Aug 2010 00:00:00 UTC +00:00..Sun, 15 Aug 2010 23:59:59 UTC +00:00 +now.all_month +# => Sat, 01 Aug 2010 00:00:00 UTC +00:00..Tue, 31 Aug 2010 23:59:59 UTC +00:00 +now.all_quarter +# => Thu, 01 Jul 2010 00:00:00 UTC +00:00..Thu, 30 Sep 2010 23:59:59 UTC +00:00 +now.all_year +# => Fri, 01 Jan 2010 00:00:00 UTC +00:00..Fri, 31 Dec 2010 23:59:59 UTC +00:00 + + h4. Time Constructors Active Support defines +Time.current+ to be +Time.zone.now+ if there's a user time zone defined, with fallback to +Time.now+: -- cgit v1.2.3 From 0c1e630d181fdf63a03ce87b70820832f22d00d8 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Tue, 14 Jun 2011 11:01:00 -0300 Subject: Prefer Time.current over Time.now on example code --- railties/guides/source/active_support_core_extensions.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 763e0d585b..21708e0fba 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -3327,7 +3327,7 @@ h5. +all_day+, +all_week+, +all_month+, +all_quarter+ and +all_year+ The method +all_day+ returns a range representing the whole day of the current time. -now = Time.now +now = Time.current # => Mon, 09 Aug 2010 23:20:05 UTC +00:00 now.all_day # => Mon, 09 Aug 2010 00:00:00 UTC +00:00..Mon, 09 Aug 2010 23:59:59 UTC +00:00 @@ -3336,7 +3336,7 @@ now.all_day Analogously, +all_week+, +all_month+, +all_quarter+ and +all_year+ all serve the purpose of generating time ranges. -now = Time.now +now = Time.current # => Mon, 09 Aug 2010 23:20:05 UTC +00:00 now.all_week # => Mon, 09 Aug 2010 00:00:00 UTC +00:00..Sun, 15 Aug 2010 23:59:59 UTC +00:00 -- cgit v1.2.3 From d5b1cf592b5e9e4363ff6ee87e33850ae7e9c929 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Wed, 15 Jun 2011 07:36:04 +0530 Subject: Adding doc for Sqlite3 database for Jruby platform #jruby --- railties/guides/source/getting_started.textile | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 7ae3da560e..a3d8178eac 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -258,6 +258,16 @@ development: Change the username and password in the +development+ section as appropriate. +h5. Configuring an SQLite3 Database for Jruby Platform + +If you choose to use SQLite3 and using Jruby, your +config/database.yml+ will look a little different. Here's the development section: + + +development: + adapter: jdbcsqlite3 + database: db/development.sqlite3 + + TIP: You don't have to update the database configurations manually. If you had a look at the options of application generator, you have seen that one of them is named --database. It lets you choose an adapter for couple of most used relational databases. You can even run the generator repeatedly: cd .. && rails new blog --database=mysql. When you confirm the overwriting of the +config/database.yml+ file, your application will be configured for MySQL instead of SQLite. h4. Creating the Database -- cgit v1.2.3 From aed85375caad9bbbb3a97aa49cec22c5771d5f8b Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Wed, 15 Jun 2011 07:36:52 +0530 Subject: Added doc for Mysql database with Jruby platform #jruby --- railties/guides/source/getting_started.textile | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index a3d8178eac..3549dd89ab 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -268,6 +268,18 @@ development: database: db/development.sqlite3 +h5. Configuring an Mysql Database for Jruby Platform + +If you choose to use Mysql and using Jruby, your +config/database.yml+ will look a little different. Here's the development section: + + +development: + adapter: jdbcmysql + database: blog_development + username: root + password: + + TIP: You don't have to update the database configurations manually. If you had a look at the options of application generator, you have seen that one of them is named --database. It lets you choose an adapter for couple of most used relational databases. You can even run the generator repeatedly: cd .. && rails new blog --database=mysql. When you confirm the overwriting of the +config/database.yml+ file, your application will be configured for MySQL instead of SQLite. h4. Creating the Database -- cgit v1.2.3 From 900dbca96536f6036a3621bd01b5c5a94386d51e Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Wed, 15 Jun 2011 07:38:08 +0530 Subject: Added Doc for Postgresql database with Jruby Platform. #jruby --- railties/guides/source/getting_started.textile | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 3549dd89ab..459063ad4b 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -280,6 +280,19 @@ development: password: +h5. Configuring an PostgreSQL Database for Jruby Platform + +If you choose to use PostgreSQL and using Jruby, your +config/database.yml+ will look a little different. Here's the development section: + + +development: + adapter: jdbcpostgresql + encoding: unicode + database: blog_development + username: blog + password: + + TIP: You don't have to update the database configurations manually. If you had a look at the options of application generator, you have seen that one of them is named --database. It lets you choose an adapter for couple of most used relational databases. You can even run the generator repeatedly: cd .. && rails new blog --database=mysql. When you confirm the overwriting of the +config/database.yml+ file, your application will be configured for MySQL instead of SQLite. h4. Creating the Database -- cgit v1.2.3 From 8f05a2f7aeae0d1185417882d1939c9c0aba1379 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Wed, 15 Jun 2011 07:39:24 +0530 Subject: Using "Finally" at the end of database section. --- railties/guides/source/getting_started.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 459063ad4b..a6396c029a 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -244,7 +244,7 @@ If your development computer's MySQL installation includes a root user with an e h5. Configuring a PostgreSQL Database -Finally if you choose to use PostgreSQL, your +config/database.yml+ will be customized to use PostgreSQL databases: +If you choose to use PostgreSQL, your +config/database.yml+ will be customized to use PostgreSQL databases: development: @@ -282,7 +282,7 @@ development: h5. Configuring an PostgreSQL Database for Jruby Platform -If you choose to use PostgreSQL and using Jruby, your +config/database.yml+ will look a little different. Here's the development section: +Finally if you choose to use PostgreSQL and using Jruby, your +config/database.yml+ will look a little different. Here's the development section: development: -- cgit v1.2.3 From 57ace9868aa076ab2dc9763c0ef1892af0501fc3 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Wed, 15 Jun 2011 07:40:49 +0530 Subject: Moving hint down. As required after all database examples. --- railties/guides/source/getting_started.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index a6396c029a..7bd300c188 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -256,8 +256,6 @@ development: password: -Change the username and password in the +development+ section as appropriate. - h5. Configuring an SQLite3 Database for Jruby Platform If you choose to use SQLite3 and using Jruby, your +config/database.yml+ will look a little different. Here's the development section: @@ -293,6 +291,8 @@ development: password: +Change the username and password in the +development+ section as appropriate. + TIP: You don't have to update the database configurations manually. If you had a look at the options of application generator, you have seen that one of them is named --database. It lets you choose an adapter for couple of most used relational databases. You can even run the generator repeatedly: cd .. && rails new blog --database=mysql. When you confirm the overwriting of the +config/database.yml+ file, your application will be configured for MySQL instead of SQLite. h4. Creating the Database -- cgit v1.2.3 From 0bdeddb97e61dbfde01e928cf577c7bf7cfd0592 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Wed, 15 Jun 2011 10:45:05 +0530 Subject: Jruby => JRuby, Mysql => MySQL --- railties/guides/source/getting_started.textile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 7bd300c188..5e9d37df85 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -256,9 +256,9 @@ development: password: -h5. Configuring an SQLite3 Database for Jruby Platform +h5. Configuring an SQLite3 Database for JRuby Platform -If you choose to use SQLite3 and using Jruby, your +config/database.yml+ will look a little different. Here's the development section: +If you choose to use SQLite3 and using JRuby, your +config/database.yml+ will look a little different. Here's the development section: development: @@ -266,9 +266,9 @@ development: database: db/development.sqlite3 -h5. Configuring an Mysql Database for Jruby Platform +h5. Configuring an MySQL Database for JRuby Platform -If you choose to use Mysql and using Jruby, your +config/database.yml+ will look a little different. Here's the development section: +If you choose to use MySQL and using JRuby, your +config/database.yml+ will look a little different. Here's the development section: development: @@ -278,9 +278,9 @@ development: password: -h5. Configuring an PostgreSQL Database for Jruby Platform +h5. Configuring an PostgreSQL Database for JRuby Platform -Finally if you choose to use PostgreSQL and using Jruby, your +config/database.yml+ will look a little different. Here's the development section: +Finally if you choose to use PostgreSQL and using JRuby, your +config/database.yml+ will look a little different. Here's the development section: development: -- cgit v1.2.3 From 045d9d2baeb0e733edcd7b1815132ac2a48b2d5a Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 15 Jun 2011 11:44:31 +0530 Subject: minor copy edit 0bdeddb --- railties/guides/source/getting_started.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 5e9d37df85..3011f7136b 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -266,7 +266,7 @@ development: database: db/development.sqlite3 -h5. Configuring an MySQL Database for JRuby Platform +h5. Configuring a MySQL Database for JRuby Platform If you choose to use MySQL and using JRuby, your +config/database.yml+ will look a little different. Here's the development section: @@ -278,7 +278,7 @@ development: password: -h5. Configuring an PostgreSQL Database for JRuby Platform +h5. Configuring a PostgreSQL Database for JRuby Platform Finally if you choose to use PostgreSQL and using JRuby, your +config/database.yml+ will look a little different. Here's the development section: -- cgit v1.2.3 From 6d965355244055e7bef995f1a263cb1cd2993e45 Mon Sep 17 00:00:00 2001 From: thoefer Date: Wed, 15 Jun 2011 12:14:17 +0200 Subject: =?UTF-8?q?Updated=20rails=C2=B4s=20guides=20on=20the=20config.ser?= =?UTF-8?q?ve=5Fstatic=5Fassets=20and=20it=C2=B4s=20settings=20in=20produc?= =?UTF-8?q?tion=20mode=20using=20WEBrick.=20This=20documentation=20has=20i?= =?UTF-8?q?t=C2=B4s=20roots=20in=20#issue1657.=20You=20have=20to=20set=20c?= =?UTF-8?q?onfig.serve=5Fstatic=5Fassets=20to=20true=20in=20production=20m?= =?UTF-8?q?ode=20with=20WEBrick=20as=20only=20this=20includes=20ActionDisp?= =?UTF-8?q?atch::Static.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- railties/guides/source/configuring.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index a4cc62c117..84b5fbc73b 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -98,7 +98,7 @@ NOTE. The +config.asset_path+ configuration is ignored if the asset pipeline is * +config.secret_token+ used for specifying a key which allows sessions for the application to be verified against a known secure key to prevent tampering. Applications get +config.secret_token+ initialized to a random key in +config/initializers/secret_token.rb+. -* +config.serve_static_assets+ configures Rails to serve static assets. Defaults to true, but in the production environment is turned off. The server software used to run the application should be used to serve the assets instead. +* +config.serve_static_assets+ configures Rails itself to serve static assets. Defaults to true, but in the production environment is turned off as the server software (e.g. Nginx or Apache) used to run the application should serve static assets instead. Unlike the default setting set this to true when running (absolutely not recommended!) or testing your app in production mode using WEBrick. Otherwise you won´t be able use page caching and requests for files that exist regularly under the public directory will anyway hit your Rails app. * +config.session_store+ is usually set up in +config/initializers/session_store.rb+ and specifies what class to use to store the session. Possible values are +:cookie_store+ which is the default, +:mem_cache_store+, and +:disabled+. The last one tells Rails not to deal with sessions. Custom session stores can also be specified: -- cgit v1.2.3 From 3e441596509bbb5eb485c60efe78a629c028562e Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 15 Jun 2011 22:53:26 +0530 Subject: document how rake notes work --- railties/guides/source/command_line.textile | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 6110846b19..c71baa76d1 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -402,7 +402,28 @@ If you want to strip out or rebuild any of the Rails documentation (including th 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. ++rake notes+ will search through your code for comments beginning with FIXME, OPTIMIZE or TODO. This checks only for files with extension +.builder+, +.rb+, +.rxml+, +.rhtml+ and +.erb+. + + +$ rake notes +(in /home/foobar/commandsapp) +app/controllers/admin/users_controller.rb: + * [ 20] [TODO] any other way to do this? + * [132] [FIXME] high priority for next deploy + +app/model/school.rb: + * [ 13] [OPTIMIZE] refactor this code to make it faster + * [ 17] [FIXME] + + +You can also use custom annotations in your code and list them using +rake notes:custom+ and specify the annotation using an environment variable +ANNOTATION+. + + +$ rake notes:custom ANNOTATION=BUG +(in /home/foobar/commandsapp) +app/model/post.rb: + * [ 23] Have to fix this one before pushing! + h4. +routes+ -- cgit v1.2.3 From 406d61ee8c0311f742ac74b9a15845cc3cd214d3 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 15 Jun 2011 23:26:19 +0530 Subject: add details on how to use specific annotations in rake:notes --- railties/guides/source/command_line.textile | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index c71baa76d1..03ff3097da 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -402,7 +402,7 @@ If you want to strip out or rebuild any of the Rails documentation (including th h4. +notes+ -+rake notes+ will search through your code for comments beginning with FIXME, OPTIMIZE or TODO. This checks only for files with extension +.builder+, +.rb+, +.rxml+, +.rhtml+ and +.erb+. ++rake notes+ will search through your code for comments beginning with FIXME, OPTIMIZE or TODO. The search is only done in files with extension +.builder+, +.rb+, +.rxml+, +.rhtml+ and +.erb+ for both default and custom annotations. $ rake notes @@ -416,7 +416,19 @@ app/model/school.rb: * [ 17] [FIXME] -You can also use custom annotations in your code and list them using +rake notes:custom+ and specify the annotation using an environment variable +ANNOTATION+. +If you are looking for a specific annotation, say FIXME, you can use +rake notes:fixme+. Note that you have to lower case the annotation's name. + + +$ rake notes:fixme +(in /home/foobar/commandsapp) +app/controllers/admin/users_controller.rb: + * [132] high priority for next deploy + +app/model/school.rb: + * [ 17] + + +You can also use custom annotations in your code and list them using +rake notes:custom+ by specifying the annotation using an environment variable +ANNOTATION+. $ rake notes:custom ANNOTATION=BUG @@ -425,6 +437,8 @@ app/model/post.rb: * [ 23] Have to fix this one before pushing! +NOTE. When using specific annotations and custom annotations, the annotation name (FIXME, BUG etc) is not displayed in the output lines. + 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. -- cgit v1.2.3 From 0dd9db871d78408db7b1fe7397c3fcf7c9ffb541 Mon Sep 17 00:00:00 2001 From: JudeAr Date: Wed, 15 Jun 2011 22:04:20 -0700 Subject: fixed typo chnages --- railties/guides/source/command_line.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 03ff3097da..bedb9fc6d9 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -527,7 +527,7 @@ NOTE. The only catch with using the SCM options is that you have to make your ap h4(#different-servers). +server+ with Different Backends -Many people have created a large number different web servers in Ruby, and many of them can be used to run Rails. Since version 2.3, Rails uses Rack to serve its webpages, which means that any webserver that implements a Rack handler can be used. This includes WEBrick, Mongrel, Thin, and Phusion Passenger (to name a few!). +Many people have created a large number of different web servers in Ruby, and many of them can be used to run Rails. Since version 2.3, Rails uses Rack to serve its webpages, which means that any webserver that implements a Rack handler can be used. This includes WEBrick, Mongrel, Thin, and Phusion Passenger (to name a few!). NOTE: For more details on the Rack integration, see "Rails on Rack":rails_on_rack.html. -- cgit v1.2.3 From cbf2af1e81fcae8c0ee4472e7bb0620c77786106 Mon Sep 17 00:00:00 2001 From: JudeAr Date: Wed, 15 Jun 2011 22:15:53 -0700 Subject: typo changes fixed --- railties/guides/source/command_line.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index bedb9fc6d9..8c78cab84f 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -3,7 +3,7 @@ h2. A Guide to The Rails Command Line Rails comes with every command line tool you'll need to * Create a Rails application -* Generate models, controllers, database migrations, and unit tests +* Generate models, controllers, database migrations and unit tests * Start a development server * Experiment with objects through an interactive shell * Profile and benchmark your new creation -- cgit v1.2.3 From bfb022adae4b8f6ba35872531bc5774b72fbe467 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Thu, 16 Jun 2011 12:29:47 +0530 Subject: document doc:* rake tasks --- railties/guides/source/command_line.textile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 8c78cab84f..b42fdac7e4 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -398,7 +398,13 @@ More information about migrations can be found in the "Migrations":migrations.ht 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. +The +doc:+ namespace has the tools to generate documentation for your app, API documentation, guides. Documentation can also be stripped which is mainly useful for slimming your codebase, like if you're writing a Rails application for an embedded platform. + +* +rake doc:app+ generates documentation for your application in +doc/app+. +* +rake doc:guides+ generates Rails guides in +doc/guides+. +* +rake doc:rails+ generates API documentation for Rails in +doc/api+. +* +rake doc:plugins+ generates API documentation for all the plugins installed in the application in +doc/plugins+. +* +rake doc:clobber_plugins+ removes the generated documentation for all plugins. h4. +notes+ -- cgit v1.2.3 From 7c2db6ce37aa37014ad216e0f5070c6b147382e7 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Thu, 16 Jun 2011 22:48:47 +0530 Subject: add info that plugin installs need git or svn installed --- railties/guides/source/command_line.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index b42fdac7e4..dd21fb0e93 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -292,7 +292,7 @@ You can also use the alias "db" to invoke the dbconsole: rails db. h4. +rails plugin+ -The +rails plugin+ command simplifies plugin management; think a miniature version of the Gem utility. +The +rails plugin+ command simplifies plugin management. Plugins can be installed by name or their repository urls. You need to have git installed if you want to install a plugin from a git repo. The same holds for Subversion too. $ rails plugin install https://github.com/technoweenie/acts_as_paranoid.git -- cgit v1.2.3 From 07d62ff7191f3334dffece1495a38b35f5669cbf Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Thu, 16 Jun 2011 22:48:05 +0530 Subject: minor clean up generators section --- railties/guides/source/command_line.textile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index dd21fb0e93..43f2aad5bf 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -83,7 +83,7 @@ $ rails server -e production -p 4000 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: +The +rails generate+ command uses templates to create a whole lot of things. Running +rails generate+ by itself gives a list of available generators: $ rails generate @@ -103,7 +103,7 @@ Rails: NOTE: You can install more generators through generator gems, portions of plugins you'll undoubtedly install, and you can even create your own! -Using generators will save you a large amount of time by writing *boilerplate code*, code that is necessary for the app to work, but not necessary for you to spend time writing. That's what we have computers for. +Using generators will save you a large amount of time by writing *boilerplate code*, code that is necessary for the app to work. Let's make our own controller with the controller generator. But what command should we use? Let's ask the generator: @@ -152,7 +152,8 @@ $ rails generate controller Greetings hello create test/unit/helpers/greetings_helper_test.rb invoke assets create app/assets/javascripts/greetings.js - create app/assets/stylesheets/greetings.css + invoke css + create app/assets/stylesheets/greetings.css @@ -188,7 +189,7 @@ The URL will be "http://localhost:3000/greetings/hello":http://localhost:3000/gr INFO: With a normal, plain-old Rails application, your URLs will generally follow the pattern of http://(host)/(controller)/(action), and a URL like http://(host)/(controller) will hit the *index* action of that controller. -Rails comes with a generator for data models too: +Rails comes with a generator for data models too. $ rails generate model -- cgit v1.2.3 From 248552e32432cf807634188add05489d6902242d Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 17 Jun 2011 10:57:33 +0200 Subject: AS guide: expands safe string docs regarding destructive methods, coercion, copying, etc. --- .../source/active_support_core_extensions.textile | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 7512f7bcb9..1fe805d2d7 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1146,8 +1146,12 @@ h3. Extensions to +String+ h4. Output Safety +h5. Motivation + Inserting data into HTML templates needs extra care. For example you can't just interpolate +@review.title+ verbatim into an HTML page. On one hand if the review title is "Flanagan & Matz rules!" the output won't be well-formed because an ampersand has to be escaped as "&amp;". On the other hand, depending on the application that may be a big security hole because users can inject malicious HTML setting a hand-crafted review title. Check out the "section about cross-site scripting in the Security guide":security.html#cross-site-scripting-xss for further information about the risks. +h5. Safe Strings + Active Support has the concept of (html) safe strings since Rails 3. A safe string is one that is marked as being insertable into HTML as is. It is trusted, no matter whether it has been escaped or not. Strings are considered to be unsafe by default: @@ -1173,8 +1177,6 @@ s # => "" It is your responsibility to ensure calling +html_safe+ on a particular string is fine. -NOTE: For performance reasons safe strings are implemented in a way that cannot offer an in-place +html_safe!+ variant. - If you append onto a safe string, either in-place with +concat+/<<, or with +, the result is a safe string. Unsafe arguments are escaped: @@ -1215,6 +1217,22 @@ end NOTE: Defined in +active_support/core_ext/string/output_safety.rb+. +h5. Transformation + +As a rule of thumb, except perhaps for concatenation as explained above, any method that may change a string gives you an unsafe string. These are +donwcase+, +gsub+, +strip+, +chomp+, +underscore+, etc. + +In the case of in-place transformations like +gsub!+ the receiver itself becomes unsafe. + +INFO: The safety bit is lost always, no matter whether the transformation actually changed something. + +h5. Conversion and Coercion + +Calling +to_s+ on a safe string returns a safe string, but coercion with +to_str+ returns an unsafe string. + +h5. Copying + +Calling +dup+ or +clone+ on safe strings yields safe strings. + h4. +squish+ The method +squish+ strips leading and trailing whitespace, and substitutes runs of whitespace with a single space each: -- cgit v1.2.3 From 0fd52bb6c79f20b8dbd5c8afb774ef1dae155fc4 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sat, 18 Jun 2011 11:16:10 +1000 Subject: Added 'Configuring Assets' section to configuring guide --- railties/guides/source/configuring.textile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index 84b5fbc73b..ca11f757ff 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -116,8 +116,23 @@ WARNING: Threadsafe operation is incompatible with the normal workings of develo * +config.whiny_nils+ enables or disables warnings when a certain set of methods are invoked on +nil+ and it does not respond to them. Defaults to true in development and test environments. +h4. Configuring Assets + +Rails 3.1, by default, is set up to use the +sprockets+ gem to manage assets within an application. This gem concatenates and compresses assets in order to make serving them much less painful. + +* +config.assets.css_compressor+ defines the CSS compressor to use. Only supported value at the moment is +:yui+, which uses the +yui-compressor+ gem. + * +config.assets.enabled+ a flag that controls whether the asset pipeline is enabled. It is explicitly initialized in +config/application.rb+. +* +config.assets.js_compressor+ defines the JavaScript compressor to use. Possible values are +:closure+, +:uglifier+ and +:yui+ which require the use of the +closure-compiler+, +uglifier+ or +yui-compressor+ gems respectively. + +* +config.assets.paths+ contains the paths which are used to look for assets. Appending paths to this configuration option will cause those paths to be used in the search for assets. + +* +config.assets.precompile+ allows you to specify additional assets (other than +application.css+ and +application.js+) which are to be precompiled when +rake assets:precompile+ is run. + +* +config.assets.prefix+ defines the prefix where assets are served from. Defaults to +/assets+. + + h4. Configuring Generators Rails 3 allows you to alter what generators are used with the +config.generators+ method. This method takes a block: -- cgit v1.2.3 From 20d7d2415f99620590aec07cedcaace34cced1c6 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 18 Jun 2011 10:14:32 +0200 Subject: copy-edits 7c2db6c, cbf2af1, and f391f94 --- railties/guides/source/command_line.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 43f2aad5bf..b0edc1017d 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -3,7 +3,7 @@ h2. A Guide to The Rails Command Line Rails comes with every command line tool you'll need to * Create a Rails application -* Generate models, controllers, database migrations and unit tests +* Generate models, controllers, database migrations, and unit tests * Start a development server * Experiment with objects through an interactive shell * Profile and benchmark your new creation @@ -293,7 +293,7 @@ You can also use the alias "db" to invoke the dbconsole: rails db. h4. +rails plugin+ -The +rails plugin+ command simplifies plugin management. Plugins can be installed by name or their repository urls. You need to have git installed if you want to install a plugin from a git repo. The same holds for Subversion too. +The +rails plugin+ command simplifies plugin management. Plugins can be installed by name or their repository URLs. You need to have Git installed if you want to install a plugin from a Git repo. The same holds for Subversion too. $ rails plugin install https://github.com/technoweenie/acts_as_paranoid.git -- cgit v1.2.3 From c8f046bd45718a741ead574182f3468cddc05c1c Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sat, 18 Jun 2011 19:44:55 +1000 Subject: Flesh out the asset pipeline guide with information learned from today's research --- railties/guides/source/asset_pipeline.textile | 92 +++++++++++++++++++++------ 1 file changed, 72 insertions(+), 20 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index c12bc3d1dc..1b444811a2 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -3,6 +3,7 @@ h2. Asset Pipeline 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: +* Understand what the asset pipeline is and what it does * Properly organize your application assets * Understand the benefits of the asset pipeline * Adding a preprocessor to the pipeline @@ -12,46 +13,97 @@ 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, 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. +With Rails 3.1 comes a new feature known as the asset pipeline. The asset pipeline provides features that have usually been implemented by external gems, such as Jammit and Sprockets. These gems would serve concatenated or compressed versions of the assets of an application, such as stylesheets or javascript files so that the number of requests made to the server are lessened, making the page load faster. + +By having this now as a core feature of Rails, all developers can benefit from the power of having their assets pre-processed, compressed and minified by one central gem, Sprockets. 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. +In previous versions of Rails, all assets lived under the +public+ directory in directories such as +images+, +javascripts+ and +stylesheets+. With Rails 3.1, the preferred location for these assets is now the +app/assets+ directory. Files in this directory will be served by the Sprockets middleware included in the sprockets gem. + +This is not to say that assets can (or should) no longer be placed in +public+. They still can be, they will just be served by the application or the web server which is running the application and served just like normal files. You would only use +app/assets+ if you wish your files to undergo some pre-processing before they are served. + +When a scaffold or controller is generated for the application, Rails will also generate a JavaScript (or CoffeeScript if the +coffee-script+ gem is in the +Gemfile+) and CSS (or SCSS if +sass-rails+ is in the +Gemfile+) file for that controller. For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. It's in these files that JavaScript and CSS unique to this part of the application belong. h4. Asset Organization -WIP +Assets can be placed inside an application in one of three locations: +app/assets+, +lib/assets+ or +vendor/assets+. + ++app/assets+ is for assets that are owned by the application, such as custom images, javascript files or stylesheets. + ++lib/assets+ is for your own libraries' code that doesn't really fit into the scope of the application or those libraries which are shared across applications. + ++vendor/assets+ is for assets that are owned by outside entities, such as code for JavaScript plugins. + +Any subdirectory that exists within these three locations will be added to the search path for Sprockets (visible by calling +Rails.application.config.assets.paths+ in a console). When an asset is requested, these paths will be looked through to see if they contain an asset matching the name specified. Once an asset has been found, it's processed by Sprockets and then served up. + +h4. External Assets + +Assets can also come from external sources such as engines. A good example of this is the +jquery_rails+ gem which comes with Rails 3.1 as standard. This gem contains an engine class which inherits from +Rails::Engine+. By doing this, Rails is informed that the directory for this gem may contain assets and the +app/assets+, +lib/assets+ and +vendor/assets+ directories of this engine are added to the search path of Sprockets. + +h4. Serving Assets + +To serve assets, we can use the same tags that we are generally familiar with: + + + <%= image_tag "rails.png" %> + + +Providing that assets are enabled within our application (+Rails.application.config.assets.enabled+ is set to +true+), this file will be served by Sprockets unless a file at +public/images/rails.png+ exists, in which case that file will be served. If there is no file at +public/images+, Sprockets will look through the available paths until it finds a file that matches the name and then will serve it, first looking in the application's assets directories and then falling back to the various engines of the application. + +To include a JavaScript file we can still use the familiar +javascript_include_tag+. + + + <%= javascript_include_tag "application" %> + + +Similarly, to include a CSS file we can also still use +stylesheet_link_tag+. + + + <%= stylesheet_link_tag "application" %> + + +These files could just be straight JavaScript or CSS files, or they could be _manifest files_. -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. Manifest Files and Directives -h4. Directives +Sprockets allows some assets to be manifest files. These manifest files require what's known as _directives_, which instruct Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets will load the files specified, process them if necessary, concatenate them into one single file and then compress them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, a page's load time can be greatly reduced. -WIP +For example, in the default Rails application there's a +app/assets/javascripts/application.js+ file which contains the following lines: -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) + + //= require jquery + //= require jquery_ujs + //= require_tree . + -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. +In JS files, directives begin with +//=+. In this case, the file is using the +require+ directive twice and the +require_tree+ directive once. The +require+ directive tells Sprockets that we would like to require a file called +jquery.js+ that is available somewhere in the search path for Sprockets. By default, this is located inside the +vendor/assets/javascripts+ directory contained within the +jquery_rails+ gem. An identical event takes place for the +jquery_ujs+ require specified here also. -Using the +require_tree+ directive you can easily include an entire folder of assets. The paths must be relative, so begin them with either a forward slash or dots. For example to include a folder in the same directory you would do +require_tree ./folder_name+ +The +require_tree .+ directive tells Sprockets to include _all_ JavaScript files in this directory into the output. A path relative to the file can be specified if only certain files are required to be loaded. -Require self does... something +There's also a default +app/assets/stylesheets/application.css+ file which contains these lines: -h4. Stacking Preprocessors + + /* ... + *= require_self + *= require_tree . + */ + -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. +The directives that work in the JavaScript files will also work in stylesheets, obviously requiring stylesheets rather than JavaScript files. The +require_tree+ directive here works the same way as the JavaScript one, requiring all stylesheets from the current directory. -h4. Adding a Preproccessor +In this example +require_self+ is used. This will put the CSS contained within the file (if any) at the top of any other CSS in this file unless +require_self+ is specified after another +require+ directive. -WIP +h4. Preprocessing -https://github.com/rtomayko/tilt for gems or config.register_processor('text/css', MyAwesomeProccessor) for local stuff +Based on the extensions of the assets, Sprockets will do preprocessing on the files. With the default gemset that comes with Rails, when a controller or a scaffold is generated, a CoffeeScript file and a SCSS file will be generated in place of a regular JavaScript and CSS file. The example used before was a controller called "projects", which generated an +app/assets/javascripts/projects.js.coffee+ and a +app/assets/stylesheets/projects.css.scss+ file. -h3. Packaging Assets with Your Gems +When these files are requested, they will be processed by the processors provided by the +coffee-script+ and +sass-rails+ gems and then sent back to the browser as JavaScript and SCSS respectively. -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 +In addition to this single layer of pre-processing, we can also put on additional extensions to the end of the file in order for them to be processed using other languages first. For example, we could call our stylesheet +app/assets/stylesheets/projects.css.scss.erb+ it would first be processed as ERB, then SCSS and finally served as CSS. We could also do this with our JavaScript file, calling it +app/assets/javascripts/projects.js.coffee.erb+. -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. +Keep in mind that the order of these pre-processors is important. For example, if we called our JavaScript file +app/assets/javascripts/projects.js.erb.coffee+ then it would be processed with the CoffeeScript interpreter first, which wouldn't understand ERB and therefore we would run into problems. -h3. More on Sprockets +h4. Compressing Assets -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. +WIP: Compressed Assets in Rails are served ... how? \ No newline at end of file -- cgit v1.2.3