From ae3965b4752285991acb5ac8147fc9f4a88eea6d Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sun, 9 Sep 2012 23:31:18 -0500 Subject: fix punctuation in Getting Started prologue [ci skip] --- guides/source/getting_started.textile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'guides/source') diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile index 226c3dce14..af6768ac14 100644 --- a/guides/source/getting_started.textile +++ b/guides/source/getting_started.textile @@ -3,10 +3,11 @@ h2. Getting Started with Rails This guide covers getting up and running with Ruby on Rails. After reading it, you should be familiar with: -* Installing Rails, creating a new Rails application, and connecting your application to a database -* The general layout of a Rails application -* The basic principles of MVC (Model, View Controller) and RESTful design -* How to quickly generate the starting pieces of a Rails application +* Installing Rails, creating a new Rails application, and connecting your + application to a database. +* The general layout of a Rails application. +* The basic principles of MVC (Model, View, Controller) and RESTful design. +* How to quickly generate the starting pieces of a Rails application. endprologue. -- cgit v1.2.3 From 6639ef8b5a2d0655a84888f3a227cbd33b92e175 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Tue, 11 Sep 2012 22:52:58 +0100 Subject: More concise flash output --- guides/source/action_controller_overview.textile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'guides/source') diff --git a/guides/source/action_controller_overview.textile b/guides/source/action_controller_overview.textile index 1d43b44391..5806faed2a 100644 --- a/guides/source/action_controller_overview.textile +++ b/guides/source/action_controller_overview.textile @@ -308,12 +308,10 @@ The +destroy+ action redirects to the application's +root_url+, where the messag - <% if flash[:notice] %> -

<%= flash[:notice] %>

- <% end %> - <% if flash[:alert] %> -

<%= flash[:alert] %>

- <% end %> + <% flash.each do |name, msg| -%> + <%= content_tag :div, msg, class: name %> + <% end -%> + -- cgit v1.2.3 From 1affc30cd5a3ed91beb41014e203795c78a0db8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Corcuera?= Date: Wed, 12 Sep 2012 10:04:29 -0500 Subject: Fix typo [ci skip] --- guides/source/active_record_validations_callbacks.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/active_record_validations_callbacks.textile b/guides/source/active_record_validations_callbacks.textile index b866337e3f..3f6fb7606f 100644 --- a/guides/source/active_record_validations_callbacks.textile +++ b/guides/source/active_record_validations_callbacks.textile @@ -48,7 +48,7 @@ We can see how it works by looking at some +rails console+ output: >> p = Person.new(:name => "John Doe") -=> # +=> # >> p.new_record? => true >> p.save -- cgit v1.2.3 From 961355a9f34a9cdb3001d8a4b69741408145ebb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Corcuera?= Date: Wed, 12 Sep 2012 13:29:42 -0500 Subject: Update action_controller_overview.textile to ruby 1.9 syntax [ci skip] --- guides/source/action_controller_overview.textile | 68 +++++++++++++----------- 1 file changed, 37 insertions(+), 31 deletions(-) (limited to 'guides/source') diff --git a/guides/source/action_controller_overview.textile b/guides/source/action_controller_overview.textile index 5806faed2a..a292d56fd8 100644 --- a/guides/source/action_controller_overview.textile +++ b/guides/source/action_controller_overview.textile @@ -77,7 +77,7 @@ class ClientsController < ActionController::Base else # This line overrides the default rendering behavior, which # would have been to render the "create" view. - render :action => "new" + render action: "new" end end end @@ -106,7 +106,13 @@ To send a hash you include the key name inside the brackets: -When this form is submitted, the value of +params[:client]+ will be {"name" => "Acme", "phone" => "12345", "address" => {"postcode" => "12345", "city" => "Carrot City"}}. Note the nested hash in +params[:client][:address]+. +When this form is submitted, the value of +params[:client]+ will be: + + +{ name: "Acme", phone: "12345", address: { postcode: "12345", city: "Carrot City" } } + + +Note the nested hash in +params[:client][:address]+. Note that the +params+ hash is actually an instance of +HashWithIndifferentAccess+ from Active Support, which acts like a hash that lets you use symbols and strings interchangeably as keys. @@ -120,7 +126,7 @@ So for example, if you are sending this JSON parameter: { "company": { "name": "acme", "address": "123 Carrot Street" } } -You'll get params[:company] as { :name => "acme", "address" => "123 Carrot Street" }. +You'll get params[:company] as { name: "acme", address: "123 Carrot Street" }. Also, if you've turned on +config.wrap_parameters+ in your initializer or calling +wrap_parameters+ in your controller, you can safely omit the root element in the JSON/XML parameter. The parameters will be cloned and wrapped in the key according to your controller's name by default. So the above parameter can be written as: @@ -131,7 +137,7 @@ Also, if you've turned on +config.wrap_parameters+ in your initializer or callin And assume that you're sending the data to +CompaniesController+, it would then be wrapped in +:company+ key like this: -{ :name => "acme", :address => "123 Carrot Street", :company => { :name => "acme", :address => "123 Carrot Street" }} +{ name: "acme", address: "123 Carrot Street", company: { name: "acme", address: "123 Carrot Street" } } You can customize the name of the key or specific parameters you want to wrap by consulting the "API documentation":http://api.rubyonrails.org/classes/ActionController/ParamsWrapper.html @@ -141,7 +147,7 @@ h4. Routing Parameters The +params+ hash will always contain the +:controller+ and +:action+ keys, but you should use the methods +controller_name+ and +action_name+ instead to access these values. Any other parameters defined by the routing, such as +:id+ will also be available. As an example, consider a listing of clients where the list can show either active or inactive clients. We can add a route which captures the +:status+ parameter in a "pretty" URL: -match '/clients/:status' => 'clients#index', :foo => "bar" +match '/clients/:status' => 'clients#index', foo: 'bar' In this case, when a user opens the URL +/clients/active+, +params[:status]+ will be set to "active". When this route is used, +params[:foo]+ will also be set to "bar" just like it was passed in the query string. In the same way +params[:action]+ will contain "index". @@ -153,7 +159,7 @@ You can set global default parameters for URL generation by defining a method ca class ApplicationController < ActionController::Base def default_url_options - {:locale => I18n.locale} + { locale: I18n.locale } end end @@ -196,7 +202,7 @@ Rails sets up a session key (the name of the cookie) when signing the session da # Be sure to restart your server when you modify this file. -YourApp::Application.config.session_store :cookie_store, :key => '_your_app_session' +YourApp::Application.config.session_store :cookie_store, key: '_your_app_session' You can also pass a +:domain+ key and specify the domain name for the cookie: @@ -204,7 +210,7 @@ You can also pass a +:domain+ key and specify the domain name for the cookie: # Be sure to restart your server when you modify this file. -YourApp::Application.config.session_store :cookie_store, :key => '_your_app_session', :domain => ".example.com" +YourApp::Application.config.session_store :cookie_store, key: '_your_app_session', domain: ".example.com" Rails sets up (for the CookieStore) a secret key used for signing the session data. This can be changed in +config/initializers/secret_token.rb+ @@ -297,9 +303,9 @@ end Note that it is also possible to assign a flash message as part of the redirection. You can assign +:notice+, +:alert+ or the general purpose +:flash+: -redirect_to root_url, :notice => "You have successfully logged out." -redirect_to root_url, :alert => "You're stuck here!" -redirect_to root_url, :flash => { :referral_code => 1234 } +redirect_to root_url, notice: "You have successfully logged out." +redirect_to root_url, alert: "You're stuck here!" +redirect_to root_url, flash: { referral_code: 1234 } The +destroy+ action redirects to the application's +root_url+, where the message will be displayed. Note that it's entirely up to the next action to decide what, if anything, it will do with what the previous action put in the flash. It's conventional to display any error alerts or notices from the flash in the application's layout: @@ -359,7 +365,7 @@ class ClientsController < ApplicationController # ... else flash.now[:error] = "Could not save client" - render :action => "new" + render action: "new" end end end @@ -373,7 +379,7 @@ Your application can store small amounts of data on the client -- called cookies class CommentsController < ApplicationController def new # Auto-fill the commenter's name if it has been stored in a cookie - @comment = Comment.new(:name => cookies[:commenter_name]) + @comment = Comment.new(name: cookies[:commenter_name]) end def create @@ -389,7 +395,7 @@ class CommentsController < ApplicationController end redirect_to @comment.article else - render :action => "new" + render action: "new" end end end @@ -407,14 +413,14 @@ class UsersController < ApplicationController @users = User.all respond_to do |format| format.html # index.html.erb - format.xml { render :xml => @users} - format.json { render :json => @users} + format.xml { render xml: @users} + format.json { render json: @users} end end end -Notice that in the above case code is render :xml => @users and not render :xml => @users.to_xml. That is because if the input is not string then rails automatically invokes +to_xml+ . +Notice that in the above case code is render xml: @users and not render xml: @users.to_xml. That is because if the input is not string then rails automatically invokes +to_xml+ . h3. Filters @@ -455,7 +461,7 @@ In this example the filter is added to +ApplicationController+ and thus all cont class LoginsController < ApplicationController - skip_before_filter :require_login, :only => [:new, :create] + skip_before_filter :require_login, only: [:new, :create] end @@ -473,7 +479,7 @@ For example, in a website where changes have an approval workflow an administrat class ChangesController < ActionController::Base - around_filter :wrap_in_transaction, :only => :show + around_filter :wrap_in_transaction, only: :show private @@ -620,7 +626,7 @@ HTTP basic authentication is an authentication scheme that is supported by the m class AdminController < ApplicationController - http_basic_authenticate_with :name => "humbaba", :password => "5baa61e4" + http_basic_authenticate_with name: "humbaba", password: "5baa61e4" end @@ -662,15 +668,15 @@ class ClientsController < ApplicationController def download_pdf client = Client.find(params[:id]) send_data generate_pdf(client), - :filename => "#{client.name}.pdf", - :type => "application/pdf" + filename: "#{client.name}.pdf", + type: "application/pdf" end private def generate_pdf(client) Prawn::Document.new do - text client.name, :align => :center + text client.name, align: :center text "Address: #{client.address}" text "Email: #{client.email}" end.render @@ -690,8 +696,8 @@ class ClientsController < ApplicationController def download_pdf client = Client.find(params[:id]) send_file("#{Rails.root}/files/clients/#{client.id}.pdf", - :filename => "#{client.name}.pdf", - :type => "application/pdf") + filename: "#{client.name}.pdf", + type: "application/pdf") end end @@ -716,7 +722,7 @@ class ClientsController < ApplicationController respond_to do |format| format.html - format.pdf { render :pdf => generate_pdf(@client) } + format.pdf { render pdf: generate_pdf(@client) } end end end @@ -764,12 +770,12 @@ Here's how you can use +rescue_from+ to intercept all +ActiveRecord::RecordNotFo class ApplicationController < ActionController::Base - rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found + rescue_from ActiveRecord::RecordNotFound, with: :record_not_found private def record_not_found - render :text => "404 Not Found", :status => 404 + render text: "404 Not Found", status: 404 end end @@ -778,7 +784,7 @@ Of course, this example is anything but elaborate and doesn't improve on the def class ApplicationController < ActionController::Base - rescue_from User::NotAuthorized, :with => :user_not_authorized + rescue_from User::NotAuthorized, with: :user_not_authorized private @@ -822,9 +828,9 @@ Just like the filter, you could also passing +:only+ and +:except+ to enforce th class DinnerController - force_ssl :only => :cheeseburger + force_ssl only: :cheeseburger # or - force_ssl :except => :cheeseburger + force_ssl except: :cheeseburger end -- cgit v1.2.3 From 744b8e0f35db6acd738f0b0619765facb9c546f1 Mon Sep 17 00:00:00 2001 From: Simon Hengel Date: Sun, 16 Sep 2012 21:12:07 +0200 Subject: Update "Getting Started" guide --- guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile index af6768ac14..3760decef7 100644 --- a/guides/source/getting_started.textile +++ b/guides/source/getting_started.textile @@ -91,7 +91,7 @@ To verify that you have everything installed correctly, you should be able to ru $ rails --version -If it says something like "Rails 3.2.3" you are ready to continue. +If it says something like "Rails 3.2.8" you are ready to continue. h4. Creating the Blog Application -- cgit v1.2.3 From e9acafd984ef64b44a8f0c998acaddbdce1dd6fb Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 17 Sep 2012 22:03:34 +0300 Subject: Add note about inheretance and poly associations. This note came about due to discussion in #6786. --- guides/source/association_basics.textile | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'guides/source') diff --git a/guides/source/association_basics.textile b/guides/source/association_basics.textile index 151752eee9..e991a309ff 100644 --- a/guides/source/association_basics.textile +++ b/guides/source/association_basics.textile @@ -338,6 +338,10 @@ end !images/polymorphic.png(Polymorphic Association Diagram)! +Polymorphic associations can get tricky with inheritance. If you need +an inheritance relationship in your ActiveRecord models, you should use +Single Table Inheritance instead. + h4. Self Joins In designing a data model, you will sometimes find a model that should have a relation to itself. For example, you may want to store all employees in a single database model, but be able to trace relationships such as between manager and subordinates. This situation can be modeled with self-joining associations: -- cgit v1.2.3 From 143675189ef3f5518c3a2a705ab07ab1451e614e Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 18 Sep 2012 03:26:07 +0300 Subject: Expanded note about poly associations. Now with example! --- guides/source/association_basics.textile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'guides/source') diff --git a/guides/source/association_basics.textile b/guides/source/association_basics.textile index e991a309ff..3ee87f642a 100644 --- a/guides/source/association_basics.textile +++ b/guides/source/association_basics.textile @@ -338,9 +338,18 @@ end !images/polymorphic.png(Polymorphic Association Diagram)! -Polymorphic associations can get tricky with inheritance. If you need -an inheritance relationship in your ActiveRecord models, you should use -Single Table Inheritance instead. +Polymorphic associations can get tricky when combined with Single Table +Inheritance. For example, given the models Parent, Child (inheriting from +Parent) and Polymorphic (with poly_type and poly_id used to reference other +objects), if a new Polymorphic object was to point to a object of type Child, +the "poly_type" field would contain "Parent" instead of "Child". Assuming the +child object had an id of 1, when querying the Polymophic model, the query +would have to be: Polymorphic.find_by_poly_type_and_poly_id("Parent", 1) as +opposed to Polymorphic.find_by_poly_type_and_poly_id("Child", 1). + +The benefit is that using "Parent" for poly_type allows you to query the +polymorphic model for both child and parent objects instead of having to query +individually for each child class. h4. Self Joins -- cgit v1.2.3 From 166409337a6bf8c1d57ef8fa8cc8e364f17bb468 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 18 Sep 2012 20:47:54 +0300 Subject: Update 3.0 -> 3.1 session information. Fixes #7685 --- guides/source/upgrading_ruby_on_rails.textile | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'guides/source') diff --git a/guides/source/upgrading_ruby_on_rails.textile b/guides/source/upgrading_ruby_on_rails.textile index b750cc2ffb..f2fd86127f 100644 --- a/guides/source/upgrading_ruby_on_rails.textile +++ b/guides/source/upgrading_ruby_on_rails.textile @@ -228,3 +228,16 @@ ActiveSupport.on_load(:active_record) do self.include_root_in_json = false end + +h4(#config_session3_1). config/initializers/session_store.rb + +You need to change your session key to something new, or remove all sessions: + + +# in config/initializers/session_store.rb +AppName::Application.config.session_store :cookie_store, :key => 'SOMETHINGNEW' + + +or + +$ rake db:sessions:clear -- cgit v1.2.3 From deed3f99754bdeca11dfbc5ba674c939bd70de13 Mon Sep 17 00:00:00 2001 From: Przemek Hocke Date: Fri, 21 Sep 2012 03:40:49 +0200 Subject: fix a small typo --- guides/source/command_line.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/command_line.textile b/guides/source/command_line.textile index 39b75c2781..a8df2285c1 100644 --- a/guides/source/command_line.textile +++ b/guides/source/command_line.textile @@ -490,7 +490,7 @@ Each task should be defined in next format (dependencies are optional): desc "I am short, but comprehensive description for my cool task" task :task_name => [:prerequisite_task, :another_task_we_depend_on] do - # All your magick here + # All your magic here # Any valid Ruby code is allowed end -- cgit v1.2.3 From 649a95b8af3aa42183fe0096ccf2a54ec1c13656 Mon Sep 17 00:00:00 2001 From: Przemek Hocke Date: Fri, 21 Sep 2012 03:46:14 +0200 Subject: fix two typos in the associations guide --- guides/source/association_basics.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/association_basics.textile b/guides/source/association_basics.textile index 3ee87f642a..e3da9b7e45 100644 --- a/guides/source/association_basics.textile +++ b/guides/source/association_basics.textile @@ -985,7 +985,7 @@ h6(#has_one-dependent). +:dependent+ Controls what happens to the associated object when its owner is destroyed: * +:destroy+ causes the associated object to also be destroyed -* +:delete+ causes the asssociated object to be deleted directly from the database (so callbacks will not execute) +* +:delete+ causes the associated object to be deleted directly from the database (so callbacks will not execute) * +:nullify+ causes the foreign key to be set to +NULL+. Callbacks are not executed. * +:restrict_with_exception+ causes an exception to be raised if there is an associated record * +:restrict_with_error+ causes an error to be added to the owner if there is an associated object @@ -1283,7 +1283,7 @@ The collection.create method returns a new object of the assoc h5. Options for +has_many+ -While Rails uses intelligent defaults that will work well in most situations, there may be times when you want to customize the behavior of the +has_many+ association reference. Such customizations can easily be accomplished by passing options when you create the association. For example, this assocation uses two such options: +While Rails uses intelligent defaults that will work well in most situations, there may be times when you want to customize the behavior of the +has_many+ association reference. Such customizations can easily be accomplished by passing options when you create the association. For example, this association uses two such options: class Customer < ActiveRecord::Base -- cgit v1.2.3 From fca6c0f03c656d25af9b58f74307b27a69e7f5ce Mon Sep 17 00:00:00 2001 From: Przemek Hocke Date: Fri, 21 Sep 2012 03:48:17 +0200 Subject: Add missing "m" char --- guides/source/ajax_on_rails.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/ajax_on_rails.textile b/guides/source/ajax_on_rails.textile index 67b0c9f0d3..15301945ce 100644 --- a/guides/source/ajax_on_rails.textile +++ b/guides/source/ajax_on_rails.textile @@ -41,7 +41,7 @@ that contain text. h4. Standard HTML communication vs AJAX -In regular HTML comunications, when you click on a link, the browser makes an HTTP +In regular HTML communications, when you click on a link, the browser makes an HTTP +GET+ request, the server responds with a new HTML document that the browsers renders and then replaces the previous one. The same thing happens when you click a button to submit a form, except that you make and HTTP +POST+ request, but you also get a new -- cgit v1.2.3 From 79942d426d28bcb726c1aedcae00fb07c34ae766 Mon Sep 17 00:00:00 2001 From: Przemek Hocke Date: Fri, 21 Sep 2012 03:49:26 +0200 Subject: correct a typo --- guides/source/active_support_core_extensions.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile index 8748817eb8..aa4ad2bbd7 100644 --- a/guides/source/active_support_core_extensions.textile +++ b/guides/source/active_support_core_extensions.textile @@ -1349,7 +1349,7 @@ The second argument, +indent_string+, specifies which indent string to use. The "foo".indent(2, "\t") # => "\t\tfoo" -While +indent_string+ is tipically one space or tab, it may be any string. +While +indent_string+ is typically one space or tab, it may be any string. The third argument, +indent_empty_lines+, is a flag that says whether empty lines should be indented. Default is false. -- cgit v1.2.3