mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove unnecessary / confusing code in example
This commit is contained in:
parent
75afe19182
commit
da9031ae26
1 changed files with 2 additions and 11 deletions
|
@ -561,7 +561,7 @@ Note that while for session values you set the key to `nil`, to delete a cookie
|
||||||
Rendering xml and json data
|
Rendering xml and json data
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
ActionController makes it extremely easy to render `xml` or `json` data. If you generate a controller using scaffolding then it would look something like this:
|
ActionController makes it extremely easy to render `xml` or `json` data. If you've generated a controller using scaffolding, it would look something like this:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class UsersController < ApplicationController
|
class UsersController < ApplicationController
|
||||||
|
@ -576,7 +576,7 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
Notice that in the above case code is `render xml: @users` and not `render xml: @users.to_xml`. That is because if the input is not string then rails automatically invokes `to_xml` .
|
You may notice in the above code that we're using `render xml: @users`, not `render xml: @users.to_xml`. If the object is not a String, then Rails will automatically invoke `to_xml` for us.
|
||||||
|
|
||||||
Filters
|
Filters
|
||||||
-------
|
-------
|
||||||
|
@ -599,15 +599,6 @@ class ApplicationController < ActionController::Base
|
||||||
redirect_to new_login_url # halts request cycle
|
redirect_to new_login_url # halts request cycle
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# The logged_in? method simply returns true if the user is logged
|
|
||||||
# in and false otherwise. It does this by "booleanizing" the
|
|
||||||
# current_user method we created previously using a double ! operator.
|
|
||||||
# Note that this is not common in Ruby and is discouraged unless you
|
|
||||||
# really mean to convert something into true or false.
|
|
||||||
def logged_in?
|
|
||||||
!!current_user
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue