简体   繁体   中英

Rails devise: how to allow guest user to add a record then confirm the record only after sign up confirmation

How to allow guest user to add a record to DB, then confirm the record only after sign up confirmation?

More details:

I want to allow guest user to submit a review, then I want to save it in database with a flag that it is unconfirmed, after making the review I want to require user to sign up & then I will send him a confirmation email (normal devise sign-up & confirm flow)

Is there any default/preferred way to achieve this?

I have looked everywhere but I can't see this use case for devise/rails

You have some callbacks that you can use with Devise, the one that will interest you is after confirmation .

For instance:

class User < ApplicationRecord
  # ...
  has_many :reviews
  # ...

  def after_confirmation
    super
    # associate the pending unassociated review
    reviews << Review.where(guest_user_nickname: nickname)
    # update the status of the review
    reviews.update(confirmed: true)
  end
end

See https://github.com/plataformatec/devise/wiki/Callbacks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM