【发布时间】:2016-07-11 17:27:40
【问题描述】:
我最近将我的 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
Controller 'controllers'--> 这对我来说真的很奇怪。我不记得自己做了这个,我不确定它是否是我遵循的其他过程的副产品,但不知何故最终出现在我的申请中。在下面找到:
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
不胜感激有关调试此错误的帮助!
【问题讨论】:
-
您的应用程序/控制器中是否有类似
ControllersController的内容?您也可以发布您的设计初始化程序吗? -
我在上面的帖子中添加了这个信息!
标签: ruby-on-rails ruby devise redis sidekiq