- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在尝试访问 Questions#Show 时遇到了一个令人费解的错误。每当我重定向到 View 时,都会收到 500 内部服务器错误。根据我的服务器跟踪,问题出在“set_question”中的问题 Controller 中
Started GET "/questions/1" for 127.0.0.1 at 2020-02-01 18:57:34 +0100
Processing by QuestionsController#show as HTML
Parameters: {"id"=>"1"}
User Load (1.1ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
Question Load (3.5ms) SELECT `questions`.* FROM `questions` WHERE `questions`.`id` = 1 LIMIT 1
↳ app/controllers/questions_controller.rb:105:in `set_question'
Completed 500 Internal Server Error in 15ms (ActiveRecord: 4.6ms | Allocations: 3861)
TypeError - can't quote Rack::Session::SessionId:
class QuestionsController < ApplicationController
before_action :set_question, only: [:show, :edit, :update, :destroy]
impressionist :actions => [:show], unique: [:session_hash]
def index
end
def show
@answers = @question.answers.includes(:user).page(params[:page]).per(5)
end
def new
@question = Question.new
end
def edit
authorize @question
end
def create
@question = Question.new(question_params)
respond_to do |format|
if @question.save
format.html { redirect_to @question, notice: 'You have successfully asked a question!' }
format.json { render :show, status: :created, location: @question }
else
format.html { render :new }
format.json { render json: @question.errors, status: :unprocessable_entity }
end
end
end
def update
authorize @question
respond_to do |format|
if @question.update(question_params)
format.html { redirect_to @question, notice: 'Question successfully updated.' }
format.json { render :show, status: :ok, location: @question }
else
format.html { render :edit }
format.json { render json: @question.errors, status: :unprocessable_entity }
end
end
end
def destroy
authorize @question
@question.destroy
respond_to do |format|
format.html { redirect_to @questions_url, notice: 'Question successfully deleted.' }
format.json { head :no_content }
end
end
private
def set_question
@question = Question.find(params[:id])
end
def question_params
params.require(:question).permit(:title, :body, :tag_list).merge(user_id: current_user.id)
end
end
activerecord (6.0.2.1) lib/active_record/connection_adapters/abstract/quoting.rb:231:in `_quote'
activerecord (6.0.2.1) lib/active_record/connection_adapters/abstract/quoting.rb:18:in `quote'
activerecord (6.0.2.1) lib/arel/collectors/substitute_binds.rb:17:in `add_bind'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:703:in `visit_Arel_Nodes_BindParam'
activerecord (6.0.2.1) lib/arel/visitors/visitor.rb:31:in `visit'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:611:in `visit_Arel_Nodes_Equality'
activerecord (6.0.2.1) lib/arel/visitors/visitor.rb:31:in `visit'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:790:in `block in inject_join'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:788:in `each'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:788:in `each_with_index'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:788:in `inject_join'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:578:in `visit_Arel_Nodes_And'
activerecord (6.0.2.1) lib/arel/visitors/visitor.rb:31:in `visit'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:790:in `block in inject_join'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:788:in `each'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:788:in `each_with_index'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:788:in `inject_join'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:181:in `collect_nodes_for'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:161:in `visit_Arel_Nodes_SelectCore'
activerecord (6.0.2.1) lib/arel/visitors/mysql.rb:28:in `visit_Arel_Nodes_SelectCore'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:128:in `block in visit_Arel_Nodes_SelectStatement'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:127:in `each'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:127:in `inject'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:127:in `visit_Arel_Nodes_SelectStatement'
activerecord (6.0.2.1) lib/arel/visitors/mysql.rb:23:in `visit_Arel_Nodes_SelectStatement'
activerecord (6.0.2.1) lib/arel/visitors/visitor.rb:31:in `visit'
activerecord (6.0.2.1) lib/arel/visitors/visitor.rb:11:in `accept'
activerecord (6.0.2.1) lib/arel/visitors/to_sql.rb:18:in `compile'
activerecord (6.0.2.1) lib/active_record/connection_adapters/abstract/database_statements.rb:34:in `to_sql_and_binds'
activerecord (6.0.2.1) lib/active_record/connection_adapters/abstract/query_cache.rb:99:in `select_all'
activerecord (6.0.2.1) lib/active_record/connection_adapters/mysql/database_statements.rb:12:in `select_all'
activerecord (6.0.2.1) lib/active_record/connection_adapters/abstract/database_statements.rb:77:in `select_one'
activerecord (6.0.2.1) lib/active_record/relation/finder_methods.rb:317:in `block in exists?'
activerecord (6.0.2.1) lib/active_record/relation.rb:828:in `skip_query_cache_if_necessary'
activerecord (6.0.2.1) lib/active_record/relation/finder_methods.rb:317:in `exists?'
impressionist (1.6.1) app/controllers/impressionist_controller.rb:103:in `check_unique_impression?'
impressionist (1.6.1) app/controllers/impressionist_controller.rb:99:in `check_impression?'
impressionist (1.6.1) app/controllers/impressionist_controller.rb:94:in `unique?'
impressionist (1.6.1) app/controllers/impressionist_controller.rb:44:in `impressionist_subapp_filter'
impressionist (1.6.1) app/controllers/impressionist_controller.rb:7:in `block in impressionist'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:429:in `instance_exec'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:429:in `block in make_lambda'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:201:in `block (2 levels) in halting'
actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:34:in `block (2 levels) in <module:Callbacks>'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:202:in `block in halting'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:514:in `block in invoke_before'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:514:in `each'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:514:in `invoke_before'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:110:in `block in run_callbacks'
public_activity (1.6.4) lib/public_activity/utility/store_controller.rb:27:in `store_controller_for_public_activity'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:121:in `block in run_callbacks'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:139:in `run_callbacks'
actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `block in instrument'
activesupport (6.0.2.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `instrument'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (6.0.2.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (6.0.2.1) lib/abstract_controller/base.rb:136:in `process'
actionview (6.0.2.1) lib/action_view/rendering.rb:39:in `process'
rack-mini-profiler (1.1.5) lib/mini_profiler/profiling_methods.rb:104:in `block in profile_method'
actionpack (6.0.2.1) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (6.0.2.1) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:51:in `dispatch'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:33:in `serve'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:49:in `block in serve'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:837:in `call'
rack-pjax (1.1.0) lib/rack/pjax.rb:12:in `call'
bullet (6.1.0) lib/bullet/rack.rb:15:in `call'
remotipart (1.4.4) lib/remotipart/middleware.rb:32:in `call'
warden (1.2.8) lib/warden/manager.rb:36:in `block in call'
warden (1.2.8) lib/warden/manager.rb:34:in `catch'
warden (1.2.8) lib/warden/manager.rb:34:in `call'
rack (2.1.2) lib/rack/tempfile_reaper.rb:17:in `call'
rack (2.1.2) lib/rack/etag.rb:27:in `call'
rack (2.1.2) lib/rack/conditional_get.rb:27:in `call'
rack (2.1.2) lib/rack/head.rb:14:in `call'
actionpack (6.0.2.1) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.1.2) lib/rack/session/abstract/id.rb:269:in `context'
rack (2.1.2) lib/rack/session/abstract/id.rb:263:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/cookies.rb:648:in `call'
activerecord (6.0.2.1) lib/active_record/migration.rb:567:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:101:in `run_callbacks'
actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
web-console (4.0.1) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.0.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `catch'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.1.2) lib/rack/method_override.rb:24:in `call'
rack (2.1.2) lib/rack/runtime.rb:24:in `call'
activesupport (6.0.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.1.2) lib/rack/sendfile.rb:113:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/host_authorization.rb:83:in `call'
rack-mini-profiler (1.1.5) lib/mini_profiler/profiler.rb:296:in `call'
webpacker (4.2.2) lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
railties (6.0.2.1) lib/rails/engine.rb:526:in `call'
puma (4.3.1) lib/puma/configuration.rb:228:in `call'
puma (4.3.1) lib/puma/server.rb:681:in `handle_request'
puma (4.3.1) lib/puma/server.rb:472:in `process_client'
puma (4.3.1) lib/puma/server.rb:328:in `block in run'
puma (4.3.1) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
最佳答案
我成功地重现了相同的异常。也许您的代码或您使用的 gem 正在使用 session.id
运行查询.
解决方案
如果您的代码使用 session.id
要识别用户,您应该在使用之前将其转换为字符串。
# Bad
user = User.find_by(session_id: session.id)
# => TypeError can't quote Rack::Session::SessionId
# Good
user = User.find_by(session_id: session.id.to_s)
# Success!
session.id
运行查询,您应该怀疑在 Rack session 中间插入处理的 gem。
Rails 5.2.4.2
中运行.
# In controller
def new
logger.info "class=#{session.id.class} to_s=#{session.id.to_s}"
end
# The log for the above code
# INFO -- class=Rack::Session::SessionId to_s=adf8...9af0 <- a long string
session.id
运行查询,您将获得
TypeError
.
SomethingModel.where(session_id: session.id).to_a
# => TypeError can't quote Rack::Session::SessionId
关于ruby-on-rails - 类型错误 - 不能引用 Rack::Session::SessionId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60019801/
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: template pass by value or const reference or…? 以下对于将函数
我用相同的参数列表重载了一个运算符两次。但返回类型不同: T& operator()(par_list){blablabla} const T& operator()(par_list){bla
假设我有实现接口(interface) I 的 Activity A。我的 ViewModel 类 (VM) 持有对实现接口(interface) I 的对象的引用: class A extends
PHP 如何解释 &$this ?为什么允许? 我遇到了以下问题,这看起来像是 PHP 7.1 和 7.2 中的错误。它与 &$this 引用和跨命名空间调用以及 call_user_func_arr
谁能解释一下下面“&”的作用: class TEST { } $abc =& new TEST(); 我知道这是引用。但是有人可以说明我为什么以及什么时候需要这样的东西吗?或者给我指向一个对此有很好解
引用变量是一个别名,也就是说,它是某个已存在变量的另一个名字。一旦把引用初始化为某个变量,就可以使用该引用名称或变量名称来指向变量。 C++ 引用 vs 指针 引用很容易与指针混淆,它们之间有三
目录 引言 背景 结论 引言 我选择写C++中的引用是因为我感觉大多数人误解了引用。而我之所以有这个感受是因为我主持过很多C++的面试,并且我很少
Perl 中的引用是指一个标量类型可以指向变量、数组、哈希表(也叫关联数组)甚至函数,可以应用在程序的任何地方 创建引用 定义变量的时候,在变量名前面加个 \,就得到了这个变量的一个引用 $sc
我编写了一个将从主脚本加载的 Perl 模块。该模块使用在主脚本中定义的子程序(我不是维护者)。 对于主脚本中的一个子例程,需要扩展,但我不想修补主脚本。相反,我想覆盖我的模块中的函数并保存对原始子例
我花了几个小时试图掌握 F# Quotations,但我遇到了一些障碍。我的要求是从可区分的联合类型中取出简单的函数(只是整数、+、-、/、*)并生成一个表达式树,最终将用于生成 C 代码。我知道使用
很多时候,问题(尤其是那些标记为 regex 的问题)询问验证密码的方法。似乎用户通常会寻求密码验证方法,包括确保密码包含特定字符、匹配特定模式和/或遵守最少字符数。这篇文章旨在帮助用户找到合适的密码
我想通过 MIN 函数内的地址(例如,C800)引用包含文本的最后一个单元格。你能帮忙吗? Sub Set_Formula() ' ----------------------------- Dim
使用常规的 for 循环,我可以做类似的事情: for (let i = 0; i < objects.length; i++) { delete objects[i]; } 常规的 for-
在 Cucumber 中,您定义了定义 BDD 语法的步骤;例如,您的测试可能有: When I navigate to step 3 然后你可以定义一个步骤: When /^I navigate t
这是什么UnaryExpression的目的,以及应该怎样使用? 最佳答案 它需要一个 Expression对象并用另一个 Expression 包裹它.例如,如果您有一个用于 lambda 的表达式
给出以下内容 $("#identifier div:first, #idetifier2").fadeOut(300,function() { // I need to reference jus
我不知道我要找的东西的正确术语,但我要找的是一个完整的引用,可以放在双引号之间的语句,比如 *, node()、@* 以及所有列出的 here加上任何其他存在的。 我链接到的答案提供了一些细节,但还
This question's answers are a community effort。编辑现有答案以改善此职位。它当前不接受新的答案或互动。 这是什么? 这是常见问答的集合。这也是一个社区Wi
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-topic
考虑下一个代码: fn get_ref(slice: &'a Vec, f: fn(&'a Vec) -> R) -> R where R: 'a, { f(slice) } fn m
我是一名优秀的程序员,十分优秀!