From 78b40bba7b669296218149c5b2052b83c0104f00 Mon Sep 17 00:00:00 2001 From: Mikhail Dieterle Date: Sun, 4 Mar 2012 14:37:25 +0800 Subject: typo --- railties/guides/source/configuring.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index e796f44606..06a2bbcf77 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -493,7 +493,7 @@ Rails has 5 initialization events which can be hooked into (listed in the order * +after_initialize+: Run directly after the initialization of the application, but before the application initializers are run. -To define an event for these hooks, use the block syntax within a +Rails::Aplication+, +Rails::Railtie+ or +Rails::Engine+ subclass: +To define an event for these hooks, use the block syntax within a +Rails::Application+, +Rails::Railtie+ or +Rails::Engine+ subclass: module YourApp -- cgit v1.2.3 From 69786d1d4a2cb861755d47dfb37d79ca504a474b Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sun, 4 Mar 2012 16:45:10 -0300 Subject: Bump "latest version" from 3.2.1 to 3.2.2 in upgrading rails guide --- railties/guides/source/upgrading_ruby_on_rails.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/upgrading_ruby_on_rails.textile b/railties/guides/source/upgrading_ruby_on_rails.textile index 6e84b7fe40..731d56c850 100644 --- a/railties/guides/source/upgrading_ruby_on_rails.textile +++ b/railties/guides/source/upgrading_ruby_on_rails.textile @@ -38,14 +38,14 @@ h3. Upgrading from Rails 3.1 to Rails 3.2 If your application is currently on any version of Rails older than 3.1.x, you should upgrade to Rails 3.1 before attempting an update to Rails 3.2. -The following changes are meant for upgrading your application to Rails 3.2.1, the latest 3.2.x version of Rails. +The following changes are meant for upgrading your application to Rails 3.2.2, the latest 3.2.x version of Rails. h4(#gemfile3_2). Gemfile Make the following changes to your +Gemfile+. -gem 'rails', '= 3.2.1' +gem 'rails', '= 3.2.2' group :assets do gem 'sass-rails', '~> 3.2.3' -- cgit v1.2.3 From 9f7804215249fa725596fdbeb4aeba9abbc1f26f Mon Sep 17 00:00:00 2001 From: Swanand Pagnis Date: Mon, 5 Mar 2012 18:54:34 +0530 Subject: Fixed a slightly misleading equivalent SQL code on the 3.2 query interface. --- railties/guides/source/active_record_querying.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 21bbc64255..d9a62f7574 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -94,7 +94,7 @@ client = Client.find(10) The SQL equivalent of the above is: -SELECT * FROM clients WHERE (clients.id = 10) +SELECT * FROM clients WHERE (clients.id = 10) LIMIT 1 Model.find(primary_key) will raise an +ActiveRecord::RecordNotFound+ exception if no matching record is found. -- cgit v1.2.3 From 3a0433b898a93d543abb261e1d3a307fcbf01ecd Mon Sep 17 00:00:00 2001 From: Matthew Conway Date: Mon, 5 Mar 2012 16:07:52 -0500 Subject: Fix typo in asset pipeline guide --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index a061c1fc16..b1b1d21c2d 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -128,7 +128,7 @@ For example, these files: app/assets/javascripts/home.js lib/assets/javascripts/moovinator.js -vendor/assets/javascript/slider.js +vendor/assets/javascripts/slider.js would be referenced in a manifest like this: -- cgit v1.2.3 From fd584a63deb8d2f1e8969d8527e7a9dbd9d68848 Mon Sep 17 00:00:00 2001 From: adman65 Date: Mon, 5 Mar 2012 23:08:35 +0200 Subject: Add rails glossary of common terms & concepts --- railties/guides/source/credits.html.erb | 4 + railties/guides/source/glossary.textile | 424 ++++++++++++++++++++++++++++++++ 2 files changed, 428 insertions(+) create mode 100644 railties/guides/source/glossary.textile (limited to 'railties/guides') diff --git a/railties/guides/source/credits.html.erb b/railties/guides/source/credits.html.erb index da6bd6acdf..00cf765b77 100644 --- a/railties/guides/source/credits.html.erb +++ b/railties/guides/source/credits.html.erb @@ -70,3 +70,7 @@ Ryan Bigg works as a consultant at RubyX and has <%= author('Heiko Webers', 'hawe') do %> Heiko Webers is the founder of bauland42, a German web application security consulting and development company focused on Ruby on Rails. He blogs at the Ruby on Rails Security Project. After 10 years of desktop application development, Heiko has rarely looked back. <% end %> + +<%= author('Adam Hawkins', 'adman65') do %> + Ruby developer and founder of ThreadedLabs a modern web shop. You can read his blog at Broadcasting Adam +<% end %> diff --git a/railties/guides/source/glossary.textile b/railties/guides/source/glossary.textile new file mode 100644 index 0000000000..099a35bc52 --- /dev/null +++ b/railties/guides/source/glossary.textile @@ -0,0 +1,424 @@ +h2. Rails Glossary + +This is a beginner guide to common terms, projects, and things you will come across when +working with Rails. The glossary is here to provide you introductory material on each +topic so you can learn more. When you come across a topic you're not familiar with, +you can check here. + +endprologue. + +h3. Acceptance Testing + +Acceptancing testing is the act of testing use cases. Test cases are written +in a way that describes a use case. Then a test case is passing it can be +accepted. Cucumber is a good tool for acceptance testings. Work with your +stake holder to develop tests that represent use cases. When the test is +complete the feature should be accepted. Acceptance testing is focused +around people outside the code development accepting features. + +h3. Application Servers: Thin, Passenger, Unicorn + +These are all application servers. They interact with your Ruby code +and respond to requests. They are integrated with web servers like Nginx +or Apache to server you application on the internet. Some also serve +the application by itself. You can +rackup+ a rack app and serve it with +Thin right away. + +h3. Assets + +Assets are static files that are part of your application. They include: images, sytlesheets, scripts, or fonts. +Essentially, anything that needs to be server with your code for your app to run is +an asset. The asset pipeline gives you an easy way to manage all the different files. + +h3. Authentication + +Authentication is the process of matching credentials to a person and +verifying them. Authentication is purely about identifiying who the +user is–and not what they can do. +"Sorcery":https://github.com/NoamB/sorcery is an example of an authentication library. + +h3. Authorization + +Authorization is the process for determine what a specific user can do. +Authorization usually involves permission or role based systems. +"CanCan":https://github.com/ryanb/cancan is an example of an authorization library. + +h3. Behavior Driven Development (BDD) + +Is essentially the same as TDD except using a different set of tools +to express code in terms of user facing behavior. +"Rspec":https://github.com/rspec/rspec and "Cucumber":https://github.com/cucumber/cucumber are part of the BDD toolbox. + +h3. Bundler + +Bundler reads a Gemfile and calculates a set of version requirements +to make all the specified gems live happily together. It will prevent +version conflicts and infamous ‘gem already activated error’. It allows +you to install git gems or standard gems from rubygems.org. It does +not require libraries, it simply makes them available. It is up to you +require them in your programs. However, Rails will automatically setup bundler when your application boots. + +h3. Capistrano + +Capistrano is a tool for executing command one groups of remote +(or local) serves over SSH. It is primary used to deploy +Ruby (on Rails) applications. It has support for multistage environments. +Example, staging and production. You can easily write your own +tasks similar to writing rake task. It is the preferred way deploy Rails applications. + +h3. Capybara + +Capybara is a gem designed to provide an abstraction layer between +different browser drivers. It is primarily used in integration testing +to interact with the web server. It provides an API to navigate between +pages, click buttons, fill in forms, and other user interactions. It has +adapters for many different browser drivers. Notable drivers include +Selenium, rack-test and webrat. It is primary used in acceptance testing. + +h3. CoffeeScript + +CoffeeScript is a JavaScript superset. It aims to solves some problems +with JavaScript. It has some syntatical sugar around creating colsures and +objects. It supports for splat arguments. CoffeeScript files are compiled +into JavaScript files. CoffeeScript is usually called CS. You'll often see +CS/JS in reference to CoffeeScript and Javascript. + +h3. Compass + +Compass is a library built around SASS abstractions. It provides mixins +for many common things like styling buttons and forms. It is also easy +to extend and comes with many built in functions. The blueprint CSS +framework is bundled by default. + +h3. Cucumber + +Cucumber is a test framework for creating plain english acceptance +tests. The tests can be executed automatically. Cucumber is used for +integration testing web applications. The test suite is often used in CI +(Continuous Integration). Cucumber uses a language called Gherkin to +parse files into lines and match them against regular expressions. +Regular expressions are matched with code blocks. Your test code lives +in these blocks. + +Cucumber tests are divided up into "Feature" files. Each feature has +many "scenarios." Features are like use cases. Scenarios are different +permutations of that use case. Here is an example Feature file: + +
+Feature: Make Widthdrawls from Accounts
+  As an account holder
+  I want to use my money
+  In order to use it buy thing
+
+  Background:
+    Given I have account under "RubyX"
+    And my account is activated
+
+  Scenario: There is enough money in my account
+    Given my account has "$1,000"
+    And I'm at the bank
+    When I widthdraw "$500"
+    Then my account should have "$500"
+
+  Scenario: There is not enough money in my account
+    Given my account has "$1,000"
+    And I'm at the bank
+    When I widthdraw "$500"
+    Then the teller should reject my transaction
+
+ +Here is an example step definition: + + +Given /I'm at the bank/ do + # set up pre conditions +end + +Then /the teller should reject my transaction/ do + # assert on things +end + + +h3. DSL + +DSL stands for Domain Specific Language. They are crafted to solve one +or more problems very eloquently and nothing more. For example, a DSL +created to declare work order would be horrible suited for writing +Photoshop. DSLs are usually wrappers around more complicated methods +that make it easier to express the intent of the underlying code from +a programmer's perspective. You may have used a DSL before and +not realized it. Here is an example from Sunspot's search +functionality. It's designed for describing a search and nothing more: + + +Post.search do + fulltext 'best pizza' + with :blog_id, 1 + with(:published_at).less_than Time.now + order_by :published_at, :desc + paginate :page => 2, :per_page => 15 + facet :category_ids, :author_id +end + + +h3. ERB + +ERB is Embedded Ruby. ERB is built into the Ruby core. It allows to to +place Ruby inside other files. For example, placing Ruby inside HTML. +Here is an example: + + +
<%= @ticket.message %>

+
+
+ +h3. Factories - FactoryGirl & Fabrication + +These are two popular libraries for creating object factories. They are +usually used in test suites and population scripts. They provide a +default set of attributes and allow programmers to specify the +attributes they care about at creation time. Factories are commonly used +to replace fixtures. + +h3. Fixtures + +Fixtures are static objects used in test cases. You may have a fixtures for specific +test cases to build up needed preconditions. Fixtures are commonly used to represent +data in a table. Fixtures are stored in YML and are loaded by a test library. +Fixtures become hard to main at scale. They are often replaced with Factories because +it's easier to generate an object at runtime then maintain a static file with its +attributes. + +h3. Gem + +A gem is a resuable library of Ruby code. Gems are hosted on "RubyGems":http://rubygems.org. +They are managed with the +gem+ command or with bundler. Rails is +distributed as a gem. + +h3. Git + +Git is a distributed version control system. Each user has a complete +copy of the repository. Changes can be pushed back to the remote +repositories for others to pull or push from. Linus Torvalds created Git +because he was unsatisfied with other version control systems like CVS +or SVN. Do not get GitHub confused with Git. GitHub is simply a service +for hosting the main Git repository. You can use git independent of +github, however most Ruby developers use github exclusively. + +h3. HAML + +HAML is an HTML abstraction language. It's great for structuring +documents and horrible to content. It will autoclose tags and lets you +specify attributes as a hash. You can also include ruby code inside +the templates. Here is an example: + +
+.post#post_5 
+  .content= simple_format(@post.content)
+
+ +h3. Heroku + +Ruby PaaS (Platform as a Service). They provide free cloud hosting for +Rack applications with paid plans for increased resources. It is a very +easy way to deploy your first application. Beware, they are easily owned +by Amazon's AWS failure. + +h3. Integration Testing + +Integration testing referes testing different modules of code in concert. +Ingration testing tests that all the parts of your system are working correctly. +It is different than unit testing because it involves more than one component +at at time. Integration tests for rails apps usually mean submitting web requests +and see how they are handled. You can take this a step further and move into +acceptance testing which simulates a user in front of your application. +Integration tests are written "outside in" meaning they only focus on +the outward functions of your system. + +h3. Less + +Less is a library for writing stylesheets. It enables you to do things +like use variables and other handy things. Less files are compiled into +vanilla CSS files. It is similar to SCSS/SASS. Twitter Bootstrap is written in Less. + +h3. Metaprogramming + +Metaprogramming is a term for dynamically generating code at runtime. +Metaprogramming is why Rails feel the way it does. ActiveRecord +associations to dynamically add methods to your classed based on how to +declare them. Metaprogramming is possible in Ruby because it's a dynamic +language interpreted at run time. + +h3. Nonrelational Databases (NoSQL) + +Nonrelational databases are the oppposte of relational databases. They +are usually more free form and don't have defined schemas (like tables.) +There is no such thing as SQL for non relational databases because each +one uses it's own langauge to inster and retreive data. MonogDB is +the most popular nonrelationable database. + +h3. Open Classes & Monkey Patching + +Ruby has open classes. This means you can simply declare methods insides +a class that's already been defined. ActiveSupport uses open classes to +add all those nice methods to core Ruby objects. This is how you can add +a method to the `String` class: + + +class String + def lulz + puts "lulz " * self.length + end +end + +"Hey".lulz + + +h3. ORM - Object Relational Mapping + +ORM's provide a way to map one object into some sort of persistent storage. +ActiveRecord is a well known ORM that implements that Active Record pattern. +ActiveRecord allows you persist objects into a relational database. ActiveRecord +is not the only ORM. Datamapper and Sequel are also popular for relational databases. +Mongoid is popular for MongoDB (a nonrelational database.) + +h3. Relational Databases + +Relational databases store data into tables with columns. Each column has a +type of data. For example: numbers, text, or dates. Data is retrieved +using SQL. ORM's are commonly used to make it easier to work with data +in retional databases. PostreSQL and MySQL are examples of popular +realtional databases to use with Rails. + +h3. Rack + +Rack is a standard interface for writing web applications in Ruby. +Rails as of version 3 is a Rack app. Rack defines things like HTTP requests +and how your code is called. Rack applications are easily served by application +servers such as Thin. + +h3. Rake + +Rake is like the Ruby version of make. You can create custom tasks that +can be executed from the command line. `rake db:migrate` is a classic +example. You can create as many tasks as you want. They can have +prerequisites. They can also be in namespaces. A ':' designates tasks in +different namespace. `db:migrate` means 'db' namespace, 'migrate' task. +Multiple tasks can be executed in one go like so: `rake db:create +schema:load`. They will be executed in the order they are listed. Rake +was originally designed to be like make, but is often used to execute +arbitrary code outside an application context. A cron job is a perfect +example. + +h3. RSpec + +Rspec is a unit testing framework. It is based around the idea that test +should describe behavior of classes in an english like way. Test files +are called "specs". Spec files are divided into "examples." Examples +contain matchers. Spec files can share examples. Here is an example +spec_file: + + +require 'spec_helper' + +describe Post do + it { should have_many(:comments) } + + describe "Post#out_dated?" do + subject { Post.new :created_at => 2.months.ago } + + it { should be_outdated } + end +end + + +h3. RVM + +Rvm stands for Ruby Version Manager. It is a set of bash script designed +to allow you switch out Ruby interpreters on the fly. It manages +installed ruby interpreters and makes is very easy to install different +implementations. It also manages Gemsets. Gemsets are groups of gemsets +that are distinct from other groups (except the global gemset which +shares gems between different ruby interpreters). + +h3. Rbenv + +Rbenv was created to address some flaws in RVM. It does the same thing +as RVM in a different way. It allows you manage different Ruby versions +and switch between them. + +h3. SASS & SCSS + +SASS and SCSS are CSS abstraction languages. They are compiled down to +CSS. They allow you use variables, modules and include other files. +In short, they make it much easier to write and main large amounts of +CSS. + +h3. SQL - Structured Query Language + +SQL is the standard language for talking to relational database. It's sole +purpose is to describe what to get from the db, and now how to get it. +SQL is based on simple concepts like selects and joins. You select columns +from tables that you want back. You can define conditions to further refine +your query or use joins to connect more than one table together. + +h3. Selenium + +Selenium is a library that simulates user interaction with a browser. It +runs the full browser. Selenium works best in FireFox, but can work in +Chrome and other browsers. Commands are sent across as JavaScript which +the browser evaluates to complete each action. Selenium is the most +complete solution for simulating a user for your web application. + +h3. Unit Testing + +Unit testing refers to testing small units of code insolation. This +makes it easier to determine if individual modules of code are functioning +directly. You can do unit testing with many different libraries. +Test::Unit+ +is the Rails default. + +h3. Test Driven Development (TDD) + +The practice of writing a failing test first then completing the +implementation. This makes the developer spend more time thinking about +the code upfront while providing a solid test suite for the entire +application. You can use Test::Unit for TDD in Ruby. + +h3. Test::Unit + +Test::Unit is a unit test framework built into Ruby 1.8. It is known as +MiniTest in 1.9. It provides functionality for writing test cases with +standard setup and tear down. Rails generates test files built in +Test::Unit by default. It provides basic assertions. It's similar to +jUnit or any member of the xUnit family. Here is an example: + + +require 'test_helper' + +class PostTest < Test::Unit::TestCase + + def test_out_dated? do + post = Post.new :created_at => 2.months.ago + assertTrue(post.out_dated?) + end +end + + +h3. UJS (Unobstrusive JavaScript) + +Unobtrusive JavaScript means separating JavaScript from the HTML. +Specifying an `onClick` attribute in HTML is consider obtrusive because +it obfuscates the markup. It is also hard to maintain because your +javascript is harder to maintain. You can do the same thing +unobtrusively by using jQuery to find the element by a class name and +applying a click handler. Essentially UJS means keep JavaScript in .js +files and HTML in .html files. Separation of church and state if you +will. + +h3. Webrat + +Webrat is the original headless browser. It's similar to selenium, but +much more implemented. It does not execute JavaScript and does not +execute in a GUI. It is the most basic driver and is perfect for +interacting with simple websites. -- cgit v1.2.3 From 4bfc8b1e2ceaa0f87fa9642b535f4dd8a2f7fd6f Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 5 Mar 2012 15:08:15 -0800 Subject: [instrumentation guide] Add introduction + basic outline --- .../source/active_support_instrumentation.textile | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 railties/guides/source/active_support_instrumentation.textile (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_instrumentation.textile b/railties/guides/source/active_support_instrumentation.textile new file mode 100644 index 0000000000..f9452400ad --- /dev/null +++ b/railties/guides/source/active_support_instrumentation.textile @@ -0,0 +1,39 @@ +h2. Active Support Instrumentation + +Active Support is a part of core Rails that provides Ruby language extensions, utilities and other things. One of the things it includes is an instrumentation API that can be used inside an application to measure certain actions that occur within Ruby code, such as that inside a Rails application or the framework itself. It is not limited to Rails, however. It can be used independently in other Ruby scripts if it is so desired. + +In this guide, you will learn how to use the instrumentation API inside of ActiveSupport to measure events inside of Rails and other Ruby code. We cover: + +* What instrumentation can provide +* The hooks inside the Rails framework for instrumentation +* Adding a subscriber to a hook +* Building a custom instrumentation implementation + +endprologue. + +h3. Introduction to instrumentation + +The instrumentation API provided by ActiveSupport allows developers to provide hooks which other developers may hook into. There are several of these within the Rails framework, as described below in . With this API, developers can choose to be notified when certain events occur inside their application or another piece of Ruby code. + +For example, there is a hook provided within Active Record that is called every time Active Record uses a SQL query on a database. This hook could be *subscribed* to, and used to track the number of queries during a certain action. There's another hook around the processing of an action of a controller. This could be used, for instance, to track how long a specific action has taken. + +You are even able to create your own events inside your application which you can later subscribe to. + +h3. Rails framework hooks + +h4. Action Mailer + +h4. Action Controller + +h4. Action View + +h4. Active Record + +h4. Active Resource + +h4. Active Support + +h3. Subscribing to an event + +h3. Creating custom events + -- cgit v1.2.3 From 9ab7620eb55d00515f0fef2bd9d15e1cd511e716 Mon Sep 17 00:00:00 2001 From: Kevin Griffin Date: Tue, 6 Mar 2012 16:02:53 -0600 Subject: Correct it's/its usage. --- railties/guides/source/ajax_on_rails.textile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile index 5913a472fd..cda9c64460 100644 --- a/railties/guides/source/ajax_on_rails.textile +++ b/railties/guides/source/ajax_on_rails.textile @@ -134,7 +134,7 @@ If the server returns 200, the output of the above example is equivalent to our ** *position* By default (i.e. when not specifying this option, like in the examples before) the response is injected into the element with the specified DOM id, replacing the original content of the element (if there was any). You might want to alter this behavior by keeping the original content - the only question is where to place the new content? This can specified by the +position+ parameter, with four possibilities: *** +:before+ Inserts the response text just before the target element. More precisely, it creates a text node from the response and inserts it as the left sibling of the target element. *** +:after+ Similar behavior to +:before+, but in this case the response is inserted after the target element. -*** +:top+ Inserts the text into the target element, before it's original content. If the target element was empty, this is equivalent with not specifying +:position+ at all. +*** +:top+ Inserts the text into the target element, before its original content. If the target element was empty, this is equivalent with not specifying +:position+ at all. *** +:bottom+ The counterpart of +:top+: the response is inserted after the target element's original content. A typical example of using +:bottom+ is inserting a new <li> element into an existing list: @@ -174,7 +174,7 @@ link_to_remote "Update record", This generates a remote link which adds 2 parameters to the standard URL generated by Rails, taken from the page (contained in the elements matched by the 'status' and 'completed' DOM id). -** *Callbacks* Since an AJAX call is typically asynchronous, as it's name suggests (this is not a rule, and you can fire a synchronous request - see the last option, +:type+) your only way of communicating with a request once it is fired is via specifying callbacks. There are six options at your disposal (in fact 508, counting all possible response types, but these six are the most frequent and therefore specified by a constant): +** *Callbacks* Since an AJAX call is typically asynchronous, as its name suggests (this is not a rule, and you can fire a synchronous request - see the last option, +:type+) your only way of communicating with a request once it is fired is via specifying callbacks. There are six options at your disposal (in fact 508, counting all possible response types, but these six are the most frequent and therefore specified by a constant): *** +:loading:+ => +code+ The request is in the process of receiving the data, but the transfer is not completed yet. *** +:loaded:+ => +code+ The transfer is completed, but the data is not processed and returned yet *** +:interactive:+ => +code+ One step after +:loaded+: The data is fully received and being processed @@ -203,7 +203,7 @@ link_to_remote "Add new item", ** *:type* If you want to fire a synchronous request for some obscure reason (blocking the browser while the request is processed and doesn't return a status code), you can use the +:type+ option with the value of +:synchronous+. * Finally, using the +html_options+ parameter you can add HTML attributes to the generated tag. It works like the same parameter of the +link_to+ helper. There are interesting side effects for the +href+ and +onclick+ parameters though: ** If you specify the +href+ parameter, the AJAX link will degrade gracefully, i.e. the link will point to the URL even if JavaScript is disabled in the client browser -** +link_to_remote+ gains it's AJAX behavior by specifying the remote call in the onclick handler of the link. If you supply +html_options[:onclick]+ you override the default behavior, so use this with care! +** +link_to_remote+ gains its AJAX behavior by specifying the remote call in the onclick handler of the link. If you supply +html_options[:onclick]+ you override the default behavior, so use this with care! We are finished with +link_to_remote+. I know this is quite a lot to digest for one helper function, but remember, these options are common for all the rest of the Rails view helpers, so we will take a look at the differences / additional parameters in the next sections. @@ -211,8 +211,8 @@ h4. AJAX Forms There are three different ways of adding AJAX forms to your view using Rails Prototype helpers. They are slightly different, but striving for the same goal: instead of submitting the form using the standard HTTP request/response cycle, it is submitted asynchronously, thus not reloading the page. These methods are the following: -* +remote_form_for+ (and it's alias +form_remote_for+) is tied to Rails most tightly of the three since it takes a resource, model or array of resources (in case of a nested resource) as a parameter. -* +form_remote_tag+ AJAXifies the form by serializing and sending it's data in the background +* +remote_form_for+ (and its alias +form_remote_for+) is tied to Rails most tightly of the three since it takes a resource, model or array of resources (in case of a nested resource) as a parameter. +* +form_remote_tag+ AJAXifies the form by serializing and sending its data in the background * +submit_to_remote+ and +button_to_remote+ is more rarely used than the previous two. Rather than creating an AJAX form, you add a button/input Let's see them in action one by one! -- cgit v1.2.3 From 4b89b90e93486d7ff99ccc429bc24c46adb0cb9f Mon Sep 17 00:00:00 2001 From: coreyhaines Date: Tue, 6 Mar 2012 20:43:48 -0600 Subject: In a nested resource route, the parent resource param is _id --- railties/guides/source/routing.textile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 42665114be..001b507c3b 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -234,14 +234,14 @@ end In addition to the routes for magazines, this declaration will also route ads to an +AdsController+. The ad URLs require a magazine: -|_.HTTP Verb |_.Path |_.action |_.used for | -|GET |/magazines/:id/ads |index |display a list of all ads for a specific magazine | -|GET |/magazines/:id/ads/new |new |return an HTML form for creating a new ad belonging to a specific magazine | -|POST |/magazines/:id/ads |create |create a new ad belonging to a specific magazine | -|GET |/magazines/:id/ads/:id |show |display a specific ad belonging to a specific magazine | -|GET |/magazines/:id/ads/:id/edit |edit |return an HTML form for editing an ad belonging to a specific magazine | -|PATCH/PUT |/magazines/:id/ads/:id |update |update a specific ad belonging to a specific magazine | -|DELETE |/magazines/:id/ads/:id |destroy |delete a specific ad belonging to a specific magazine | +|_.HTTP Verb |_.Path |_.action |_.used for | +|GET |/magazines/:magazine_id/ads |index |display a list of all ads for a specific magazine | +|GET |/magazines/:magazine_id/ads/new |new |return an HTML form for creating a new ad belonging to a specific magazine | +|POST |/magazines/:magazine_id/ads |create |create a new ad belonging to a specific magazine | +|GET |/magazines/:magazine_id/ads/:id |show |display a specific ad belonging to a specific magazine | +|GET |/magazines/:magazine_id/ads/:id/edit |edit |return an HTML form for editing an ad belonging to a specific magazine | +|PATCH/PUT |/magazines/:magazine_id/ads/:id |update |update a specific ad belonging to a specific magazine | +|DELETE |/magazines/:magazine_id/ads/:id |destroy |delete a specific ad belonging to a specific magazine | This will also create routing helpers such as +magazine_ads_url+ and +edit_magazine_ad_path+. These helpers take an instance of Magazine as the first parameter (+magazine_ads_url(@magazine)+). -- cgit v1.2.3 From f434fa846ecd564e1bb6f82025a94c03c22eff59 Mon Sep 17 00:00:00 2001 From: coreyhaines Date: Tue, 6 Mar 2012 20:46:47 -0600 Subject: Left off a : when specifying the :namespace option for a :controller path segment --- railties/guides/source/routing.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 001b507c3b..1d4cb9f783 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -389,7 +389,7 @@ match ':controller/:action/:id/:user_id' An incoming path of +/photos/show/1/2+ will be dispatched to the +show+ action of the +PhotosController+. +params[:id]+ will be +"1"+, and +params[:user_id]+ will be +"2"+. -NOTE: You can't use +namespace+ or +:module+ with a +:controller+ path segment. If you need to do this then use a constraint on :controller that matches the namespace you require. e.g: +NOTE: You can't use +:namespace+ or +:module+ with a +:controller+ path segment. If you need to do this then use a constraint on :controller that matches the namespace you require. e.g: match ':controller(/:action(/:id))', :controller => /admin\/[^\/]+/ -- cgit v1.2.3 From 97e7d43146b6edca19891d8c7ed6b4d93e7dad00 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Thu, 8 Mar 2012 23:36:46 +0530 Subject: Revert "Add rails glossary of common terms & concepts" This reverts commit fd584a63deb8d2f1e8969d8527e7a9dbd9d68848. Reason: This is not suitable for a Rails guide in my opinion. --- railties/guides/source/credits.html.erb | 4 - railties/guides/source/glossary.textile | 424 -------------------------------- 2 files changed, 428 deletions(-) delete mode 100644 railties/guides/source/glossary.textile (limited to 'railties/guides') diff --git a/railties/guides/source/credits.html.erb b/railties/guides/source/credits.html.erb index 00cf765b77..da6bd6acdf 100644 --- a/railties/guides/source/credits.html.erb +++ b/railties/guides/source/credits.html.erb @@ -70,7 +70,3 @@ Ryan Bigg works as a consultant at RubyX and has <%= author('Heiko Webers', 'hawe') do %> Heiko Webers is the founder of bauland42, a German web application security consulting and development company focused on Ruby on Rails. He blogs at the Ruby on Rails Security Project. After 10 years of desktop application development, Heiko has rarely looked back. <% end %> - -<%= author('Adam Hawkins', 'adman65') do %> - Ruby developer and founder of ThreadedLabs a modern web shop. You can read his blog at Broadcasting Adam -<% end %> diff --git a/railties/guides/source/glossary.textile b/railties/guides/source/glossary.textile deleted file mode 100644 index 099a35bc52..0000000000 --- a/railties/guides/source/glossary.textile +++ /dev/null @@ -1,424 +0,0 @@ -h2. Rails Glossary - -This is a beginner guide to common terms, projects, and things you will come across when -working with Rails. The glossary is here to provide you introductory material on each -topic so you can learn more. When you come across a topic you're not familiar with, -you can check here. - -endprologue. - -h3. Acceptance Testing - -Acceptancing testing is the act of testing use cases. Test cases are written -in a way that describes a use case. Then a test case is passing it can be -accepted. Cucumber is a good tool for acceptance testings. Work with your -stake holder to develop tests that represent use cases. When the test is -complete the feature should be accepted. Acceptance testing is focused -around people outside the code development accepting features. - -h3. Application Servers: Thin, Passenger, Unicorn - -These are all application servers. They interact with your Ruby code -and respond to requests. They are integrated with web servers like Nginx -or Apache to server you application on the internet. Some also serve -the application by itself. You can +rackup+ a rack app and serve it with -Thin right away. - -h3. Assets - -Assets are static files that are part of your application. They include: images, sytlesheets, scripts, or fonts. -Essentially, anything that needs to be server with your code for your app to run is -an asset. The asset pipeline gives you an easy way to manage all the different files. - -h3. Authentication - -Authentication is the process of matching credentials to a person and -verifying them. Authentication is purely about identifiying who the -user is–and not what they can do. -"Sorcery":https://github.com/NoamB/sorcery is an example of an authentication library. - -h3. Authorization - -Authorization is the process for determine what a specific user can do. -Authorization usually involves permission or role based systems. -"CanCan":https://github.com/ryanb/cancan is an example of an authorization library. - -h3. Behavior Driven Development (BDD) - -Is essentially the same as TDD except using a different set of tools -to express code in terms of user facing behavior. -"Rspec":https://github.com/rspec/rspec and "Cucumber":https://github.com/cucumber/cucumber are part of the BDD toolbox. - -h3. Bundler - -Bundler reads a Gemfile and calculates a set of version requirements -to make all the specified gems live happily together. It will prevent -version conflicts and infamous ‘gem already activated error’. It allows -you to install git gems or standard gems from rubygems.org. It does -not require libraries, it simply makes them available. It is up to you -require them in your programs. However, Rails will automatically setup bundler when your application boots. - -h3. Capistrano - -Capistrano is a tool for executing command one groups of remote -(or local) serves over SSH. It is primary used to deploy -Ruby (on Rails) applications. It has support for multistage environments. -Example, staging and production. You can easily write your own -tasks similar to writing rake task. It is the preferred way deploy Rails applications. - -h3. Capybara - -Capybara is a gem designed to provide an abstraction layer between -different browser drivers. It is primarily used in integration testing -to interact with the web server. It provides an API to navigate between -pages, click buttons, fill in forms, and other user interactions. It has -adapters for many different browser drivers. Notable drivers include -Selenium, rack-test and webrat. It is primary used in acceptance testing. - -h3. CoffeeScript - -CoffeeScript is a JavaScript superset. It aims to solves some problems -with JavaScript. It has some syntatical sugar around creating colsures and -objects. It supports for splat arguments. CoffeeScript files are compiled -into JavaScript files. CoffeeScript is usually called CS. You'll often see -CS/JS in reference to CoffeeScript and Javascript. - -h3. Compass - -Compass is a library built around SASS abstractions. It provides mixins -for many common things like styling buttons and forms. It is also easy -to extend and comes with many built in functions. The blueprint CSS -framework is bundled by default. - -h3. Cucumber - -Cucumber is a test framework for creating plain english acceptance -tests. The tests can be executed automatically. Cucumber is used for -integration testing web applications. The test suite is often used in CI -(Continuous Integration). Cucumber uses a language called Gherkin to -parse files into lines and match them against regular expressions. -Regular expressions are matched with code blocks. Your test code lives -in these blocks. - -Cucumber tests are divided up into "Feature" files. Each feature has -many "scenarios." Features are like use cases. Scenarios are different -permutations of that use case. Here is an example Feature file: - -
-Feature: Make Widthdrawls from Accounts
-  As an account holder
-  I want to use my money
-  In order to use it buy thing
-
-  Background:
-    Given I have account under "RubyX"
-    And my account is activated
-
-  Scenario: There is enough money in my account
-    Given my account has "$1,000"
-    And I'm at the bank
-    When I widthdraw "$500"
-    Then my account should have "$500"
-
-  Scenario: There is not enough money in my account
-    Given my account has "$1,000"
-    And I'm at the bank
-    When I widthdraw "$500"
-    Then the teller should reject my transaction
-
- -Here is an example step definition: - - -Given /I'm at the bank/ do - # set up pre conditions -end - -Then /the teller should reject my transaction/ do - # assert on things -end - - -h3. DSL - -DSL stands for Domain Specific Language. They are crafted to solve one -or more problems very eloquently and nothing more. For example, a DSL -created to declare work order would be horrible suited for writing -Photoshop. DSLs are usually wrappers around more complicated methods -that make it easier to express the intent of the underlying code from -a programmer's perspective. You may have used a DSL before and -not realized it. Here is an example from Sunspot's search -functionality. It's designed for describing a search and nothing more: - - -Post.search do - fulltext 'best pizza' - with :blog_id, 1 - with(:published_at).less_than Time.now - order_by :published_at, :desc - paginate :page => 2, :per_page => 15 - facet :category_ids, :author_id -end - - -h3. ERB - -ERB is Embedded Ruby. ERB is built into the Ruby core. It allows to to -place Ruby inside other files. For example, placing Ruby inside HTML. -Here is an example: - - -
<%= @ticket.message %>

-
-
- -h3. Factories - FactoryGirl & Fabrication - -These are two popular libraries for creating object factories. They are -usually used in test suites and population scripts. They provide a -default set of attributes and allow programmers to specify the -attributes they care about at creation time. Factories are commonly used -to replace fixtures. - -h3. Fixtures - -Fixtures are static objects used in test cases. You may have a fixtures for specific -test cases to build up needed preconditions. Fixtures are commonly used to represent -data in a table. Fixtures are stored in YML and are loaded by a test library. -Fixtures become hard to main at scale. They are often replaced with Factories because -it's easier to generate an object at runtime then maintain a static file with its -attributes. - -h3. Gem - -A gem is a resuable library of Ruby code. Gems are hosted on "RubyGems":http://rubygems.org. -They are managed with the +gem+ command or with bundler. Rails is -distributed as a gem. - -h3. Git - -Git is a distributed version control system. Each user has a complete -copy of the repository. Changes can be pushed back to the remote -repositories for others to pull or push from. Linus Torvalds created Git -because he was unsatisfied with other version control systems like CVS -or SVN. Do not get GitHub confused with Git. GitHub is simply a service -for hosting the main Git repository. You can use git independent of -github, however most Ruby developers use github exclusively. - -h3. HAML - -HAML is an HTML abstraction language. It's great for structuring -documents and horrible to content. It will autoclose tags and lets you -specify attributes as a hash. You can also include ruby code inside -the templates. Here is an example: - -
-.post#post_5 
-  .content= simple_format(@post.content)
-
- -h3. Heroku - -Ruby PaaS (Platform as a Service). They provide free cloud hosting for -Rack applications with paid plans for increased resources. It is a very -easy way to deploy your first application. Beware, they are easily owned -by Amazon's AWS failure. - -h3. Integration Testing - -Integration testing referes testing different modules of code in concert. -Ingration testing tests that all the parts of your system are working correctly. -It is different than unit testing because it involves more than one component -at at time. Integration tests for rails apps usually mean submitting web requests -and see how they are handled. You can take this a step further and move into -acceptance testing which simulates a user in front of your application. -Integration tests are written "outside in" meaning they only focus on -the outward functions of your system. - -h3. Less - -Less is a library for writing stylesheets. It enables you to do things -like use variables and other handy things. Less files are compiled into -vanilla CSS files. It is similar to SCSS/SASS. Twitter Bootstrap is written in Less. - -h3. Metaprogramming - -Metaprogramming is a term for dynamically generating code at runtime. -Metaprogramming is why Rails feel the way it does. ActiveRecord -associations to dynamically add methods to your classed based on how to -declare them. Metaprogramming is possible in Ruby because it's a dynamic -language interpreted at run time. - -h3. Nonrelational Databases (NoSQL) - -Nonrelational databases are the oppposte of relational databases. They -are usually more free form and don't have defined schemas (like tables.) -There is no such thing as SQL for non relational databases because each -one uses it's own langauge to inster and retreive data. MonogDB is -the most popular nonrelationable database. - -h3. Open Classes & Monkey Patching - -Ruby has open classes. This means you can simply declare methods insides -a class that's already been defined. ActiveSupport uses open classes to -add all those nice methods to core Ruby objects. This is how you can add -a method to the `String` class: - - -class String - def lulz - puts "lulz " * self.length - end -end - -"Hey".lulz - - -h3. ORM - Object Relational Mapping - -ORM's provide a way to map one object into some sort of persistent storage. -ActiveRecord is a well known ORM that implements that Active Record pattern. -ActiveRecord allows you persist objects into a relational database. ActiveRecord -is not the only ORM. Datamapper and Sequel are also popular for relational databases. -Mongoid is popular for MongoDB (a nonrelational database.) - -h3. Relational Databases - -Relational databases store data into tables with columns. Each column has a -type of data. For example: numbers, text, or dates. Data is retrieved -using SQL. ORM's are commonly used to make it easier to work with data -in retional databases. PostreSQL and MySQL are examples of popular -realtional databases to use with Rails. - -h3. Rack - -Rack is a standard interface for writing web applications in Ruby. -Rails as of version 3 is a Rack app. Rack defines things like HTTP requests -and how your code is called. Rack applications are easily served by application -servers such as Thin. - -h3. Rake - -Rake is like the Ruby version of make. You can create custom tasks that -can be executed from the command line. `rake db:migrate` is a classic -example. You can create as many tasks as you want. They can have -prerequisites. They can also be in namespaces. A ':' designates tasks in -different namespace. `db:migrate` means 'db' namespace, 'migrate' task. -Multiple tasks can be executed in one go like so: `rake db:create -schema:load`. They will be executed in the order they are listed. Rake -was originally designed to be like make, but is often used to execute -arbitrary code outside an application context. A cron job is a perfect -example. - -h3. RSpec - -Rspec is a unit testing framework. It is based around the idea that test -should describe behavior of classes in an english like way. Test files -are called "specs". Spec files are divided into "examples." Examples -contain matchers. Spec files can share examples. Here is an example -spec_file: - - -require 'spec_helper' - -describe Post do - it { should have_many(:comments) } - - describe "Post#out_dated?" do - subject { Post.new :created_at => 2.months.ago } - - it { should be_outdated } - end -end - - -h3. RVM - -Rvm stands for Ruby Version Manager. It is a set of bash script designed -to allow you switch out Ruby interpreters on the fly. It manages -installed ruby interpreters and makes is very easy to install different -implementations. It also manages Gemsets. Gemsets are groups of gemsets -that are distinct from other groups (except the global gemset which -shares gems between different ruby interpreters). - -h3. Rbenv - -Rbenv was created to address some flaws in RVM. It does the same thing -as RVM in a different way. It allows you manage different Ruby versions -and switch between them. - -h3. SASS & SCSS - -SASS and SCSS are CSS abstraction languages. They are compiled down to -CSS. They allow you use variables, modules and include other files. -In short, they make it much easier to write and main large amounts of -CSS. - -h3. SQL - Structured Query Language - -SQL is the standard language for talking to relational database. It's sole -purpose is to describe what to get from the db, and now how to get it. -SQL is based on simple concepts like selects and joins. You select columns -from tables that you want back. You can define conditions to further refine -your query or use joins to connect more than one table together. - -h3. Selenium - -Selenium is a library that simulates user interaction with a browser. It -runs the full browser. Selenium works best in FireFox, but can work in -Chrome and other browsers. Commands are sent across as JavaScript which -the browser evaluates to complete each action. Selenium is the most -complete solution for simulating a user for your web application. - -h3. Unit Testing - -Unit testing refers to testing small units of code insolation. This -makes it easier to determine if individual modules of code are functioning -directly. You can do unit testing with many different libraries. +Test::Unit+ -is the Rails default. - -h3. Test Driven Development (TDD) - -The practice of writing a failing test first then completing the -implementation. This makes the developer spend more time thinking about -the code upfront while providing a solid test suite for the entire -application. You can use Test::Unit for TDD in Ruby. - -h3. Test::Unit - -Test::Unit is a unit test framework built into Ruby 1.8. It is known as -MiniTest in 1.9. It provides functionality for writing test cases with -standard setup and tear down. Rails generates test files built in -Test::Unit by default. It provides basic assertions. It's similar to -jUnit or any member of the xUnit family. Here is an example: - - -require 'test_helper' - -class PostTest < Test::Unit::TestCase - - def test_out_dated? do - post = Post.new :created_at => 2.months.ago - assertTrue(post.out_dated?) - end -end - - -h3. UJS (Unobstrusive JavaScript) - -Unobtrusive JavaScript means separating JavaScript from the HTML. -Specifying an `onClick` attribute in HTML is consider obtrusive because -it obfuscates the markup. It is also hard to maintain because your -javascript is harder to maintain. You can do the same thing -unobtrusively by using jQuery to find the element by a class name and -applying a click handler. Essentially UJS means keep JavaScript in .js -files and HTML in .html files. Separation of church and state if you -will. - -h3. Webrat - -Webrat is the original headless browser. It's similar to selenium, but -much more implemented. It does not execute JavaScript and does not -execute in a GUI. It is the most basic driver and is perfect for -interacting with simple websites. -- cgit v1.2.3