From b2deeabffb542bb1683571db4f1a69a3426f838f Mon Sep 17 00:00:00 2001 From: mhutchin Date: Sat, 8 Oct 2011 01:58:57 -0700 Subject: Correct stylesheet filename and remove reference to old stylesheet compilation location --- railties/guides/source/active_record_validations_callbacks.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 781b9001b6..2f78f1d0c8 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -880,7 +880,7 @@ The selectors used to customize the style of error messages are: * +#error_explanation p+ - Style for the paragraph holding the message that appears right below the header of the +div+ element. * +#error_explanation ul li+ - Style for the list items with individual error messages. -If scaffolding was used, file +app/assets/stylesheets/scaffold.css.scss+ (which later compiles to +app/assets/stylesheets/scaffold.css+), will have been generated automatically. This file defines the red-based styles you saw in the examples above. +If scaffolding was used, file +app/assets/stylesheets/scaffolds.css.scss+ will have been generated automatically. This file defines the red-based styles you saw in the examples above. The name of the class and the id can be changed with the +:class+ and +:id+ options, accepted by both helpers. -- cgit v1.2.3 From 62c03816e8b034ad0265548fe599667af6de5e87 Mon Sep 17 00:00:00 2001 From: mhutchin Date: Sat, 8 Oct 2011 03:59:13 -0700 Subject: copy editing "updated the ajax_on_rails.textile for rails3" --- railties/guides/source/active_record_validations_callbacks.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 2f78f1d0c8..665e7f9ccc 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -1162,7 +1162,7 @@ class PictureFile < ActiveRecord::Base end -Note that we needed to instantiate a new +PictureFileCallbacks+ object, since we declared our callback as an instance method. This is particularly useful if the callbacks make use of the state of instantiated object. Often, however, it will make more sense to declare the callbacks as class methods: +Note that we needed to instantiate a new +PictureFileCallbacks+ object, since we declared our callback as an instance method. This is particularly useful if the callbacks make use of the state of the instantiated object. Often, however, it will make more sense to declare the callbacks as class methods: class PictureFileCallbacks -- cgit v1.2.3 From 6a5eeab3cde28f0faf187b681fde4e52a96a1268 Mon Sep 17 00:00:00 2001 From: "Karunakar (Ruby)" Date: Sun, 9 Oct 2011 00:03:12 +0530 Subject: Revert "Revert "updated the ajax_on_rails.textile for rails3" because of invalid git user" This reverts commit 5d2ffbb992b4ab875a121761fc0cf14dcaa12033. --- railties/guides/source/ajax_on_rails.textile | 69 ++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile index 29d4fae888..b5d4fb10f8 100644 --- a/railties/guides/source/ajax_on_rails.textile +++ b/railties/guides/source/ajax_on_rails.textile @@ -3,7 +3,7 @@ h2. AJAX on Rails This guide covers the built-in Ajax/JavaScript functionality of Rails (and more); it will enable you to create rich and dynamic AJAX applications with ease! We will cover the following topics: * Quick introduction to AJAX and related technologies -* Handling JavaScript the Rails way: Rails helpers, Prototype and script.aculo.us +* Unobtrusive JavaScript helpers with drivers for Prototype, jQuery, and more coming (end of inline JS) * Testing JavaScript functionality endprologue. @@ -26,13 +26,74 @@ How do 'standard' and AJAX requests differ, why does this matter for understandi h3. Built-in Rails Helpers -Rails' JavaScript framework of choice is "Prototype":http://www.prototypejs.org. Prototype is a generic-purpose JavaScript framework that aims to ease the development of dynamic web applications by offering DOM manipulation, AJAX and other JavaScript functionality ranging from utility functions to object oriented constructs. It is not specifically written for any language, so Rails provides a set of helpers to enable seamless integration of Prototype with your Rails views. +Rails 3.1 default javaScript framework of choice is Jquery "http://jquery.com". + +jQuery is a new kind of JavaScript Library and jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. + +jquery-rails is default gem and it adds Ruby on Rails style restful HTTP verbs to the jQuery library. Instead of sending an actual PUT or DELETE request (many browsers only support GET and POST), jQuery will make a POST request with an additional data parameter called _method set to the proper verb. Ruby on Rails can then act accordingly. + +Jquery helpers you can access defaultly - typically in your master layout, application.html.erb - like so: + + +javascript_include_tag :defaults + + +jquery-rails is default in Gemfile. + + +javascript_include_tag :defaults + + +All the remote_ true option to the original non-remote method + +==== Examples + + button_to "New", :action => "new", :form_class => "new-thing" + +# => "
+#
+#
" -To get access to these helpers, all you have to do is to include the prototype framework in your pages - typically in your master layout, application.html.erb - like so: -javascript_include_tag 'prototype' + button_to "Create", :action => "create", :remote => true, :form => { "data-type" => "json" } +# => "
+#
+#
" + + + + +button_to "Delete Image", { :action => "delete", :id => @image.id }, + :confirm => "Are you sure?", :method => :delete + + +# => "
+#
+# +# +#
+#
" + + + button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?', + :method => "delete", :remote => true, :disable_with => 'loading...') + +# => "
+#
+# +# +#
+#
" + +TODO: Write more Jquery helpers here. + +You can also specify the prototype to use instead of jquery or any other libraries + +rails new app_name -j prototype + +Prototype is a generic-purpose JavaScript framework that aims to ease the development of dynamic web applications by offering DOM manipulation, AJAX and other JavaScript functionality ranging from utility functions to object oriented constructs. It is not specifically written for any language, so Rails provides a set of helpers to enable seamless integration of Prototype with your Rails views. You are ready to add some AJAX love to your Rails app! -- cgit v1.2.3 From 3deb35ea5c92d576b3979e39f816e83d76355836 Mon Sep 17 00:00:00 2001 From: mhutchin Date: Sat, 8 Oct 2011 22:45:31 -0700 Subject: copy editing --- railties/guides/source/association_basics.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile index f5f0f9340c..5e8610073b 100644 --- a/railties/guides/source/association_basics.textile +++ b/railties/guides/source/association_basics.textile @@ -566,7 +566,7 @@ The build_association method returns a new object of the assoc h6(#belongs_to-create_association). create_association(attributes = {}) -The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set. In addition, the associated object _will_ be saved (assuming that it passes any validations). +The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set. In addition, once it passes all of the validations specified on the associated model, the associated object _will_ be saved. @customer = @order.create_customer(:customer_number => 123, -- cgit v1.2.3 From ac8555b5a0f52d02b66d2074672d287db0bb91dc Mon Sep 17 00:00:00 2001 From: mhutchin Date: Sat, 8 Oct 2011 23:02:33 -0700 Subject: copy editing --- railties/guides/source/association_basics.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile index 5e8610073b..06cb199fd9 100644 --- a/railties/guides/source/association_basics.textile +++ b/railties/guides/source/association_basics.textile @@ -211,7 +211,7 @@ end h4. Choosing Between +belongs_to+ and +has_one+ -If you want to set up a 1–1 relationship between two models, you'll need to add +belongs_to+ to one, and +has_one+ to the other. How do you know which is which? +If you want to set up a one-to-one relationship between two models, you'll need to add +belongs_to+ to one, and +has_one+ to the other. How do you know which is which? The distinction is in where you place the foreign key (it goes on the table for the class declaring the +belongs_to+ association), but you should give some thought to the actual meaning of the data as well. The +has_one+ relationship says that one of something is yours - that is, that something points back to you. For example, it makes more sense to say that a supplier owns an account than that an account owns a supplier. This suggests that the correct relationships are like this: @@ -576,7 +576,7 @@ The create_association method returns a new object of the asso h5. Options for +belongs_to+ -In many situations, you can use the default behavior of +belongs_to+ without any customization. But despite Rails' emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +belongs_to+ association. For example, an association with several options might look like this: +In many situations, you can use the default behavior of +belongs_to+ without any customization. But despite Rails' emphasis of convention over configuration, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +belongs_to+ association. For example, an association with several options might look like this: class Order < ActiveRecord::Base @@ -842,7 +842,7 @@ The create_association method returns a new object of the asso h5. Options for +has_one+ -In many situations, you can use the default behavior of +has_one+ without any customization. But despite Rails' emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +has_one+ association. For example, an association with several options might look like this: +In many situations, you can use the default behavior of +has_one+ without any customization. But despite Rails' emphasis of convention over configuration, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +has_one+ association. For example, an association with several options might look like this: class Supplier < ActiveRecord::Base -- cgit v1.2.3 From 43baad78f758fe16485202643721a07852b25376 Mon Sep 17 00:00:00 2001 From: "Karunakar (Ruby)" Date: Sun, 9 Oct 2011 12:46:25 +0530 Subject: improving the docs for ajax_on_rails --- railties/guides/source/ajax_on_rails.textile | 35 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile index b5d4fb10f8..9f5afc87de 100644 --- a/railties/guides/source/ajax_on_rails.textile +++ b/railties/guides/source/ajax_on_rails.textile @@ -44,23 +44,30 @@ jquery-rails is default in Gemfile. javascript_include_tag :defaults +h4. Examples + All the remote_ true option to the original non-remote method -==== Examples button_to "New", :action => "new", :form_class => "new-thing" -# => "
-#
-#
" + +will produce + +
+
+
button_to "Create", :action => "create", :remote => true, :form => { "data-type" => "json" } -# => "
-#
-#
" + +will produce + +
+
+
@@ -69,12 +76,14 @@ button_to "Delete Image", { :action => "delete", :id => @image.id }, :confirm => "Are you sure?", :method => :delete -# => "
-#
-# -# -#
-#
" +will produce + +
+
+ + +
+
button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?', -- cgit v1.2.3 From 9de9f6b4d0422e23e1eec9c59bbda880684e45c9 Mon Sep 17 00:00:00 2001 From: mhutchin Date: Sun, 9 Oct 2011 01:50:53 -0700 Subject: Copy editing to improve readability and remove any potential ambiguity --- railties/guides/source/association_basics.textile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile index 06cb199fd9..8943bfa0a3 100644 --- a/railties/guides/source/association_basics.textile +++ b/railties/guides/source/association_basics.textile @@ -566,7 +566,7 @@ The build_association method returns a new object of the assoc h6(#belongs_to-create_association). create_association(attributes = {}) -The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set. In addition, once it passes all of the validations specified on the associated model, the associated object _will_ be saved. +The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through this object's foreign key will be set, and, once it passes all of the validations specified on the associated model, the associated object _will_ be saved. @customer = @order.create_customer(:customer_number => 123, @@ -760,9 +760,9 @@ h6(#belongs_to-validate). +:validate+ If you set the +:validate+ option to +true+, then associated objects will be validated whenever you save this object. By default, this is +false+: associated objects will not be validated when this object is saved. -h5(#belongs_to-how_to_know_whether_theres_an_associated_object). How To Know Whether There's an Associated Object? +h5(#belongs_to-do_any_associated_objects_exist). Do Any Associated Objects Exist? -To know whether there's and associated object just check association.nil?: +You can see if any associated objects exist by using the association.nil? method: if @order.customer.nil? @@ -834,7 +834,7 @@ The build_association method returns a new object of the assoc h6(#has_one-create_association). create_association(attributes = {}) -The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set. In addition, the associated object _will_ be saved (assuming that it passes any validations). +The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through its foreign key will be set, and, once it passes all of the validations specified on the associated model, the associated object _will_ be saved. @account = @supplier.create_account(:terms => "Net 30") @@ -980,9 +980,9 @@ h6(#has_one-validate). +:validate+ If you set the +:validate+ option to +true+, then associated objects will be validated whenever you save this object. By default, this is +false+: associated objects will not be validated when this object is saved. -h5(#has_one-how_to_know_whether_theres_an_associated_object). How To Know Whether There's an Associated Object? +h5(#has_one-do_any_associated_objects_exist). Do Any Associated Objects Exist? -To know whether there's and associated object just check association.nil?: +You can see if any associated objects exist by using the association.nil? method: if @supplier.account.nil? @@ -1147,7 +1147,7 @@ The collection.build method returns one or more new objects of h6(#has_many-collection-create). collection.create(attributes = {}) -The collection.create method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through its foreign key will be created, and the associated object _will_ be saved (assuming that it passes any validations). +The collection.create method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through its foreign key will be created, and, once it passes all of the validations specified on the associated model, the associated object _will_ be saved. @order = @customer.orders.create(:order_date => Time.now, @@ -1576,7 +1576,7 @@ The collection.build method returns a new object of the associ h6(#has_and_belongs_to_many-create-attributes). collection.create(attributes = {}) -The collection.create method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through the join table will be created, and the associated object _will_ be saved (assuming that it passes any validations). +The collection.create method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through the join table will be created, and, once it passes all of the validations specified on the associated model, the associated object _will_ be saved. @assembly = @part.assemblies.create( -- cgit v1.2.3 From da773a24beab90236802a2ca39e5b124b1b5d456 Mon Sep 17 00:00:00 2001 From: Roy Tomeij Date: Sun, 9 Oct 2011 13:38:47 +0200 Subject: Add note about how Sass & Sprockets don't match --- railties/guides/source/asset_pipeline.textile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index ef01cd32ac..303066b752 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -19,7 +19,7 @@ Prior to Rails 3.1 these features were added through third-party Ruby libraries By having this 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 library, Sprockets. This is part of Rails' "fast by default" strategy as outlined by DHH in his keynote at RailsConf 2011. -In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +config/application.rb+ by putting this line inside the application class definition: +In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +config/application.rb+ by publicing this line inside the application class definition: config.assets.enabled = false @@ -234,6 +234,8 @@ The directives that work in the JavaScript files also work in stylesheets, obvio In this example +require_self+ is used. This puts the CSS contained within the file (if any) at the precise location of the +require_self+ call. If +require_self+ is called more than once, only the last call is respected. +NOTE. If you want to use multiple Sass files, use the "Sass +@import+ rule":http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#import instead of the Sprockets directives. Using Sprockets directives all Sass files exist within their own scope, making variables or mixins only available within the document they were defined in. + You can have as many manifest files as you need. For example the +admin.css+ and +admin.js+ manifest could contain the JS and CSS files that are used for the admin section of an application. The same remarks about ordering made above apply. In particular, you can specify individual files and they are compiled in the order specified: -- cgit v1.2.3 From d214e54e7aadd15bbf872c3deae24908258e8cb8 Mon Sep 17 00:00:00 2001 From: Roy Tomeij Date: Sun, 9 Oct 2011 13:45:54 +0200 Subject: Fix a typo that was mysteriously entered in previous commit --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 303066b752..1b245b1fc7 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -19,7 +19,7 @@ Prior to Rails 3.1 these features were added through third-party Ruby libraries By having this 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 library, Sprockets. This is part of Rails' "fast by default" strategy as outlined by DHH in his keynote at RailsConf 2011. -In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +config/application.rb+ by publicing this line inside the application class definition: +In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +config/application.rb+ by putting this line inside the application class definition: config.assets.enabled = false -- cgit v1.2.3 From 3a72c01be2add83c76e6180d60a520491484c01e Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 9 Oct 2011 19:58:14 +0530 Subject: Corrections to the ajax guide recent changes. This guide is very outdated and will need a lot of changes to make it useful for Rails 3+ --- railties/guides/source/ajax_on_rails.textile | 58 +++++++++++++--------------- 1 file changed, 26 insertions(+), 32 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile index 9f5afc87de..3a0ccfe9b2 100644 --- a/railties/guides/source/ajax_on_rails.textile +++ b/railties/guides/source/ajax_on_rails.textile @@ -3,7 +3,7 @@ h2. AJAX on Rails This guide covers the built-in Ajax/JavaScript functionality of Rails (and more); it will enable you to create rich and dynamic AJAX applications with ease! We will cover the following topics: * Quick introduction to AJAX and related technologies -* Unobtrusive JavaScript helpers with drivers for Prototype, jQuery, and more coming (end of inline JS) +* Unobtrusive JavaScript helpers with drivers for Prototype, jQuery etc * Testing JavaScript functionality endprologue. @@ -26,19 +26,7 @@ How do 'standard' and AJAX requests differ, why does this matter for understandi h3. Built-in Rails Helpers -Rails 3.1 default javaScript framework of choice is Jquery "http://jquery.com". - -jQuery is a new kind of JavaScript Library and jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. - -jquery-rails is default gem and it adds Ruby on Rails style restful HTTP verbs to the jQuery library. Instead of sending an actual PUT or DELETE request (many browsers only support GET and POST), jQuery will make a POST request with an additional data parameter called _method set to the proper verb. Ruby on Rails can then act accordingly. - -Jquery helpers you can access defaultly - typically in your master layout, application.html.erb - like so: - - -javascript_include_tag :defaults - - -jquery-rails is default in Gemfile. +Rails 3.1 ships with "jQuery":http://jquery.com as the default JavaScript library. The Gemfile contains gem 'jquery-rails' which makes the jQuery files available to the application automatically. This can be accessed as: javascript_include_tag :defaults @@ -46,63 +34,69 @@ javascript_include_tag :defaults h4. Examples -All the remote_ true option to the original non-remote method +All the remote_method helpers has been removed. To make them working with AJAX, simply pass the :remote => true option to the original non-remote method. - button_to "New", :action => "new", :form_class => "new-thing" +button_to "New", :action => "new", :form_class => "new-thing" will produce +
- + - button_to "Create", :action => "create", :remote => true, :form => { "data-type" => "json" } +button_to "Create", :action => "create", :remote => true, :form => { "data-type" => "json" } will produce +
- + - button_to "Delete Image", { :action => "delete", :id => @image.id }, :confirm => "Are you sure?", :method => :delete will produce +
+ - - button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?', + +button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?', :method => "delete", :remote => true, :disable_with => 'loading...') -# => "
-#
-# -# -#
-#
" -TODO: Write more Jquery helpers here. +will produce -You can also specify the prototype to use instead of jquery or any other libraries + +
+
+ + +
+
+ -rails new app_name -j prototype +You can also choose to use Prototype instead of jQuery and specify the option using +-j+ switch while generating the application. -Prototype is a generic-purpose JavaScript framework that aims to ease the development of dynamic web applications by offering DOM manipulation, AJAX and other JavaScript functionality ranging from utility functions to object oriented constructs. It is not specifically written for any language, so Rails provides a set of helpers to enable seamless integration of Prototype with your Rails views. + +rails new app_name -j prototype + You are ready to add some AJAX love to your Rails app! -- cgit v1.2.3