对于缺少模板,给出 404 而不是 500 错误

2024-03-28

我有一个 Rails 3.0 应用程序(正在进行 3.2 升级),每当有人请求不存在的模板时,它都会在生产中给出 500 错误。例如,mysite.com/blog_posts/532 将 ID 为 532 的帖子以 HTML 形式发送回来,没有问题,但如果由于某种原因请求 mysite.com/blog_posts/532.txt,则应用程序会引发 500 ActionView::MissingTemplate 错误。

这种情况不应该发生,因为模板一开始就不应该存在。更正确的说法应该是 404 错误,或者可能只是显示 HTML 模板。

如何让应用程序针对所有缺失模板错误显示 404 错误,或者显示默认 HTML 模板而不是给出 500?

Log:

Started GET "/blog_posts/73.txt" for 127.0.0.1 at 2013-05-20 21:22:51 -0400
  Processing by BlogPostsController#show as TEXT
  Parameters: {"id"=>"73"}
  PK and serial sequence (2.0ms)   SELECT attr.attname, seq.relname
 FROM pg_class seq,
 pg_attribute attr,
 pg_depend dep,
 pg_namespace name,
 pg_constraint cons
 WHERE seq.oid = dep.objid
 AND seq.relkind = 'S'
 AND attr.attrelid = dep.refobjid
 AND attr.attnum = dep.refobjsubid
 AND attr.attrelid = cons.conrelid
 AND attr.attnum = cons.conkey[1]
 AND cons.contype = 'p'
 AND dep.refobjid = '"blog_posts_blog_tags"'::regclass
  PK and custom sequence (1.0ms)   SELECT attr.attname,
 CASE
 WHEN split_part(def.adsrc, '''', 2) ~ '.' THEN
 substr(split_part(def.adsrc, '''', 2),
 strpos(split_part(def.adsrc, '''', 2), '.')+1)
 ELSE split_part(def.adsrc, '''', 2)
 END
 FROM pg_class t
 JOIN pg_attribute attr ON (t.oid = attrelid)
 JOIN pg_attrdef def ON (adrelid = attrelid AND adnum = attnum)
 JOIN pg_constraint cons ON (conrelid = adrelid AND adnum = conkey[1])
 WHERE t.oid = '"blog_posts_blog_tags"'::regclass
 AND cons.contype = 'p'
 AND def.adsrc ~* 'nextval'
  BlogPost Load (0.0ms)  SELECT "blog_posts".* FROM "blog_posts" WHERE "blog_posts"."id" = '73' LIMIT 1
  SQL (0.0ms)   SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
 FROM pg_attribute a LEFT JOIN pg_attrdef d
 ON a.attrelid = d.adrelid AND a.attnum = d.adnum
 WHERE a.attrelid = '"blog_posts"'::regclass
 AND a.attnum > 0 AND NOT a.attisdropped
 ORDER BY a.attnum
Completed 500 Internal Server Error in 59ms
  User Load (1.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
  SQL (1.0ms)   SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
 FROM pg_attribute a LEFT JOIN pg_attrdef d
 ON a.attrelid = d.adrelid AND a.attnum = d.adnum
 WHERE a.attrelid = '"users"'::regclass
 AND a.attnum > 0 AND NOT a.attisdropped
 ORDER BY a.attnum

ActionView::MissingTemplate (Missing template blog_posts/show with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:text], :lo
cale=>[:en, :en]} in view paths "C:/Rails/myapp/app/views", "C:/Ruby/lib/ruby/gems/1.9.1/gems/devise-1.5.4/app/views"):


Rendered C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/middleware/templates/rescues/missing_template.erb within res
cues/layout (1.0ms)

更新日志,带有跟踪:

Started GET "/blog_posts/73.txt" for 127.0.0.1 at 2013-05-20 22:14:28 -0400
  Processing by BlogPostsController#show as TEXT
  Parameters: {"id"=>"73"}
  PK and serial sequence (2.0ms)   SELECT attr.attname, seq.relname
 FROM pg_class seq,
 pg_attribute attr,
 pg_depend dep,
 pg_namespace name,
 pg_constraint cons
 WHERE seq.oid = dep.objid
 AND seq.relkind = 'S'
 AND attr.attrelid = dep.refobjid
 AND attr.attnum = dep.refobjsubid
 AND attr.attrelid = cons.conrelid
 AND attr.attnum = cons.conkey[1]
 AND cons.contype = 'p'
 AND dep.refobjid = '"blog_posts_blog_tags"'::regclass
  PK and custom sequence (1.0ms)   SELECT attr.attname,
 CASE
 WHEN split_part(def.adsrc, '''', 2) ~ '.' THEN
 substr(split_part(def.adsrc, '''', 2),
 strpos(split_part(def.adsrc, '''', 2), '.')+1)
 ELSE split_part(def.adsrc, '''', 2)
 END
 FROM pg_class t
 JOIN pg_attribute attr ON (t.oid = attrelid)
 JOIN pg_attrdef def ON (adrelid = attrelid AND adnum = attnum)
 JOIN pg_constraint cons ON (conrelid = adrelid AND adnum = conkey[1])
 WHERE t.oid = '"blog_posts_blog_tags"'::regclass
 AND cons.contype = 'p'
 AND def.adsrc ~* 'nextval'
  BlogPost Load (0.0ms)  SELECT "blog_posts".* FROM "blog_posts" WHERE "blog_posts"."id" = '73' LIMIT 1
  SQL (0.0ms)   SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
 FROM pg_attribute a LEFT JOIN pg_attrdef d
 ON a.attrelid = d.adrelid AND a.attnum = d.adnum
 WHERE a.attrelid = '"blog_posts"'::regclass
 AND a.attnum > 0 AND NOT a.attisdropped
 ORDER BY a.attnum
--------------------------------------------------------------------------------
exception: Missing template blog_posts/show with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:text], :locale=>[:en, :en]} in view paths "C:/Rails/myapp/app/views", "C:/Ruby/lib/ruby/gems/1.9.1/gems/devise-1.5.4/app/views"
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_view/paths.rb:15:in `find'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_view/lookup_context.rb:81:in `find'
C:in `find_template'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_view/render/rendering.rb:46:in `_determine_template'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_view/render/rendering.rb:24:in `render'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/abstract_controller/rendering.rb:115:in `_render_template'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/abstract_controller/rendering.rb:109:in `render_to_body'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal/renderers.rb:47:in `render_to_body'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/abstract_controller/rendering.rb:102:in `render_to_string'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/abstract_controller/rendering.rb:93:in `render'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal/rendering.rb:17:in `render'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.20/lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
C:/Ruby/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.20/lib/active_support/core_ext/benchmark.rb:5:in `ms'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal/instrumentation.rb:40:in `block in render'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.20/lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal/instrumentation.rb:39:in `render'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal/implicit_render.rb:10:in `default_render'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal/implicit_render.rb:5:in `send_action'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/abstract_controller/base.rb:150:in `process_action'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal/rendering.rb:11:in `process_action'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.20/lib/active_support/callbacks.rb:436:in `_run__326851374__process_action__856302785__callbacks'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.20/lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.20/lib/active_support/callbacks.rb:94:in `run_callbacks'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/abstract_controller/callbacks.rb:17:in `process_action'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal/rescue.rb:17:in `process_action'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.20/lib/active_support/notifications.rb:52:in `block in instrument'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.20/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.20/lib/active_support/notifications.rb:52:in `instrument'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
C:/Ruby/lib/ruby/gems/1.9.1/gems/newrelic_rpm-3.6.2.96/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:38:in `block in process_action'
C:/Ruby/lib/ruby/gems/1.9.1/gems/newrelic_rpm-3.6.2.96/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:318:in `perform_action_with_newrelic_trace'
C:/Ruby/lib/ruby/gems/1.9.1/gems/newrelic_rpm-3.6.2.96/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:37:in `process_action'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/abstract_controller/base.rb:119:in `process'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/abstract_controller/rendering.rb:41:in `process'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal.rb:138:in `dispatch'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_controller/metal.rb:178:in `block in action'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/routing/route_set.rb:68:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/routing/route_set.rb:68:in `dispatch'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/routing/route_set.rb:33:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/rack-mount-0.6.14/lib/rack/mount/route_set.rb:148:in `block in call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/rack-mount-0.6.14/lib/rack/mount/code_generation.rb:93:in `block in recognize'
C:/Ruby/lib/ruby/gems/1.9.1/gems/rack-mount-0.6.14/lib/rack/mount/code_generation.rb:89:in `optimized_each'
C:/Ruby/lib/ruby/gems/1.9.1/gems/rack-mount-0.6.14/lib/rack/mount/code_generation.rb:92:in `recognize'
C:/Ruby/lib/ruby/gems/1.9.1/gems/rack-mount-0.6.14/lib/rack/mount/route_set.rb:139:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/routing/route_set.rb:499:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/newrelic_rpm-3.6.2.96/lib/new_relic/rack/error_collector.rb:12:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/newrelic_rpm-3.6.2.96/lib/new_relic/rack/agent_hooks.rb:18:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/newrelic_rpm-3.6.2.96/lib/new_relic/rack/developer_mode.rb:28:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/warden-1.2.1/lib/warden/manager.rb:35:in `block in call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/warden-1.2.1/lib/warden/manager.rb:34:in `catch'
C:/Ruby/lib/ruby/gems/1.9.1/gems/warden-1.2.1/lib/warden/manager.rb:34:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/middleware/head.rb:14:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.2.7/lib/rack/methodoverride.rb:24:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/middleware/flash.rb:182:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/middleware/cookies.rb:302:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.20/lib/active_record/query_cache.rb:32:in `block in call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.20/lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.20/lib/active_record/query_cache.rb:12:in `cache'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.20/lib/active_record/query_cache.rb:31:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.20/lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.20/lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/middleware/callbacks.rb:44:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.2.7/lib/rack/sendfile.rb:106:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.0.20/lib/rails/rack/logger.rb:13:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.2.7/lib/rack/runtime.rb:17:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.20/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.2.7/lib/rack/lock.rb:13:in `block in call'
<internal:prelude>:10:in `synchronize'
C:/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.2.7/lib/rack/lock.rb:13:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.20/lib/action_dispatch/middleware/static.rb:30:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/airbrake-3.1.4/lib/airbrake/rack.rb:41:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/airbrake-3.1.4/lib/airbrake/user_informer.rb:12:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.0.20/lib/rails/application.rb:168:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.0.20/lib/rails/application.rb:77:in `method_missing'
C:/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.0.20/lib/rails/rack/log_tailer.rb:14:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.2.7/lib/rack/content_length.rb:13:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.2.7/lib/rack/handler/webrick.rb:52:in `service'
C:/Ruby/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
C:/Ruby/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
C:/Ruby/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
--------------------------------------------------------------------------------
Completed 200 OK in 59ms
[2013-05-20 22:14:28] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked
= true

在您的 applicationController 中,您应该能够从丢失的模板中拯救出来,然后重新引发 404 。

class ApplicationController > ActionController::Base
  rescue_from ActionView::MissingTemplate do |exception|
     raise ActionController::RoutingError.new('Not Found')
  end
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

对于缺少模板,给出 404 而不是 500 错误 的相关文章

  • 如何让 Rails 资产管道生成源地图?

    我想让 Rails 与编译后的 CoffeeScript 缩小的 JS 一起生成源映射 以便更好地记录错误 不过 网上似乎还没有关于如何执行此操作的全面文档 有人这样做过吗 我使用 Rails 3 2 和 Heroku Rails 支持缩小
  • Facebook 注册后重定向至页面

    我正在尝试在成功 Facebook 注册 未登录 后重定向用户 我想重定向到 getstarted welcome用户注册后首次 我的omniauth回调是 def facebook You need to implement the me
  • ActiveAdmin 使用 Devise Rails 登录两次

    我有一个Rails已设置使用的应用程序devise with User模型 我只是添加ActiveAdmin并且它使用单独的型号名称AdminUser 这个新模型也使用了设计 我遇到的问题是 当我去localhost 3000 admin
  • docker 中的 Capybara headless chrome 返回 DevToolsActivePort 文件不存在

    我正在尝试配置系统测试以使用硒中的无头铬 我有以下水豚配置 spec support capybara rb Capybara server puma Silent true RSpec configure do config config
  • Rails 3 UJS 干客户端 + 服务器端表单验证

    使用 jQuery 进行表单验证就像向字段添加类名一样简单 使用 Rails 进行表单验证就像将条件放入控制器 和 或模型 中一样简单 我认为应该有一种方法可以编写一次验证并将它们应用到客户端和服务器端 我一直热衷于编写自己的 javasc
  • 在初始化程序中重新加载命名空间常量

    今天遇到一个有趣的情况 我不确定如何解决 给定一个带有初始化器的 Rails 应用程序 file config initializers integrations rb Integrations CONFIGS key gt value f
  • Rails 应用程序中的持久 TCP 连接

    我有一个在服务器上运行的第三方应用程序 它对客户端进行身份验证并返回响应 我的问题是 对于我收到 Rails 应用程序的每个请求 我都需要建立 TCP 连接并获取数据 是否可以有一个持久连接 以便我可以减少建立连接的开销 我希望你使用的是
  • 通过 has_many 进行多个数据库连接

    如何通过使用多个数据库连接来创建 has many 我有一个名为 master 的数据库 其中保存位置信息 这是从单独的应用程序更新的 用户可以访问许多位置 但所有其他模型都位于另一个名为 budget 的数据库中 以下是模型的设置方式 p
  • 在 Rails 上制作 ruby​​ 占用更少的内存

    我正在尝试运行 Ruby on Rails 项目 redmine http www redmine org 在 VPS 上 它可以工作 但需要相当多的内存 与 VPS 的其余部分相比 rails 应用程序的使用量非常少 我的服务器上也运行着
  • Rails-自定义删除前确认对话框的视图

    要删除 Rails 中的记录 我使用此代码 result of which I get dialog box like this But I wants this dialog box to look like this 有没有办法自定义确
  • Rails 建模:将 HABTM 转换为 has_many :through

    我正在现有的 Rails 站点上进行维护工作 并且遇到了一些由多对多关联引起的问题 看起来该网站最初是使用has and belongs to many对于一些业务逻辑变得更加复杂的关系 所以我需要使用has many through而是支
  • 如何修复 AJAX 在选中复选框时始终触发?

    有时这个 AJAX 会触发 有时不会 让我解释一下 habit js document ready function habit check change function habit this parent siblings habit
  • Rails 中的多列主键

    我正在尝试将桌面应用程序迁移到rails 还处理相当老式的现有数据库 问题是我在一列中没有唯一的 ID 但表的三列保证了记录的唯一性 鉴于我有三个表 authors author name author letter author nr1
  • 如何使用 ActiveAdmin 创建 STI 子类的对象

    给出以下设置 当前不起作用 class Employee lt ActiveRecord Base end class Manager lt Employee end ActiveAdmin register Employee do for
  • 使用 RSpec 请求规范授权请求时,access_token 无效

    我正在尝试测试CredentialsController 使用 RSpec 请求规范在生产中运行良好 Code 控制器 class CredentialsController lt ApplicationController before
  • Escape String - 在 Javascript 中输出rails字符串[重复]

    这个问题在这里已经有答案了 我正在尝试将字符串值分配给 erb 文件中的 javascript 对象 如下所示 var data name 问题是 如果name is Tom s small ears 的输出data name将会Tom x
  • 2015 年重新审视 Ember Handling 401

    我可以在 Ember Ember Data 中找到大量询问 回答如何从 Rails 后端处理 401 的老问题 许多 如果不是全部的话 在这一点上似乎已经过时了 我已经尝试了我能找到的一切 Ember 数据处理 401 https stac
  • Watir 脚本偶尔返回 Net::ReadTimeout 错误

    我有一个 Watir 脚本 偶尔会意外地返回此错误 Net ReadTimeout 我搜索了这个错误并发现这个问题 https stackoverflow com questions 47452276 watir get sometimes
  • Ruby on Rails:simple_form + Twitter Bootstrap 未显示

    我正在为我的网站上的新用户创建一个简单的注册表单 我已经运行了 simple form bootstrap 的安装 rails g simple form install bootstrap 但是 它仍然没有显示并呈现为正常的 simple
  • 使用“回形针”gem 和 Ruby on Rails 3 时出现问题

    我在运行 Snow Leopard v1 6 5 的 MacO 上使用 Ruby on Rails 3 我想使用 回形针 gem 所以我将它包含在我的 Gemfile 中 如下所示 gem paperclip gt 2 3 然后 在终端中运

随机推荐

  • 从列表中删除重复的子列表

    如果我有一个这样的列表 mylist 1 2 3 a c 3 4 5 1 2 3 4 5 a c 3 4 5 1 2 删除重复子列表的最佳方法是什么 现在我用this https stackoverflow com a 20462808 4
  • Docker COPY 没有这样的文件或目录

    构建 docker 映像在复制任务中失败 没有这样的文件或目录 我正在使用你好世界春天的例子 https spring io guides gs spring boot docker 从 openjdk 构建 8 jdk alpine Ru
  • Jquery 加载函数将附加到已经存在的 HTML 上

    我正在尝试进行 AJAX 调用 该调用将附加 html 即向标签之间已存在的内容添加额外的 html 这是我的加载函数的样子 我如何修改这个函数才能将其附加到类 tid list 中 提前致谢 您必须通过ajax获取数据并使用 tid li
  • 在 jQuery 中将 processData 设置为 false 会破坏我的 AJAX 请求

    我已经用谷歌搜索了一段时间 只能找到什么processData false做 我找不到经历过同样问题的人 我将 JSON 传递回服务器 并且不希望 jQuery 自动将数据转换为查询字符串 因此我将 processData 设置为 fals
  • 获取 VBScript 中变量的类型

    如何使用 VBScript 获取变量的类型 Is VarType https msdn microsoft com en us library aa263402 v vs 60 aspx你需要什么 返回一个指示变量子类型的值 Constan
  • 在区域之外的 MVC 应用程序中托管 WCF 服务

    我有一个 MVC 项目 我在根目录中添加了一个名为 WCF 的文件夹 在此文件夹中 我创建了一个名为的 WCF 服务CustomFunctions 当我尝试启动该服务时 我收到以下错误 错误 无法从中获取元数据http localhost
  • 使用 ajax 包含子行的闪亮数据表

    我正在尝试使用数据表库来实现更多自定义的闪亮效果 这是我试图做的例子 https datatables net examples api row details html https datatables net examples api
  • AfxGetAppName() 返回垃圾字符

    我的应用程序中有以下代码行 CString strAppName AfxGetAppName 有时会充满strAppName出现了垃圾字符 我不明白为什么 有人有主意吗 TIA 如果你改变的话这是可能的m pszAppName手动 在应用程
  • 将字符串列表通过管道传输到 for 循环

    我如何将列表传递给for在bash中 I tried echo some different lines for i do echo do something with i done 但这行不通 我也试图找到一个解释man但没有man fo
  • 使用 javascript 在循环内设置超时

    我正在制作一个解谜函数 它使用当前打乱顺序的一系列拼图 每个片段都有一个 id 它指向数组中的正确位置 我在要交换的部分上设置了叠加颜色 我希望在着色和交换的部分之间有一个延迟 function solvePuzzle while rezo
  • JavaScript/GSON:通过对象图动态访问 JSON 引用(循环引用)

    由于存在多个循环引用 我在通过 Google GSON 序列化 Java 对象时遇到了问题 我所有的尝试都以 StackOverflowException 结束 因为 GSON 无法处理这些循环引用 作为解决方案 我发现以下GraphAda
  • SELECT FOR UPDATE 中的数据库死锁

    我的应用程序间歇性陷入僵局 我的应用程序有 1 个表 例如 EMPLOYEE ID PK NAME SAL 并且有 2 个会话 第一节 SELECT ID NAME SAL FROM EMPLOYEE WHERE SAL SELECT MI
  • spring mvc 对 URL 参数进行加密和编码

    我正在编写一个 Spring mvc 应用程序 它需要发送一封包含链接和加密参数的电子邮件 用户将单击该链接 我需要解密新页面中的参数 因此 我正在编写一个 util 类来加密和解密以及对参数进行编码和解码 当我运行我的独立java类 用于
  • 你能告诉 PHP 在发生错误时发送标头(如 500)吗?

    在我当前的项目中 我使用普通 HTTP 请求查询 PHP 但也通过 AJAX 查询 有时返回 JSON 格式的数据 有时返回普通文本 当发生错误时 在正常请求中 您会看到错误消息并可以采取一些措施 另一方面 对于 AJAX 请求 您无法确定
  • getchar() 返回错误的特殊情况是什么?

    所以我知道getchar 当输入结束或发生错误时返回 EOF 我也知道我可以通过以下方式检查发生了哪些情况ferror stdin and feof stdin 我想知道什么情况下会特别发生错误 我检查了这两个函数的手册页 但那里没有任何内
  • 就性能而言,使用 std::memcpy() 还是 std::copy() 更好?

    是不是比较好用memcpy如下所示还是使用更好std copy 就性能而言 为什么 char bits NULL bits new std nothrow char int copyMe gt bits 0 if bits NULL cou
  • 使用 Foreman 重新启动单个进程

    我已经使用 foreman 一段时间来以集中方式扩展我的各种 ruby 流程 并且它对我来说工作得很好 无论如何 我希望有一些功能来重新启动进程 甚至给它更多的控制权 例如终止进程并再次启动它 在当前的实现中 当我终止一个进程时 主工头中的
  • Chrome 无法播放 MP4

    我每天都会从我的安全摄像头系统中收到几封发送到我的 Gmail 帐户的电子邮件 此类邮件包含来自摄像机的 MP4 格式的视频剪辑 每个大约 20 秒 的链接 奇怪的是 在基于 Mageia 的 PC 上单击此类链接后 剪辑将打开并在新的单独
  • 在matlab中将绘图保存到图像文件中:saveas和print之间的区别

    我想知道在matlab中将绘图保存到图像文件时 saveas和print有什么区别 什么情况下两者可以同时使用 什么情况下只能使用其中一种 感谢致敬 我相信 SAVEAS 只是 PRINT 的包装 查看 SAVEAS 的源代码 编辑 sav
  • 对于缺少模板,给出 404 而不是 500 错误

    我有一个 Rails 3 0 应用程序 正在进行 3 2 升级 每当有人请求不存在的模板时 它都会在生产中给出 500 错误 例如 mysite com blog posts 532 将 ID 为 532 的帖子以 HTML 形式发送回来