Chapter 7
7.1.1
Ex1)
controller: static_pages
action: about
Ex2)
irb(main):002:0> puts user.attributes.to_yaml
---
id: 1
name: Issao
email: [email protected]
created_at: !ruby/object:ActiveSupport::TimeWithZone
utc: &1 2017-09-23 16:26:39.365744000 Z
zone: &2 !ruby/object:ActiveSupport::TimeZone
name: Etc/UTC
time: *1
updated_at: !ruby/object:ActiveSupport::TimeWithZone
utc: &3 2017-09-23 16:26:39.365744000 Z
zone: *2
time: *3
password_digest:
=> nil
irb(main):003:0> y user.attributes
---
id: 1
name: Issao
email: [email protected]
created_at: !ruby/object:ActiveSupport::TimeWithZone
utc: &1 2017-09-23 16:26:39.365744000 Z
zone: &2 !ruby/object:ActiveSupport::TimeZone
name: Etc/UTC
time: *1
updated_at: !ruby/object:ActiveSupport::TimeWithZone
utc: &3 2017-09-23 16:26:39.365744000 Z
zone: *2
time: *3
password_digest:
=> nil
7.1.2
Ex1)
<%= @user.created_at %>, <%= @user.updated_at %>
Ex2)
Display the current time
7.1.4
Ex1)
irb(main):003:0> Digest::MD5::hexdigest(user.email.downcase)
=> "bb802b83e9c0688408abc77095c70676"
Ex2)
Yes.
Ex3)
Rails is already reading the components of the Def and can recognize without {} or without setting directly.
7.2.1
Ex1)
undefined method `nome' for #<User:0x00000003e381b0>
Ex2)
In that case it`s just a local variable being used and for convention is used f.
Using foobar works, but isn`t legible.
7.3.2
Ex2)
admin: '1'
controller: users
action: new
7.3.3
Ex1)
Yes, it changes automatically.
Ex2)
Because they need an action to to verify the fields, so them displays the errors.
7.3.4
Ex2)
Both cases use /signup now. The test goes green.
Ex3)
No.
Ex4)
Tested.
7.4.1
Ex1) You create a variable where contain the informations of the user and save those infos in the db with the create.
Ex2) Confirmed.
7.4.3
Ex1)
irb(main):001:0> User.find_by(email: "[email protected]")
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."email" = ? LIMIT ? ["email", "[email protected]"], ["LIMIT", 1](/nortonbino/sample_app/wiki/"email",-"[email protected]"],-["LIMIT",-1)
=> #<User id: 2, name: "Norton", email: "[email protected]", created_at: "2017-09-26 15:45:08", updated_at: "2017-09-26 15:45:08", password_digest: "$2a$10$5m95QT8ChX/IFMXQAF1k4uAZ19CRab/AOUNzuXDnvzA...">
Ex2) Yes.
7.5.3