Weird Caching / Devise Issue - Have to restart server for user signup to work

30 views Asked by At

I have this issue on a new site I'm working on where I can sign-up as a new user without any problems, but then when I log out and then try to sign-up as another new user (for testing purposes), the sign-up button doesn't do anything - nothing in the logs and this happens on both dev and prod. When I do a server restart, I can then sign-up a new user again with no problems (same behaviour on dev and prod).

Login/logout/login works fine.

I use Devise and have a fairly standard setup.

Really scratching my head on this one, so any tips welcome!

User model setup:

# frozen_string_literal: true

class DeviseCreateUsers < ActiveRecord::Migration[7.1]
  def change
    create_table :users do |t|
      ## Database authenticatable
      t.string :email,              null: false, default: ""
      t.string :encrypted_password, null: false, default: ""

      ## Recoverable
      t.string   :reset_password_token
      t.datetime :reset_password_sent_at

      ## Rememberable
      t.datetime :remember_created_at

      ## Trackable
      t.integer  :sign_in_count, default: 0, null: false
      # t.datetime :current_sign_in_at
      t.datetime :last_sign_in_at
      # t.string   :current_sign_in_ip
      # t.string   :last_sign_in_ip

      ## Confirmable
      # t.string   :confirmation_token
      # t.datetime :confirmed_at
      # t.datetime :confirmation_sent_at
      # t.string   :unconfirmed_email # Only if using reconfirmable

      ## Lockable
      # t.integer  :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
      # t.string   :unlock_token # Only if unlock strategy is :email or :both
      # t.datetime :locked_at
      t.string :user_alias
      t.string :location
      t.string :user_classification
      t.integer :role, default: 0
      
      t.string :interests
      t.string :hobbies
      t.string :meet_status
      t.string :age_group
      
      t.boolean :open_to_contact, default: 1

      t.timestamps null: false
    end

    add_index :users, :email,                unique: true
    add_index :users, :reset_password_token, unique: true
    # add_index :users, :confirmation_token,   unique: true
    # add_index :users, :unlock_token,         unique: true
  end
end

Registration controller:

# frozen_string_literal: true

class Users::RegistrationsController < Devise::RegistrationsController
  before_action :configure_account_update_params, only: [:update]
  # before_action :configure_sign_up_params, only: [:create]
  # before_action :configure_account_update_params, only: [:update]

    def sign_up_params
      params.require(:user).permit(:email, :password, :user_alias, :location, :age_group, :hobbies, :interests, :open_to_contact, :meet_status, :icon, :newsletter, :notification_events, :notification_discussion, :gender, :relationship_status)
    end

  # GET /resource/sign_up
  # def new
  #   super
  # end

  # POST /resource
  # def create
  #   super
  # end

  # GET /resource/edit
  # def edit
  #   super
  # end

  # PUT /resource
  # def update
  #   super
  # end

  # DELETE /resource
  # def destroy
  #   super
  # end

  # GET /resource/cancel
  # Forces the session data which is usually expired after sign
  # in to be expired now. This is useful if the user wants to
  # cancel oauth signing in/up in the middle of the process,
  # removing all OAuth session data.
  # def cancel
  #   super
  # end

  protected


  def configure_account_update_params
    devise_parameter_sanitizer.permit(:account_update, keys: [:email, :password, :user_alias, :location, :age_group, :hobbies, :interests, :open_to_contact, :icon, :meet_status, :password_confirmation, :current_password, :newsletter, :notification_events, :notification_discussion, :gender, :relationship_status])
  end
  
  def after_update_path_for(resource)
    user_profile_path # Assuming you have a user_profile_path route set up
  end

  # If you have extra params to permit, append them to the sanitizer.
  # def configure_sign_up_params
  #   devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])
  # end

  # If you have extra params to permit, append them to the sanitizer.
  # def configure_account_update_params
  #   devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
  # end

  # The path used after sign up.
  # def after_sign_up_path_for(resource)
  #   super(resource)
  # end

  # The path used after sign up for inactive accounts.
  # def after_inactive_sign_up_path_for(resource)
  #   super(resource)
  # end
end

User sign-up view:

<div class="mx-auto max-w-4xl px-4 sm:px-6 lg:px-8">

<article class="prose align-top" style="margin-top:0">
  <h1>Sign-up</h1>
</article>

  <div class="space-y-12">
    <div class="border-b border-gray-900/10 pb-12">

    <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
      <%= render "devise/shared/error_messages", resource: resource %>

      <div class="mt-10 grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
        
        <div class="sm:col-span-4">
          <label for="email" class="block text-sm font-medium leading-6 text-gray-900">Email address</label>
          <div class="mt-2">
             <%= f.email_field :email, autofocus: true, autocomplete: "email", class: "pl-4 block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" %>
          </div>
        </div>

        <div class="sm:col-span-4">
          <label for="user_alias" class="block text-sm font-medium leading-6 text-gray-900">Username</label>
          <div class="mt-2">
            <%= f.text_field :user_alias, autocomplete: "user_alias", class: "pl-4 block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" %>
          </div>
        </div>

        <div class="sm:col-span-4">
          <label for="location" class="block text-sm font-medium leading-6 text-gray-900">Where are you based?</label>
          <div class="mt-2">
            <%= f.text_field :location, autocomplete: "location", class: "pl-4 block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" %>
          </div>
        </div>

        <div class="sm:col-span-4">
          <label for="gender" class="block text-sm font-medium leading-6 text-gray-900 mb-2">Gender</label>
          <%= f.select :gender, options_for_select([
              ['', ''],
              ['Female', 'Female'],
              ['Male', 'Male'],
              ['Other', 'Other'],
              ['Prefer not to say', 'Prefer not to say']
            ]), {}, class: "pl-4 block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:max-w-xs sm:text-sm sm:leading-6" %>
        </div>
        
        <div class="sm:col-span-4">
          <label for="age_group" class="block text-sm font-medium leading-6 text-gray-900 mb-2">Age group</label>
          <%= f.select :age_group, options_for_select([
              ['20-25', '20-25'],
              ['25-30', '25-30'],
              ['30-40', '30-40'],
              ['40-50', '40-50'],
              ['50-60', '50-60'],
              ['60+', '60+']
            ]), {}, class: "pl-4 block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:max-w-xs sm:text-sm sm:leading-6" %>
        </div>

        <div class="sm:col-span-4">
          <label for="relationship_status" class="block text-sm font-medium leading-6 text-gray-900 mb-2"> Status</label>
          <%= f.select :relationship_status, options_for_select([
              ['', ''],
            ]), {}, class: "pl-4 block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:max-w-xs sm:text-sm sm:leading-6" %>
        </div>
        
        <div class="col-span-full">
          <label for="interests" class="block text-sm font-medium leading-6 text-gray-900">About</label>
          <div class="mt-2">
            <%= f.text_area :interests, rows:3, autocomplete: "interests", class: "pl-4 block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" %>
          </div>
        </div>


        <div class="col-span-full">
          <label for="icon" class="block text-sm font-medium leading-6 text-gray-900">Icon (photo upload coming soon)</label>
          <div class="mt-2 flex items-center gap-x-3 flex-wrap">
      
        
              <%= f.label :icon, class: "icon-label", style: "background-image: url(/assets/user_placeholder.webp)" do %>
                <%= f.radio_button :icon, "user_placeholder.webp", style: "margin-left: 50px;", checked: true %>
              <% end %>
          </div>
        </div>

      </div>
    </div>

    <div class="border-b border-gray-900/10 pb-12">
      <h2 class="text-base font-semibold leading-7 text-gray-900">Notifications</h2>
      <p class="mt-1 text-sm leading-6 text-gray-600">We'll always let you know about important changes, but you pick what else you want to hear about.</p>

      <div class="mt-10 space-y-10">
        <fieldset>
          <legend class="text-sm font-semibold leading-6 text-gray-900">By Email</legend>
          <div class="mt-6 space-y-6">
            <div class="relative flex gap-x-3">
              <div class="flex h-6 items-center">
                <%= f.check_box :notification_discussion, as: :boolean, class: "h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600" %>
              </div>
              <div class="text-sm leading-6">
                <label for="comments" class="font-medium text-gray-900">Comments</label>
                <p class="text-gray-500">Get notified when someones posts a comment on a discussion post you made.</p>
              </div>
            </div>
            <div class="relative flex gap-x-3">
              <div class="flex h-6 items-center">
                <%= f.check_box :notification_events, as: :boolean, class: "h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600" %>
              </div>
              <div class="text-sm leading-6">
                <label for="candidates" class="font-medium text-gray-900">Events</label>
                <p class="text-gray-500">Receive updates to events you have registered to attend.</p>
              </div>
            </div>
            <div class="relative flex gap-x-3">
              <div class="flex h-6 items-center">
                <%= f.check_box :newsletter, as: :boolean, class: "h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600" %>
              </div>
              <div class="text-sm leading-6">
                <label for="offers" class="font-medium text-gray-900">Newsletter</label>
                
                <p class="text-gray-500">Receive our monthly newsletter.</p>
              </div>
            </div>
          </div>
        </fieldset>
        
      </div>
    </div>
    
      <div class="field">
          <label for="region" class="block text-sm font-medium leading-6 text-gray-900">Password (<%= @minimum_password_length %> characters minimum)</label>
          <%= f.password_field :password, autocomplete: "new-password", class: "input input-bordered w-full" %>
      </div>
      
      <div class="field">
          <label for="region" class="block text-sm font-medium leading-6 text-gray-900">Password confirmation</label>
          <%= f.password_field :password_confirmation, autocomplete: "new-password", class: "input input-bordered w-full" %>
      </div>
    
      <div class="actions">
        <%= f.submit "Sign up", class: "btn btn-primary", style:"background-color:blue;color:white" %>
      </div>
  </div>

<% end %>

<style>.icon-label {
  display: inline-block;
  width: 50px; /* Adjust as needed */
  height: 50px; /* Adjust as needed */
  background-size: cover;
  background-position: center;
  margin-right: 30px;
}</style>

</div>
0

There are 0 answers