我最近将我的Rails webapp与Redis / Sidekiq集成在一起。玩了很多配置后,我意识到我可能搞砸了一些东西,因为我无法再登录我的应用程序了。在引用这个问题之后:Devise: Suddenly cannot log in anymore我认为它与我的config / initializers / session_store.rb有关,但我想是因为我不清楚该文件的运行方式是多么困难我调试这个错误。
当我尝试使用良好的凭据登录时,这是实际的错误消息:
ActionController::UrlGenerationError in Devise::SessionsController#create
No route matches {:action=>"show", :controller=>"controllers"} missing required keys: [:id]
这是我的session_store.rb:
Rails.application.config.session_store :cookie_store, key: '_appname_session'
AppName::Application.config.session_store :redis_store, servers: "redis://localhost:6379/0/session"
这是我的routes.rb文件:
Rails.application.routes.draw do
resources :controllers
devise_for :users
require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'
end
引用此链接:What is called session store?我知道会话存储只是存储会话信息,但我不确定这是如何转换为此设计错误的。
我也有正确的设计初始化文件,在我的config / environments / development.rb中我有
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
根据文档。
设计初始化程序:
config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' #haven't yet had the need to change this
config.secret_key = 'secret_key'
require 'devise/orm/active_record'
config.case_insensitive_keys = [:email]
config.strip_whitespace_keys = [:email]
config.skip_session_storage = [:http_auth]
config.stretches = Rails.env.test? ? 1 : 11
config.reconfirmable = true
config.expire_all_remember_me_on_sign_out = true
config.password_length = 6..128
config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
config.reset_password_within = 6.hours
config.sign_out_via = :delete
end
控制器'控制器' - >这对我来说真的很奇怪。我不记得自己做这个,我不确定它是否是我所遵循的其他一些过程的副产品,但不知何故最终在我的应用程序中。发现如下:
class ControllersController < ApplicationController
before_action :set_controller, only: [:show, :edit, :update, :destroy]
# GET /controllers
# GET /controllers.json
def index
@controllers = Controller.all
end
# GET /controllers/1
# GET /controllers/1.json
def show
end
# GET /controllers/new
def new
@controller = Controller.new
end
# GET /controllers/1/edit
def edit
end
# POST /controllers
# POST /controllers.json
def create
@controller = Controller.new(controller_params)
respond_to do |format|
if @controller.save
format.html { redirect_to @controller, notice: 'Controller was successfully created.' }
format.json { render :show, status: :created, location: @controller }
else
format.html { render :new }
format.json { render json: @controller.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /controllers/1
# PATCH/PUT /controllers/1.json
def update
respond_to do |format|
if @controller.update(controller_params)
format.html { redirect_to @controller, notice: 'Controller was successfully updated.' }
format.json { render :show, status: :ok, location: @controller }
else
format.html { render :edit }
format.json { render json: @controller.errors, status: :unprocessable_entity }
end
end
end
# DELETE /controllers/1
# DELETE /controllers/1.json
def destroy
@controller.destroy
respond_to do |format|
format.html { redirect_to controllers_url, notice: 'Controller was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_controller
@controller = Controller.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def controller_params
params.require(:controller).permit(:Reminder)
end
end
非常感谢有关调试此错误的帮助!
答案 0 :(得分:0)
Firstly, you don't need to config your session_store to use redis.
Secondly, you config it twice in session_store.rb
.
I suggest you use gem redis-rails
to config redis easily: https://github.com/redis-store/redis-rails