Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby on Rails User Confirmation not updating a parameter
    primarykey
    data
    text
    <p>In my application I have a user confirmation process. When a user signs up four things happen:</p> <ol> <li>An account_status_id is set to 1 (unconfirmed)</li> <li>The user is signed in (now current_user exists)</li> <li>A new_account_confirmation_token is generated</li> <li>A confirmation email is sent to the new user with a link that includes the new_account_confirmation_token</li> </ol> <p>I initially tried to handle the confirmation link with this method. It finds the user without issue and the code flows through the update_attributes! method, however it wasn't updating the account_status. From what I can tell it is due to the fact that the current_user object exists, therefore the user Im trying to update is already "in memory". Is that correct?</p> <pre><code> def new_account_confirmation @title = "Account Confirmation" logger.info("User is not logged in") @user = User.find_by_new_account_confirmation_token(params[:confirm_id]) if @user @user.update_attributes!(:account_status_id =&gt; 2) else redirect_to root_path end end </code></pre> <p>My work around is as follows. The code below works but I'd like to know why the code above doesn't work. Why won't it update the account_status?</p> <pre><code> def new_account_confirmation @title = "Account Confirmation" if current_user logger.info("User is logged in") current_user.update_attributes!(:account_status_id =&gt; 2) else logger.info("User is not logged in") @user = User.find_by_new_account_confirmation_token(params[:confirm_id]) if @user @user.update_attributes!(:account_status_id =&gt; 2) else redirect_to root_path end end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload