Skip to content

Commit 96a8755

Browse files
Aditya BhutaniAditya Bhutani
authored andcommitted
[ci skip] Improved Action View Overview
1 parent 6d3acaf commit 96a8755

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

guides/source/action_view_overview.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ What is Action View?
1616

1717
In Rails, web requests are handled by [Action Controller](action_controller_overview.html) and Action View. Typically, Action Controller is concerned with communicating with the database and performing CRUD actions where necessary. Action View is then responsible for compiling the response.
1818

19-
Action View templates are written using embedded Ruby in tags mingled with HTML. To avoid cluttering the templates with boilerplate code, a number of helper classes provide common behavior for forms, dates, and strings. It's also easy to add new helpers to your application as it evolves.
19+
Action View templates are written using embedded Ruby in tags mingled with HTML. To avoid cluttering the templates with boilerplate code, several helper classes provide common behavior for forms, dates, and strings. It's also easy to add new helpers to your application as it evolves.
2020

2121
NOTE: Some features of Action View are tied to Active Record, but that doesn't mean Action View depends on Active Record. Action View is an independent package that can be used with any sort of Ruby libraries.
2222

2323
Using Action View with Rails
2424
----------------------------
2525

26-
For each controller there is an associated directory in the `app/views` directory which holds the template files that make up the views associated with that controller. These files are used to display the view that results from each controller action.
26+
For each controller, there is an associated directory in the `app/views` directory which holds the template files that make up the views associated with that controller. These files are used to display the view that results from each controller action.
2727

2828
Let's take a look at what Rails does by default when creating a new resource using the scaffold generator:
2929

@@ -44,7 +44,7 @@ $ bin/rails generate scaffold article
4444

4545
There is a naming convention for views in Rails. Typically, the views share their name with the associated controller action, as you can see above.
4646
For example, the index controller action of the `articles_controller.rb` will use the `index.html.erb` view file in the `app/views/articles` directory.
47-
The complete HTML returned to the client is composed of a combination of this ERB file, a layout template that wraps it, and all the partials that the view may reference. Within this guide you will find more detailed documentation about each of these three components.
47+
The complete HTML returned to the client is composed of a combination of this ERB file, a layout template that wraps it, and all the partials that the view may reference. Within this guide, you will find more detailed documentation about each of these three components.
4848

4949

5050
Templates, Partials, and Layouts
@@ -150,7 +150,7 @@ end
150150

151151
[Jbuilder](https://github.com/rails/jbuilder) is a gem that's
152152
maintained by the Rails team and included in the default Rails `Gemfile`.
153-
It's similar to Builder, but is used to generate JSON, instead of XML.
153+
It's similar to Builder but is used to generate JSON, instead of XML.
154154

155155
If you don't have it, you can add the following to your `Gemfile`:
156156

@@ -182,7 +182,7 @@ more examples and information.
182182

183183
#### Template Caching
184184

185-
By default, Rails will compile each template to a method in order to render it. In the development environment, when you alter a template, Rails will check the file's modification time and recompile it.
185+
By default, Rails will compile each template to a method to render it. In the development environment, when you alter a template, Rails will check the file's modification time and recompile it.
186186

187187
### Partials
188188

@@ -268,7 +268,7 @@ we would do:
268268
<%= render partial: "product", object: @item %>
269269
```
270270

271-
With the `as` option we can specify a different name for the said local variable. For example, if we wanted it to be `item` instead of `product` we would do:
271+
With the `as` option, we can specify a different name for the said local variable. For example, if we wanted it to be `item` instead of `product` we would do:
272272

273273
```erb
274274
<%= render partial: "product", object: @item, as: "item" %>
@@ -282,7 +282,7 @@ This is equivalent to
282282

283283
#### Rendering Collections
284284

285-
It is very common that a template will need to iterate over a collection and render a sub-template for each of the elements. This pattern has been implemented as a single method that accepts an array and renders a partial for each one of the elements in the array.
285+
Commonly, a template will need to iterate over a collection and render a sub-template for each of the elements. This pattern has been implemented as a single method that accepts an array and renders a partial for each one of the elements in the array.
286286

287287
So this example for rendering all the products:
288288

@@ -298,7 +298,7 @@ can be rewritten in a single line:
298298
<%= render partial: "product", collection: @products %>
299299
```
300300

301-
When a partial is called with a collection, the individual instances of the partial have access to the member of the collection being rendered via a variable named after the partial. In this case, the partial is `_product`, and within it you can refer to `product` to get the collection member that is being rendered.
301+
When a partial is called with a collection, the individual instances of the partial have access to the member of the collection being rendered via a variable named after the partial. In this case, the partial is `_product`, and within it, you can refer to `product` to get the collection member that is being rendered.
302302

303303
You can use a shorthand syntax for rendering collections. Assuming `@products` is a collection of `Product` instances, you can simply write the following to produce the same result:
304304

@@ -371,14 +371,14 @@ View Paths
371371
----------
372372

373373
When rendering a response, the controller needs to resolve where the different
374-
views are located. By default it only looks inside the `app/views` directory.
374+
views are located. By default, it only looks inside the `app/views` directory.
375375

376-
We can add other locations and give them a certain precedence when resolving
376+
We can add other locations and give them certain precedence when resolving
377377
paths using the `prepend_view_path` and `append_view_path` methods.
378378

379379
### Prepend view path
380380

381-
This can be helpful for example, when we want to put views inside a different
381+
This can be helpful for example when we want to put views inside a different
382382
directory for subdomains.
383383

384384
We can do this by using:

0 commit comments

Comments
 (0)