rails newbie here using devise to create users for my rails 6 app.
I followed the steps outlined here: https://github.com/heartcombo/devise but when I try to sign into my app, the log in button does nothing (with valid credentials of course). Nothing happens in my logs so theres nothing interesting to show. This also happens with the sign up button when you register a new user.
I have looked through many other SO pages but they are from the past and I wonder if rails 6 has a different solution.
Here is some relevant code:
app/models/user.rb:
class User < ApplicationRecord
has_many :user_stocks
has_many :stocks, through: :user_stocks
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
end
app/views/devise/registrations/new.html.erb (Same issue with the log in):
<h1><%= t('.sign_up') %></h1>
<div class="row">
<div class="col-9>"
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= bootstrap_devise_error_messages! %>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, autofocus: true, autocomplete: 'email', class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :password %>
<%= f.password_field :password, autocomplete: 'current-password', class: 'form-control' %>
<% if @minimum_password_length %>
<small class="form-text text-muted"><%= t('devise.shared.minimum_password_length', count: @minimum_password_length) %></small>
<% end %>
</div>
<div class="form-group">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, autocomplete: 'current-password', class: 'form-control' %>
</div>
<div class="form-group">
<%= f.submit t('.sign_up'), class: 'btn btn-primary' %>
</div>
<% end %>
<%= render 'devise/shared/links' %>
</div>
</div>
app/controllers/application.rb (This helper forces you to log in/sign up):
class ApplicationController < ActionController::Base
before_action :authenticate_user!
end
config/routes.rb:
Rails.application.routes.draw do
resources :user_stocks
devise_for :users
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
root to: 'welcome#index'
get 'my_portfolio', to: 'users#my_portfolio'
get 'search_stock', to: 'stocks#search'
end
db/migrate/[timestamp]_devise_create_users.rb:
# frozen_string_literal: true
class DeviseCreateUsers < ActiveRecord::Migration[6.0]
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.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
Logs provided here, I navigated to .../my_portfolio to demonstrate that it pushed me to the log in page, but when I enter valid credentials and press "log in", nothing happens in the logs.
$ rails s
Warning: the running version of Bundler (2.1.2) is older than the version that created the lockfile (2.1.4). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.1.4`.
=> Booting Puma
=> Rails 6.0.3.2 application starting in development
=> Run `rails server --help` for more startup options
config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
* development - set it to false
* test - set it to false (unless you use a tool that preloads your test environment)
* production - set it to true
Puma starting in single mode...
* Version 4.3.5 (ruby 2.7.0-p0), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
Use Ctrl-C to stop
Started GET "/users/sign_in" for ::1 at 2020-07-15 20:33:30 -0700
Processing by Devise::SessionsController#new as HTML
(0.8ms) SELECT sqlite_version(*)
Rendering devise/sessions/new.html.erb within layouts/application
Rendered devise/shared/_links.html.erb (Duration: 2.7ms | Allocations: 713)
Rendered devise/sessions/new.html.erb within layouts/application (Duration: 31.9ms | Allocations: 5455)
/Users/kevinjay/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/helper.rb:355: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/Users/kevinjay/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/sprockets-4.0.2/lib/sprockets/base.rb:118: warning: The called method `[]' is defined here
[Webpacker] Everything's up-to-date. Nothing to do
Rendered layouts/_navigation.html.erb (Duration: 3.0ms | Allocations: 112)
Rendered layouts/_messages.html.erb (Duration: 0.8ms | Allocations: 198)
Completed 200 OK in 154ms (Views: 125.9ms | ActiveRecord: 2.4ms | Allocations: 24815)
Started GET "/my_portfolio" for ::1 at 2020-07-15 21:35:15 -0700
Processing by UsersController#my_portfolio as HTML
Completed 401 Unauthorized in 5ms (Allocations: 388)
Started GET "/users/sign_in" for ::1 at 2020-07-15 21:35:16 -0700
Processing by Devise::SessionsController#new as HTML
Rendering devise/sessions/new.html.erb within layouts/application
Rendered devise/shared/_links.html.erb (Duration: 1.2ms | Allocations: 169)
Rendered devise/sessions/new.html.erb within layouts/application (Duration: 7.7ms | Allocations: 1077)
[Webpacker] Everything's up-to-date. Nothing to do
Rendered layouts/_navigation.html.erb (Duration: 0.1ms | Allocations: 5)
Rendered layouts/_messages.html.erb (Duration: 0.1ms | Allocations: 29)
Completed 200 OK in 79ms (Views: 72.8ms | Allocations: 6463)
Thank you, any help is hugely appreciated!