title: Rails forms do not submit when I load them from a link
body: <p>I have a strange problem with my rails app. I have several forms not working when I try to submit them coming from a direct link. For example, if I click on "log in" from the home page, it does not work. But if I refresh the page, then I can submit the form. Any idea what's the problem?</p>
  
  <p>Log in view new.html.erb:</p>
  
  <pre><code>&lt;div class="main-container form"&gt;
    &lt;h2&gt;Log in&lt;/h2&gt;
  
    &lt;div class="form-fields"&gt;
  
    &lt;%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %&gt;
      &lt;div class="field"&gt;
        &lt;%= f.label :email %&gt;&lt;br /&gt;
        &lt;%= f.email_field :email, autofocus: true %&gt;
      &lt;/div&gt;
  
      &lt;div class="field"&gt;
        &lt;%= f.label :password %&gt;&lt;br /&gt;
        &lt;%= f.password_field :password, autocomplete: "off" %&gt;
      &lt;/div&gt;
  
      &lt;% if devise_mapping.rememberable? %&gt;
        &lt;div class="field"&gt;
          &lt;%= f.check_box :remember_me %&gt;
          &lt;%= f.label :remember_me %&gt;
        &lt;/div&gt;
      &lt;% end %&gt;
  
    &lt;/div&gt;
  
      &lt;div class="footer-form"&gt;
        &lt;div class="actions"&gt;
          &lt;%= f.submit "Log in", class: 'cta' %&gt;
        &lt;/div&gt;
        &lt;div class="links-form"&gt;
          &lt;%= render "devise/shared/links" %&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>User model:</p>
  
  <pre><code>class User &lt; ApplicationRecord
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable, :validatable
  
    has_many :review
  
    before_create :add_random_id
    private
    def add_random_id
      self.random_id = SecureRandom.uuid unless self.random_id
    end
  
  end
  </code></pre>
  
  <p>Routes:</p>
  
  <pre><code>devise_for :users, controllers: {registrations: 'registrations'}
  </code></pre>
  
  <p>Thank you.</p>