Resouces
used in routing can be used in a limited way with ʻonly`
resources :account_activations, only: [:edit]
Exercise
The named routes in Table 11.2 state that _url should be used instead of _path. Why? Think about it. Tip: We will now use the named route in emails.
You need to have a full path because you can only go with a path (URL) that can be accessed from outside the server.
The root relative path returned by _path
or the relative path cannot be used.
Added 3 attributes to User model
$ rails generate migration add_activation_to_users \
> activation_digest:string activated:boolean activated_at:datetime
ʻActivated gives
false` by default
class AddActivationToUsers < ActiveRecord::Migration[6.0]
def change
add_column :users, :activation_digest, :string
add_column :users, :activated, :boolean, default: false #Initial value false
add_column :users, :activated_at, :datetime
end
end
Call the method that assigns the ʻactivation_token and ʻactivation_digest
attributes in advance with before_create
before_create :create_activation_digest
def create_activation_digest
self.activation_token = User.new_token
self.activation_digest = User.digest(activation_token)
end
ʻActivation_token is an attribute that is not in the model Requires ʻattr_accessor
attr_accessor :remember_token, :activation_token #Can be written in one line
Enable sample user and fixture
$ rails test
> (GREEN)
Recommended Posts