mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove confusing json by default support and add json post example
This commit is contained in:
parent
3c2d5090b3
commit
1e78a12941
1 changed files with 8 additions and 1 deletions
|
@ -1106,7 +1106,7 @@ The `get` method kicks off the web request and populates the results into the `@
|
|||
* `headers`: for setting the headers that will be passed with the request.
|
||||
* `env`: for customizing the request environment as needed.
|
||||
* `xhr`: whether the request is Ajax request or not. Can be set to true for marking the request as Ajax.
|
||||
* `as`: for encoding the request with different content type. Supports `:json` by default.
|
||||
* `as`: for encoding the request with different content type.
|
||||
|
||||
All of these keyword arguments are optional.
|
||||
|
||||
|
@ -1122,6 +1122,13 @@ Another example: Calling the `:update` action for the last `Article`, passing in
|
|||
patch article_url(Article.last), params: { article: { title: "updated" } }, xhr: true
|
||||
```
|
||||
|
||||
One more example: Calling the `:create` action to create a new article, passing in
|
||||
text for the `title` in `params`, as JSON request:
|
||||
|
||||
```ruby
|
||||
post articles_path, params: { article: { title: "Ahoy!" } }, as: :json
|
||||
```
|
||||
|
||||
NOTE: If you try running `test_should_create_article` test from `articles_controller_test.rb` it will fail on account of the newly added model level validation and rightly so.
|
||||
|
||||
Let us modify `test_should_create_article` test in `articles_controller_test.rb` so that all our test pass:
|
||||
|
|
Loading…
Reference in a new issue