1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #13316 from JuanitoFatas/working-with-js

Improve document: working with javascript in rails [ci skip].
This commit is contained in:
Godfrey Chan 2013-12-14 03:30:29 -08:00
commit 068580d445

View file

@ -169,7 +169,7 @@ This will generate the following HTML:
</form>
```
Note the `data-remote='true'`. Now, the form will be submitted by Ajax rather
Note the `data-remote="true"`. Now, the form will be submitted by Ajax rather
than by the browser's normal submit mechanism.
You probably don't want to just sit there with a filled out `<form>`, though.
@ -194,7 +194,17 @@ is very similar to `form_for`. It has a `:remote` option that you can use like
this:
```erb
<%= form_tag('/posts', remote: true) %>
<%= form_tag('/posts', remote: true) do %>
...
<% end %>
```
This will generate the following HTML:
```html
<form accept-charset="UTF-8" action="/posts" data-remote="true" method="post">
...
</form>
```
Everything else is the same as `form_for`. See its documentation for full
@ -299,10 +309,10 @@ The `app/views/users/_user.html.erb` partial contains the following:
The top portion of the index page displays the users. The bottom portion
provides a form to create a new user.
The bottom form will call the create action on the Users controller. Because
The bottom form will call the `create` action on the `UsersController`. Because
the form's remote option is set to true, the request will be posted to the
users controller as an Ajax request, looking for JavaScript. In order to
service that request, the create action of your controller would look like
`UsersController` as an Ajax request, looking for JavaScript. In order to
serve that request, the `create` action of your controller would look like
this:
```ruby