From 05fdb310b6e27a399ef3e99e32f319a1ef37bab1 Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Sat, 19 May 2012 10:02:16 -0700 Subject: Getting started guide has been completely rewritten and edited. --- guides/source/getting_started.textile | 2 -- 1 file changed, 2 deletions(-) (limited to 'guides') diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile index e25dac22da..c129aeb2e1 100644 --- a/guides/source/getting_started.textile +++ b/guides/source/getting_started.textile @@ -13,8 +13,6 @@ endprologue. WARNING. This Guide is based on Rails 3.2. Some of the code shown here will not work in earlier versions of Rails. -WARNING: The Edge version of this guide is currently being re-worked. Please excuse us while we re-arrange the place. - h3. Guide Assumptions This guide is designed for beginners who want to get started with a Rails -- cgit v1.2.3 From 4220290d09e682d8454048312b89efaf84f028be Mon Sep 17 00:00:00 2001 From: Gaurish Sharma Date: Tue, 22 May 2012 11:19:32 +0530 Subject: Fix broken link --- guides/source/debugging_rails_applications.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/debugging_rails_applications.textile b/guides/source/debugging_rails_applications.textile index 45fa4ada78..0802a2db26 100644 --- a/guides/source/debugging_rails_applications.textile +++ b/guides/source/debugging_rails_applications.textile @@ -698,7 +698,7 @@ There are some Rails plugins to help you to find errors and debug your applicati h3. References -* "ruby-debug Homepage":http://www.datanoise.com/ruby-debug +* "ruby-debug Homepage":http://bashdb.sourceforge.net/ruby-debug/home-page.html * "debugger Homepage":http://github.com/cldwalker/debugger * "Article: Debugging a Rails application with ruby-debug":http://www.sitepoint.com/article/debug-rails-app-ruby-debug/ * "ruby-debug Basics screencast":http://brian.maybeyoureinsane.net/blog/2007/05/07/ruby-debug-basics-screencast/ -- cgit v1.2.3 From feaa7b35a0214240eb34780ab51b843571e74904 Mon Sep 17 00:00:00 2001 From: Gaurish Sharma Date: Tue, 22 May 2012 19:29:25 +0530 Subject: Remove Obsolute root specifiying short syntax This syntax does not seem to work. Throws the error "can't convert String into Hash (TypeError)" Tested on: * Ruby 1.9.3 * Rails 3.2.3 --- guides/source/routing.textile | 1 - 1 file changed, 1 deletion(-) (limited to 'guides') diff --git a/guides/source/routing.textile b/guides/source/routing.textile index 4a50edbb15..6081651364 100644 --- a/guides/source/routing.textile +++ b/guides/source/routing.textile @@ -629,7 +629,6 @@ You can specify what Rails should route +"/"+ to with the +root+ method: root :to => 'pages#main' -root 'pages#main' # shortcut for the above You should put the +root+ route at the top of the file, because it is the most popular route and should be matched first. You also need to delete the +public/index.html+ file for the root route to take effect. -- cgit v1.2.3 From acdf8ac58dbf71ac274dc93fd9b4c6da539a36b3 Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Tue, 22 May 2012 08:32:12 -0700 Subject: The initialization guide will cover Rails 4 --- guides/source/initialization.textile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'guides') diff --git a/guides/source/initialization.textile b/guides/source/initialization.textile index 155a439e64..361045282a 100644 --- a/guides/source/initialization.textile +++ b/guides/source/initialization.textile @@ -1,13 +1,15 @@ h2. The Rails Initialization Process -This guide explains the internals of the initialization process in Rails as of Rails 3.1. It is an extremely in-depth guide and recommended for advanced Rails developers. +This guide explains the internals of the initialization process in Rails +as of Rails 4. It is an extremely in-depth guide and recommended for advanced Rails developers. * Using +rails server+ * Using Passenger endprologue. -This guide goes through every single file, class and method call that is required to boot up the Ruby on Rails stack for a default Rails 3.1 application, explaining each part in detail along the way. For this guide, we will be focusing on how the two most common methods (+rails server+ and Passenger) boot a Rails application. +This guide goes through every single file, class and method call that is +required to boot up the Ruby on Rails stack for a default Rails 4 application, explaining each part in detail along the way. For this guide, we will be focusing on how the two most common methods (+rails server+ and Passenger) boot a Rails application. NOTE: Paths in this guide are relative to Rails or a Rails application unless otherwise specified. -- cgit v1.2.3 From d4d87941cbf4d8204c8d3ac6f4a87c29e42445b0 Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Tue, 22 May 2012 08:35:49 -0700 Subject: [Guides] change rails bin section --- guides/source/initialization.textile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'guides') diff --git a/guides/source/initialization.textile b/guides/source/initialization.textile index 361045282a..5ffa62fd67 100644 --- a/guides/source/initialization.textile +++ b/guides/source/initialization.textile @@ -24,16 +24,15 @@ The actual +rails+ command is kept in _bin/rails_: #!/usr/bin/env ruby -begin - require "rails/cli" -rescue LoadError - railties_path = File.expand_path('../../railties/lib', __FILE__) +if File.exists?(File.join(File.expand_path('../../..', __FILE__), '.git')) + railties_path = File.expand_path('../../lib', __FILE__) $:.unshift(railties_path) - require "rails/cli" end +require "rails/cli" -This file will attempt to load +rails/cli+. If it cannot find it then +railties/lib+ is added to the load path (+$:+) before retrying. +This file will first attempt to push the +railties/lib+ directory if +present, and then require +rails/cli+. h4. +railties/lib/rails/cli.rb+ -- cgit v1.2.3 From 987a74da23b7ef28a9564f20a3bf87b26530fa2f Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Tue, 22 May 2012 08:43:14 -0700 Subject: [Guides] Review bin/rails section --- guides/source/initialization.textile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'guides') diff --git a/guides/source/initialization.textile b/guides/source/initialization.textile index 5ffa62fd67..a1420d3b6a 100644 --- a/guides/source/initialization.textile +++ b/guides/source/initialization.textile @@ -47,7 +47,7 @@ require 'rails/script_rails_loader' Rails::ScriptRailsLoader.exec_script_rails! require 'rails/ruby_version_check' -Signal.trap("INT") { puts; exit } +Signal.trap("INT") { puts; exit(1) } if ARGV.first == 'plugin' ARGV.shift @@ -57,7 +57,7 @@ else end -The +rbconfig+ file from the Ruby standard library provides us with the +RbConfig+ class which contains detailed information about the Ruby environment, including how Ruby was compiled. We can see this in use in +railties/lib/rails/script_rails_loader+. +The +rbconfig+ file from the Ruby standard library provides us with the +RbConfig+ class which contains detailed information about the Ruby environment, including how Ruby was compiled. We can see thisin use in +railties/lib/rails/script_rails_loader+. require 'pathname' @@ -121,6 +121,9 @@ exec RUBY, SCRIPT_RAILS, *ARGV if in_rails_application? This is effectively the same as running +ruby script/rails [arguments]+, where +[arguments]+ at this point in time is simply "server". +TIP: If you execute +script/rails+ directly from your Rails app you will +avoid executing the code that we just described. + h4. +script/rails+ This file is as follows: -- cgit v1.2.3 From ba55dd59ece04aa11bdb305dddfe4e975de9177a Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Tue, 22 May 2012 08:48:46 -0700 Subject: [Guides] Change bundler section --- guides/source/initialization.textile | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'guides') diff --git a/guides/source/initialization.textile b/guides/source/initialization.textile index a1420d3b6a..fdbee7b332 100644 --- a/guides/source/initialization.textile +++ b/guides/source/initialization.textile @@ -138,23 +138,23 @@ The +APP_PATH+ constant will be used later in +rails/commands+. The +config/boot h4. +config/boot.rb+ -+config/boot.rb+ contains this: ++config/boot.rb+ contains: # Set up gems listed in the Gemfile. -gemfile = File.expand_path('../../Gemfile', __FILE__) -begin - ENV['BUNDLE_GEMFILE'] = gemfile - require 'bundler' - Bundler.setup -rescue Bundler::GemNotFound => e - STDERR.puts e.message - STDERR.puts "Try running `bundle install`." - exit! -end if File.exist?(gemfile) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) -In a standard Rails application, there's a +Gemfile+ which declares all dependencies of the application. +config/boot.rb+ sets +ENV["BUNDLE_GEMFILE"]+ to the location of this file, then requires Bundler and calls +Bundler.setup+ which adds the dependencies of the application (including all the Rails parts) to the load path, making them available for the application to load. The gems that a Rails 3.1 application depends on are as follows: +In a standard Rails application, there's a +Gemfile+ which declares all +dependencies of the application. +config/boot.rb+ sets ++ENV['BUNDLE_GEMFILE']+ to the location of this file. If the Gemfile +exists, +bundler/setup+ is then required. + +The gems that a Rails 4 application depends on are as follows: + +TODO: change these when the Rails 4 release is near. * abstract (1.0.0) * actionmailer (3.1.0.beta) -- cgit v1.2.3 From 63f094bf2984127132589f5c93e6dabcad898b12 Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Tue, 22 May 2012 08:55:59 -0700 Subject: [Guides] Update rails commands section --- guides/source/initialization.textile | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'guides') diff --git a/guides/source/initialization.textile b/guides/source/initialization.textile index fdbee7b332..dc089bfb90 100644 --- a/guides/source/initialization.textile +++ b/guides/source/initialization.textile @@ -187,6 +187,8 @@ h4. +rails/commands.rb+ Once +config/boot.rb+ has finished, the next file that is required is +rails/commands+ which will execute a command based on the arguments passed in. In this case, the +ARGV+ array simply contains +server+ which is extracted into the +command+ variable using these lines: +ARGV << '--help' if ARGV.empty? + aliases = { "g" => "generate", "c" => "console", @@ -199,6 +201,9 @@ command = ARGV.shift command = aliases[command] || command +TIP: As you can see, an empty ARGV list will make Rails show the help +snippet. + If we used s rather than +server+, Rails will use the +aliases+ defined in the file and match them to their respective commands. With the +server+ command, Rails will run this code: -- cgit v1.2.3 From f09c84ca26a73304943421d473faa3ea808d18ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rory=20O=E2=80=99Kane?= Date: Tue, 22 May 2012 15:50:19 -0300 Subject: clarified how file naming affects load order of initializers --- guides/source/configuring.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/configuring.textile b/guides/source/configuring.textile index f114075cae..af46538bf5 100644 --- a/guides/source/configuring.textile +++ b/guides/source/configuring.textile @@ -585,7 +585,7 @@ After loading the framework and any gems in your application, Rails turns to loa NOTE: You can use subfolders to organize your initializers if you like, because Rails will look into the whole file hierarchy from the initializers folder on down. -TIP: If you have any ordering dependency in your initializers, you can control the load order by naming. For example, +01_critical.rb+ will be loaded before +02_normal.rb+. +TIP: If you have any ordering dependency in your initializers, you can control the load order through naming. Initializer files are loaded in alphabetical order by their path. For example, +01_critical.rb+ will be loaded before +02_normal.rb+. h3. Initialization events -- cgit v1.2.3 From 05a4d8b8597b7cc70ea79b087ee491ffaaf8f504 Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Wed, 23 May 2012 08:45:48 -0700 Subject: [Guides] Rewrite server start section --- guides/source/initialization.textile | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'guides') diff --git a/guides/source/initialization.textile b/guides/source/initialization.textile index dc089bfb90..78790a5e3c 100644 --- a/guides/source/initialization.textile +++ b/guides/source/initialization.textile @@ -370,8 +370,9 @@ This method is defined like this: def start + url = "#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}" puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}" - puts "=> Rails #{Rails.version} application starting in #{Rails.env} on http://#{options[:Host]}:#{options[:Port]}" + puts "=> Rails #{Rails.version} application starting in #{Rails.env} on #{url}" puts "=> Call with -d to detach" unless options[:daemonize] trap(:INT) { exit } puts "=> Ctrl-C to shutdown server" unless options[:daemonize] @@ -381,6 +382,15 @@ def start FileUtils.mkdir_p(Rails.root.join('tmp', dir_to_make)) end + unless options[:daemonize] + wrapped_app # touch the app so the logger is set up + + console = ActiveSupport::Logger.new($stdout) + console.formatter = Rails.logger.formatter + + Rails.logger.extend(ActiveSupport::Logger.broadcast(console)) + end + super ensure # The '-h' option calls exit before @options is set. @@ -389,7 +399,15 @@ ensure end -This is where the first output of the Rails initialization happens. This method creates a trap for +INT+ signals, so if you +CTRL+C+ the server, it will exit the process. As we can see from the code here, it will create the +tmp/cache+, +tmp/pids+, +tmp/sessions+ and +tmp/sockets+ directories if they don't already exist prior to calling +super+. The +super+ method will call +Rack::Server.start+ which begins its definition like this: +This is where the first output of the Rails initialization happens. This +method creates a trap for +INT+ signals, so if you +CTRL-C+ the server, +it will exit the process. As we can see from the code here, it will +create the +tmp/cache+, +tmp/pids+, +tmp/sessions+ and +tmp/sockets+ +directories. It then calls +wrapped_app+ which is responsible for +creating the Rack app, before creating and assignig an +instance of +ActiveSupport::Logger+. + +The +super+ method will call +Rack::Server.start+ which begins its definition like this: def start -- cgit v1.2.3 From 13612ae5014a98cdbb86d703b50cbdf66adbcb57 Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Wed, 23 May 2012 08:53:08 -0700 Subject: [Guides] Rewrite server start section --- guides/source/initialization.textile | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'guides') diff --git a/guides/source/initialization.textile b/guides/source/initialization.textile index 78790a5e3c..5ce8173e85 100644 --- a/guides/source/initialization.textile +++ b/guides/source/initialization.textile @@ -410,7 +410,7 @@ instance of +ActiveSupport::Logger+. The +super+ method will call +Rack::Server.start+ which begins its definition like this: -def start +def start &blk if options[:warn] $-w = true end @@ -430,22 +430,37 @@ def start pp wrapped_app pp app end -end - -In a Rails application, these options are not set at all and therefore aren't used at all. The first line of code that's executed in this method is a call to this method: + check_pid! if options[:pid] - -wrapped_app + # Touch the wrapped app, so that the config.ru is loaded before + # daemonization (i.e. before chdir, etc). + wrapped_app + + daemonize_app if options[:daemonize] + + write_pid if options[:pid] + + trap(:INT) do + if server.respond_to?(:shutdown) + server.shutdown + else + exit + end + end + + server.run wrapped_app, options, &blk +end -This method calls another method: +The interesting part for a Rails app is the last line, +server.run+. Here we encounter the +wrapped_app+ method again, which this time +we're going to explore more. @wrapped_app ||= build_app app -Then the +app+ method here is defined like so: +The +app+ method here is defined like so: def app -- cgit v1.2.3 From 07f73219c0aed3d633d9d9f809f45a1758a718ef Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Wed, 23 May 2012 09:01:21 -0700 Subject: [Guides] Fix sample code --- guides/source/initialization.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/initialization.textile b/guides/source/initialization.textile index 5ce8173e85..12b2eb7458 100644 --- a/guides/source/initialization.textile +++ b/guides/source/initialization.textile @@ -482,7 +482,7 @@ The +options[:config]+ value defaults to +config.ru+ which contains this: # This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) -run YourApp::Application +run <%= app_const %> -- cgit v1.2.3 From d31b765628db6aa9ffa9a92bfa2401067e92bb6c Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 23 May 2012 22:49:39 +0530 Subject: Revert "Remove Obsolute root specifiying short syntax" This reverts commit feaa7b35a0214240eb34780ab51b843571e74904. Reason: Incorrect change. That's a Rails 4 feature and will not obviously work in 3.2.3. [ci skip] --- guides/source/routing.textile | 1 + 1 file changed, 1 insertion(+) (limited to 'guides') diff --git a/guides/source/routing.textile b/guides/source/routing.textile index 6081651364..4a50edbb15 100644 --- a/guides/source/routing.textile +++ b/guides/source/routing.textile @@ -629,6 +629,7 @@ You can specify what Rails should route +"/"+ to with the +root+ method: root :to => 'pages#main' +root 'pages#main' # shortcut for the above You should put the +root+ route at the top of the file, because it is the most popular route and should be matched first. You also need to delete the +public/index.html+ file for the root route to take effect. -- cgit v1.2.3