Я пытаюсь настроить страницу администратора, используя Devise
и Rails_Admin
гемы. Я установил devise
и создал rails g devise USER
. Я создал current_user
проверку в макетах приложений и настроил маршруты в соответствии с инструкциями Devise и учебником, которому я следую здесь: https://blog.codeplace.com/building-an-admin-panel-for-your-rails-app-d672159eb26e
Знайте, что у меня были сессии DIY / аутентификации, идущие доно избавились от этого трубопровода. Я также использую 2 базы данных: одну локальную postgresql и одну удаленную AWS RDS.
Когда я пытаюсь нажать home#index
, я получаю следующую ошибку в браузере:
We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
В терминале ошибка:
Started GET "/users/sign_in" for ::1 at 2019-11-06 12:47:03 -0500
(28.6ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
Processing by Devise::SessionsController#new as HTML
Rendering devise/sessions/new.html.erb within layouts/application
Rendered devise/shared/_links.html.erb (Duration: 2.0ms | Allocations: 626)
Rendered devise/sessions/new.html.erb within layouts/application (Duration: 141.2ms | Allocations: 177808)
Completed 500 Internal Server Error in 633ms (ActiveRecord: 31.4ms | Allocations: 257294)
Не уверенесли что-то не так в представлениях или контроллере, но я все обыскал и не могу найти решение. Вот мой Rails MVC, database.yml и маршруты:
Модель:
class User < ApplicationRecord
establish_connection(:local)
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
end
controllers / application_controller.rb:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
end
controllers / home_controller.rb:
class HomeController < ApplicationController
def index
byebug
if current_user
redirect_to search_path
end
end
end
views / application_layout.html.erb:
<!DOCTYPE html>
<html>
<head>
<title>Tml App</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> -->
<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> -->
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<!-- <%= image_tag 'logo.png', :style => 'width:50%; height:50%;' %> -->
</head>
<body>
<div class="container">
<div class="row justify-content-start">
<div class="col-5">
<%= image_tag 'logo-2.png', id: 'logo' %>
</div>
<div class="col-4 justify-content-center">
<% if flash %>
<% flash.each do |key, value| %>
<div class="<%= flash_class(key) %>" id="error">
<%= value %>
</div>
<% end %>
<% else %>
<% flash.discard %>
<% end %>
</div>
<div class="col-3">
<% if current_user %>
<%= link_to “Logout”, destroy_user_session_path, method: :delete %>
<% else %>
<%= link_to “Login”, new_user_session_path %>
<% end %>
</div>
</div>
<%= yield %>
</div>
</body>
</html>
Маршруты:
Rails.application.routes.draw do
devise_for :users
root 'home#index'
get 'searches/index' => "searches#index"
get 'searches/show' => "searches#show"
get 'searches/search' => "searches#search", as: 'search'
get 'audits/show' => 'audits#show'
get 'audits/download' => 'downloads#show'
post 'audits/' => 'audits#create'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
и мой файл database.yml на случай, если это может вызватьпроблемы?
default: &default
adapter: postgresql
encoding: unicode
database: tml_portal
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
aws:
adapter: mysql2
encoding: utf8
database: requests
username: <%= Rails.application.credentials[:aws_username] %>
password: <%= Rails.application.credentials[:aws_password] %>
host: <%= Rails.application.credentials[:aws_host] %>
cast: false
port: 3306
local:
<<: *default
production:
aws:
adapter: mysql2
encoding: utf8
database: requests
username: <%= Rails.application.credentials[:aws_username] %>
password: <%= Rails.application.credentials[:aws_password] %>
host: <%= Rails.application.credentials[:aws_host] %>
cast: false
port: 3306
local:
<<: *default
test:
aws:
adapter: mysql2
encoding: utf8
database: requests
username: <%= Rails.application.credentials[:aws_username] %>
password: <%= Rails.application.credentials[:aws_password] %>
host: <%= Rails.application.credentials[:aws_host] %>
cast: false
port: 3306
local:
<<: *default