[RUBY] 11.1 AccountActivations Resources: Rails Tutorial Notes-Chapter 11

11.1 AccountActivations resource

11.1.1 AccountActivations Controller

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.

is the path helper (_path) returning a relative path? Absolute pass? : Rails tutorial memorandum --Qiita

11.1.2 Account Activation data model

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

Why you need attr_accessor and why you don't (Thanks to Rails): Rails tutorial memorandum --Chapter 9 --Qiita

Enable sample user and fixture

$ rails test > (GREEN)

Recommended Posts

11.1 AccountActivations Resources: Rails Tutorial Notes-Chapter 11
rails tutorial
rails tutorial
rails tutorial
rails tutorial
rails tutorial
rails tutorial
rails tutorial
Piped together grep ?: Rails Tutorial Notes--Chapter 8
rails tutorial Chapter 6
Rails tutorial test
rails tutorial Chapter 1
Rails tutorial memorandum 1
Rails tutorial memorandum 2
rails tutorial Chapter 7
Testing for Error Messages: Rails Tutorial Notes-Chapter 7
rails tutorial Chapter 5
rails tutorial Chapter 10
rails tutorial Chapter 9
rails tutorial Chapter 8
Start Rails Tutorial
[Beginner] Rails Tutorial
11.2 Send Account Activation Email: Rails Tutorial Notes--Chapter 11
Rails Tutorial Chapter 10 Notes
Rails Tutorial Chapter 3 Notes
Rails Tutorial cheat sheet
Rails Tutorial Chapter 3 Learning
[Rails] Learning with Rails tutorial
Rails Tutorial Memorandum (Chapter 3, 3.1)
Rails Tutorial Chapter 4 Notes
Rails Tutorial Chapter 4 Learning
Rails Tutorial Chapter 1 Learning
Rails Tutorial Chapter 2 Learning
Rails Tutorial Chapter 8 Notes
rails tutorial fighting notes Ⅲ
Rails Tutorial Memorandum (Chapter 3, 3.3.2)
I changed the way Rails tutorials run: Rails Tutorial Notes-Chapter 9
Rails: Difference between resources and resources
Rails Tutorial Records and Memorandum # 0
Rails Tutorial (4th Edition) Summary
[Rails Tutorial Chapter 4] Rails-flavored Ruby
[Rails] Implementation of tutorial function
[Rails Struggle/Rails Tutorial] Summary of Rails Tutorial Chapter 2
[Rails Tutorial Chapter 5] Create a layout
rails tutorial chapter 10 summary (for self-learning)
Chewing Rails Tutorial [Chapter 2 Toy Application]
[Rails 6] destroy using the resources method
Rails Tutorial (4th Edition) Memo Chapter 6