diff options
Diffstat (limited to 'railties')
9 files changed, 48 insertions, 54 deletions
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 535a048b3b..788c243d2a 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -20,7 +20,7 @@ Thus, after a simple require like: require 'active_support' </ruby> -objects do not even respond to +blank?+, let's see how to load its definition. +objects do not even respond to +blank?+. Let's see how to load its definition. h5. Cherry-picking a Definition @@ -42,7 +42,7 @@ h5. Loading Grouped Core Extensions The next level is to simply load all extensions to +Object+. As a rule of thumb, extensions to +SomeClass+ are available in one shot by loading +active_support/core_ext/some_class+. -Thus, if that would do, to have +blank?+ available we could just load all extensions to +Object+: +Thus, to load all extensions to +Object+ (including +blank?+): <ruby> require 'active_support/core_ext/object' @@ -432,7 +432,7 @@ h4. +require_library_or_gem+ The convenience method +require_library_or_gem+ tries to load its argument with a regular +require+ first. If it fails loads +rubygems+ and tries again. -If the first attempt is a failure and +rubygems+ can't be loaded the method raises +LoadError+. On the other hand, if +rubygems+ is available but the argument is not loadable as a gem, the method gives up and +LoadError+ is also raised. +If the first attempt is a failure and +rubygems+ can't be loaded the method raises +LoadError+. A +LoadError+ is also raised if +rubygems+ is available but the argument is not loadable as a gem. For example, that's the way the MySQL adapter loads the MySQL library: @@ -503,7 +503,7 @@ Model attributes have a reader, a writer, and a predicate. You can alias a model <ruby> class User < ActiveRecord::Base # let me refer to the email column as "login", - # much meaningful for authentication code + # possibly meaningful for authentication code alias_attribute :login, :email end </ruby> diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index 337ef52d3b..8b37543342 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -809,6 +809,12 @@ That does not mean you're stuck with these limitations, though. The Ruby I18n ge I18n.backend = Globalize::Backend::Static.new </ruby> +You can also use the Chain backend to chain multiple backends together. This is useful when you want to use standard translations with a Simple backend but store custom application translations in a database or other backends. For example, you could use the ActiveRecord backend and fall back to the (default) Simple backend: + +<ruby> +I18n.backend = I18n::Backend::Chain.new(I18n::Backend::ActiveRecord.new, I18n.backend) +</ruby> + h4. Using Different Exception Handlers The I18n API defines the following exceptions that will be raised by backends when the corresponding unexpected conditions occur: diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index fe400d3358..8442a6e257 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -1006,11 +1006,13 @@ h5. Partial Layouts A partial can use its own layout file, just as a view can use a layout. For example, you might call a partial like this: <erb> -<%= render "link_area", :layout => "graybar" %> +<%= render :partial => "link_area", :layout => "graybar" %> </erb> This would look for a partial named +_link_area.html.erb+ and render it using the layout +_graybar.html.erb+. Note that layouts for partials follow the same leading-underscore naming as regular partials, and are placed in the same folder with the partial that they belong to (not in the master +layouts+ folder). +Also note that explicitly specifying +:partial+ is required when passing additional options such as +:layout+. + h5. Passing Local Variables You can also pass local variables into partials, making them even more powerful and flexible. For example, you can use this technique to reduce duplication between new and edit pages, while still keeping a bit of distinct content: diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile index 341525a75c..cd0a8fa384 100644 --- a/railties/guides/source/performance_testing.textile +++ b/railties/guides/source/performance_testing.textile @@ -316,16 +316,16 @@ Compile Ruby and apply this "GC Patch":http://rubyforge.org/tracker/download.php h5. Download and Extract <shell> -[lifo@null ~]$ mkdir rubygc -[lifo@null ~]$ wget <download the latest stable ruby from ftp://ftp.ruby-lang.org/pub/ruby> -[lifo@null ~]$ tar -xzvf <ruby-version.tar.gz> -[lifo@null ~]$ cd <ruby-version> +$ mkdir rubygc +$ wget <download the latest stable ruby from ftp://ftp.ruby-lang.org/pub/ruby> +$ tar -xzvf <ruby-version.tar.gz> +$ cd <ruby-version> </shell> h5. Apply the Patch <shell> -[lifo@null ruby-version]$ curl http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch | patch -p0 +$ curl http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch | patch -p0 </shell> h5. Configure and Install @@ -333,8 +333,8 @@ h5. Configure and Install The following will install ruby in your home directory's +/rubygc+ directory. Make sure to replace +<homedir>+ with a full patch to your actual home directory. <shell> -[lifo@null ruby-version]$ ./configure --prefix=/<homedir>/rubygc -[lifo@null ruby-version]$ make && make install +$ ./configure --prefix=/<homedir>/rubygc +$ make && make install </shell> h5. Prepare Aliases @@ -364,8 +364,8 @@ Additionally, install the following gems: If installing +mysql+ fails, you can try to install it manually: <shell> -[lifo@null mysql]$ gcruby extconf.rb --with-mysql-config -[lifo@null mysql]$ make && make install +$ gcruby extconf.rb --with-mysql-config +$ make && make install </shell> And you're ready to go. Don't forget to use +gcruby+ and +gcrake+ aliases when running the performance tests. diff --git a/railties/guides/source/rails_application_templates.textile b/railties/guides/source/rails_application_templates.textile index 8f87b4cd58..8e51f9e23b 100644 --- a/railties/guides/source/rails_application_templates.textile +++ b/railties/guides/source/rails_application_templates.textile @@ -198,7 +198,7 @@ route "root :to => 'person#index'" h4. inside(dir) -I have my edge rails lying at +~/commit-rails/rails+. So every time i have to manually symlink edge from my new app. But now : +Enables you to run a command from the given directory. For example, if you have a copy of edge rails that you wish to symlink from your new apps, you can do this: <ruby> inside('vendor') do @@ -206,8 +206,6 @@ inside('vendor') do end </ruby> -So +inside()+ runs the command from the given directory. - h4. ask(question) +ask()+ gives you a chance to get some feedback from the user and use it in your templates. Lets say you want your user to name the new shiny library you’re adding : diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile index c1b91da7a8..b1db2942dd 100644 --- a/railties/guides/source/rails_on_rack.textile +++ b/railties/guides/source/rails_on_rack.textile @@ -63,13 +63,13 @@ run ActionController::Dispatcher.new And start the server: <shell> -[lifo@null application]$ rackup config.ru +$ rackup config.ru </shell> To find out more about different +rackup+ options: <shell> -[lifo@null application]$ rackup --help +$ rackup --help </shell> h3. Action Controller Middleware Stack diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile index 7f303c3565..5613156245 100644 --- a/railties/guides/source/security.textile +++ b/railties/guides/source/security.textile @@ -240,7 +240,7 @@ There are many other possibilities, including Ajax to attack the victim in the b protect_from_forgery :secret => "123456789012345678901234567890..." </ruby> -This will automatically include a security token, calculated from the current session and the server-side secret, in all forms and Ajax requests generated by Rails. You won't need the secret, if you use CookieStorage as session storage. It will raise an ActionController::InvalidAuthenticityToken error, if the security token doesn't match what was expected. +This will automatically include a security token, calculated from the current session and the server-side secret, in all forms and Ajax requests generated by Rails. You won't need the secret, if you use CookieStorage as session storage. If the security token doesn't match what was expected, the session will be reset. *Note:* In Rails versions prior to 3.0.4, this raised an <tt>ActionController::InvalidAuthenticityToken</tt> error. Note that _(highlight)cross-site scripting (XSS) vulnerabilities bypass all CSRF protections_. XSS gives the attacker access to all elements on a page, so he can read the CSRF security token from a form or directly submit the form. Read <a href="#cross-site-scripting-xss">more about XSS</a> later. diff --git a/railties/lib/rails/generators/rails/app/templates/public/javascripts/jquery.js b/railties/lib/rails/generators/rails/app/templates/public/javascripts/jquery.js index 5c99a8d4a8..aa3a4f34fd 100644 --- a/railties/lib/rails/generators/rails/app/templates/public/javascripts/jquery.js +++ b/railties/lib/rails/generators/rails/app/templates/public/javascripts/jquery.js @@ -2136,7 +2136,7 @@ jQuery.event = { eventHandle = elemData.handle; if ( typeof events === "function" ) { - // On plain objects events is a fn that holds the the data + // On plain objects events is a fn that holds the data // which prevents this data from being JSON serialized // the function does not need to be called, it just contains the data eventHandle = events.handle; diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 030a838dc1..7fca565124 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -3,55 +3,43 @@ require 'rails/configuration' require 'active_support/inflector' module Rails - # Railtie is the core of the Rails Framework and provides several hooks to extend + # Railtie is the core of the Rails framework and provides several hooks to extend # Rails and/or modify the initialization process. # # Every major component of Rails (Action Mailer, Action Controller, - # Action View, Active Record and Active Resource) are all Railties, so each of - # them is responsible to set their own initialization. This makes, for example, - # Rails absent of any Active Record hook, allowing any other ORM framework to hook in. + # Action View, Active Record and Active Resource) is a Railtie. Each of + # them is responsible for their own initialization. This makes Rails itself + # absent of any component hooks, allowing other components to be used in + # place of any of the Rails defaults. # # Developing a Rails extension does _not_ require any implementation of # Railtie, but if you need to interact with the Rails framework during - # or after boot, then Railtie is what you need to do that interaction. + # or after boot, then Railtie is needed. # - # For example, the following would need you to implement Railtie in your - # plugin: + # For example, an extension doing any of the following would require Railtie: # # * creating initializers - # * configuring a Rails framework or the Application, like setting a generator - # * adding Rails config.* keys to the environment - # * setting up a subscriber to the Rails +ActiveSupport::Notifications+ - # * adding rake tasks into rails + # * configuring a Rails framework for the application, like setting a generator + # * adding config.* keys to the environment + # * setting up a subscriber with ActiveSupport::Notifications + # * adding rake tasks # # == Creating your Railtie # - # Implementing Railtie in your Rails extension is done by creating a class - # Railtie that has your extension name and making sure that this gets loaded - # during boot time of the Rails stack. + # To extend Rails using Railtie, create a Railtie class which inherits + # from Rails::Railtie within your extension's namespace. This class must be + # loaded during the Rails boot process. # - # You can do this however you wish, but here is an example if you want to provide - # it for a gem that can be used with or without Rails: + # The following example demonstrates an extension which can be used with or without Rails. # - # * Create a file (say, lib/my_gem/railtie.rb) which contains class Railtie inheriting from - # Rails::Railtie and is namespaced to your gem: - # - # # lib/my_gem/railtie.rb - # module MyGem - # class Railtie < Rails::Railtie - # end + # # lib/my_gem/railtie.rb + # module MyGem + # class Railtie < Rails::Railtie # end + # end # - # * Require your own gem as well as rails in this file: - # - # # lib/my_gem/railtie.rb - # require 'my_gem' - # require 'rails' - # - # module MyGem - # class Railtie < Rails::Railtie - # end - # end + # # lib/my_gem.rb + # require 'my_gem/railtie' if defined?(Rails) # # == Initializers # |