- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我遇到了很奇怪的问题。
Rails 在 url_for 上提示:
NoMethodError: undefined method `url_for' for nil:NilClass
完整回溯:
/gems/actionpack-3.2.18/lib/action_dispatch/routing/url_for.rb:148 in url_for
/gems/actionpack-3.2.18/lib/action_view/helpers/url_helper.rb:107 in url_for
/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:216 in reports_market_path
app/views/reports/market/index.html.erb:7 in _app_views_reports_market_index_html_erb___1902231581999475126_70184101502700
/gems/actionpack-3.2.18/lib/action_view/template.rb:145 in block in render
/gems/activesupport-3.2.18/lib/active_support/notifications.rb:125 in instrument
/gems/actionpack-3.2.18/lib/action_view/template.rb:143 in render
/gems/actionpack-3.2.18/lib/action_view/renderer/template_renderer.rb:47 in block (2 levels) in render_template
/gems/actionpack-3.2.18/lib/action_view/renderer/abstract_renderer.rb:38 in block in instrument
/gems/activesupport-3.2.18/lib/active_support/notifications.rb:123 in block in instrument
/gems/activesupport-3.2.18/lib/active_support/notifications/instrumenter.rb:20 in instrument
/gems/activesupport-3.2.18/lib/active_support/notifications.rb:123 in instrument
/gems/actionpack-3.2.18/lib/action_view/renderer/abstract_renderer.rb:38 in instrument
/gems/actionpack-3.2.18/lib/action_view/renderer/template_renderer.rb:46 in block in render_template
/gems/actionpack-3.2.18/lib/action_view/renderer/template_renderer.rb:54 in render_with_layout
/gems/actionpack-3.2.18/lib/action_view/renderer/template_renderer.rb:45 in render_template
/gems/actionpack-3.2.18/lib/action_view/renderer/template_renderer.rb:18 in render
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:145 in block in render_with_newrelic
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/method_tracer.rb:69 in block in trace_execution_scoped
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/method_tracer_helpers.rb:82 in trace_execution_scoped
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/method_tracer.rb:67 in trace_execution_scoped
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:144 in render_with_newrelic
/gems/actionpack-3.2.18/lib/action_view/renderer/renderer.rb:36 in render_template
/gems/actionpack-3.2.18/lib/action_view/renderer/renderer.rb:17 in render
/gems/actionpack-3.2.18/lib/abstract_controller/rendering.rb:110 in _render_template
/gems/actionpack-3.2.18/lib/action_controller/metal/streaming.rb:225 in _render_template
/gems/actionpack-3.2.18/lib/abstract_controller/rendering.rb:103 in render_to_body
/gems/actionpack-3.2.18/lib/action_controller/metal/renderers.rb:28 in render_to_body
/gems/actionpack-3.2.18/lib/action_controller/metal/compatibility.rb:50 in render_to_body
/gems/actionpack-3.2.18/lib/abstract_controller/rendering.rb:88 in render
/gems/actionpack-3.2.18/lib/action_controller/metal/rendering.rb:16 in render
/gems/actionpack-3.2.18/lib/action_controller/metal/instrumentation.rb:40 in block (2 levels) in render
/gems/activesupport-3.2.18/lib/active_support/core_ext/benchmark.rb:5 in block in ms
/home/deploy/.rbenv/versions/1.9.3-p484/lib/ruby/1.9.1/benchmark.rb:295 in realtime
/gems/activesupport-3.2.18/lib/active_support/core_ext/benchmark.rb:5 in ms
/gems/actionpack-3.2.18/lib/action_controller/metal/instrumentation.rb:40 in block in render
/gems/actionpack-3.2.18/lib/action_controller/metal/instrumentation.rb:83 in cleanup_view_runtime
/gems/activerecord-3.2.18/lib/active_record/railties/controller_runtime.rb:24 in cleanup_view_runtime
/gems/actionpack-3.2.18/lib/action_controller/metal/instrumentation.rb:39 in render
/gems/active_scaffold-3.3.3/lib/active_scaffold/extensions/action_controller_rendering.rb:14 in render_with_active_scaffold
/gems/actionpack-3.2.18/lib/action_controller/metal/implicit_render.rb:10 in default_render
/gems/actionpack-3.2.18/lib/action_controller/metal/implicit_render.rb:5 in send_action
/gems/actionpack-3.2.18/lib/abstract_controller/base.rb:167 in process_action
/gems/actionpack-3.2.18/lib/action_controller/metal/rendering.rb:10 in process_action
/gems/actionpack-3.2.18/lib/abstract_controller/callbacks.rb:18 in block in process_action
/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:469 in _run__801877313021617769__process_action__2065492084595526813__callbacks
/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:405 in __run_callback
/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:385 in _run_process_action_callbacks
/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:81 in run_callbacks
/gems/actionpack-3.2.18/lib/abstract_controller/callbacks.rb:17 in process_action
/gems/actionpack-3.2.18/lib/action_controller/metal/rescue.rb:29 in process_action
/gems/actionpack-3.2.18/lib/action_controller/metal/instrumentation.rb:30 in block in process_action
/gems/activesupport-3.2.18/lib/active_support/notifications.rb:123 in block in instrument
/gems/activesupport-3.2.18/lib/active_support/notifications/instrumenter.rb:20 in instrument
/gems/activesupport-3.2.18/lib/active_support/notifications.rb:123 in instrument
/gems/actionpack-3.2.18/lib/action_controller/metal/instrumentation.rb:29 in process_action
/gems/actionpack-3.2.18/lib/action_controller/metal/params_wrapper.rb:207 in process_action
/gems/activerecord-3.2.18/lib/active_record/railties/controller_runtime.rb:18 in process_action
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:23 in block in process_action
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:353 in perform_action_with_newrelic_trace
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:22 in process_action
/gems/actionpack-3.2.18/lib/abstract_controller/base.rb:121 in process
/gems/actionpack-3.2.18/lib/abstract_controller/rendering.rb:45 in process
/gems/actionpack-3.2.18/lib/action_controller/metal.rb:203 in dispatch
/gems/actionpack-3.2.18/lib/action_controller/metal/rack_delegation.rb:14 in dispatch
/gems/actionpack-3.2.18/lib/action_controller/metal.rb:246 in block in action
/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:73 in call
/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:73 in dispatch
/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:36 in call
/gems/journey-1.0.4/lib/journey/router.rb:68 in block in call
/gems/journey-1.0.4/lib/journey/router.rb:56 in each
/gems/journey-1.0.4/lib/journey/router.rb:56 in call
/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:608 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/rack/agent_hooks.rb:30 in traced_call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/rack/browser_monitoring.rb:23 in traced_call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/warden-1.2.3/lib/warden/manager.rb:35 in block in call
/gems/warden-1.2.3/lib/warden/manager.rb:34 in catch
/gems/warden-1.2.3/lib/warden/manager.rb:34 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-3.2.18/lib/action_dispatch/middleware/best_standards_support.rb:17 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-1.4.5/lib/rack/etag.rb:23 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-1.4.5/lib/rack/conditionalget.rb:25 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-3.2.18/lib/action_dispatch/middleware/head.rb:14 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-3.2.18/lib/action_dispatch/middleware/params_parser.rb:21 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-3.2.18/lib/action_dispatch/middleware/flash.rb:242 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:210 in context
/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:205 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-3.2.18/lib/action_dispatch/middleware/cookies.rb:341 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/activerecord-3.2.18/lib/active_record/query_cache.rb:64 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/activerecord-3.2.18/lib/active_record/connection_adapters/abstract/connection_pool.rb:479 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-3.2.18/lib/action_dispatch/middleware/callbacks.rb:28 in block in call
/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:405 in _run__2176267765707103723__call__2820452351963234767__callbacks
/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:405 in __run_callback
/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:385 in _run_call_callbacks
/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:81 in run_callbacks
/gems/actionpack-3.2.18/lib/action_dispatch/middleware/callbacks.rb:27 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-1.4.5/lib/rack/sendfile.rb:102 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-3.2.18/lib/action_dispatch/middleware/remote_ip.rb:31 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-3.2.18/lib/action_dispatch/middleware/debug_exceptions.rb:16 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-3.2.18/lib/action_dispatch/middleware/show_exceptions.rb:56 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/railties-3.2.18/lib/rails/rack/logger.rb:32 in call_app
/gems/railties-3.2.18/lib/rails/rack/logger.rb:16 in block in call
/gems/activesupport-3.2.18/lib/active_support/tagged_logging.rb:22 in tagged
/gems/railties-3.2.18/lib/rails/rack/logger.rb:16 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-3.2.18/lib/action_dispatch/middleware/request_id.rb:22 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-1.4.5/lib/rack/methodoverride.rb:21 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-1.4.5/lib/rack/runtime.rb:17 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-1.4.5/lib/rack/lock.rb:15 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-cache-1.2/lib/rack/cache/context.rb:136 in forward
/gems/rack-cache-1.2/lib/rack/cache/context.rb:245 in fetch
/gems/rack-cache-1.2/lib/rack/cache/context.rb:185 in lookup
/gems/rack-cache-1.2/lib/rack/cache/context.rb:66 in call!
/gems/rack-cache-1.2/lib/rack/cache/context.rb:51 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/railties-3.2.18/lib/rails/engine.rb:484 in call
/gems/railties-3.2.18/lib/rails/application.rb:231 in call
/gems/railties-3.2.18/lib/rails/railtie/configurable.rb:30 in method_missing
/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:94 in process_request
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:149 in accept_and_process_next_request
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:110 in main_loop
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:414 in block (3 levels) in start_threads
/usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:111 in block in create_thread_and_abort_on_exception
出现错误的代码示例。
views/reports/index.html.erb(第 7 行)
<% content_for :head do %>
<%= javascript_include_tag 'reports/market/index' %>
<% end %>
<h1>Market Report</h1>
7. <%= form_tag reports_market_path(params[:id] || -1), method: :get do -%>
Start:
<br/>
<input class='report-datepicker' type="text" value="<%=Time.now.strftime("%Y-%m-%d")%>" class="date-input" name="begin_time" />
<br/>
End:
<br/>
<input class='report-datepicker' type="text" value="<%=Time.now.strftime("%Y-%m-%d")%>" class="date-input" name="end_time" />
<br/>
Franchise:
<br/>
<%= select 'franchise', 'id', Franchise.name_hash(current_user.accessible_franchises).merge({'All' => -1}), :selected => params[:id] || -1 %>
<br/>
<%= submit_tag 'generate', name: nil %>
<%end%>
错误是逐个出现的。刷新几页后,它可能会消失。错误出现在存在路由路径的不同页面上。
所以行<%= form_tag reports_market_path(params[:id] || -1), method: :get do -%>
抛出错误。
可能的解决方法:
a) index.html由ActiveScaffold Controller 渲染。
b) 有一个名为 Notifier 的邮件程序具有报告 操作:
class Notifier < ActionMailer::Base
def report(to, report, template, domain)
@logo = domain.logo
av = ActionView::Base.new()
av.view_paths = ActionController::Base.view_paths
av.class.class_eval do
include Rails.application.routes.url_helpers
include ApplicationHelper
end
html = av.render(:template => template, :locals => {:report => report, :logo => @logo})
kit = PDFKit.new(html, :page_size => 'A3', :margin_top=>'0.25in', :margin_right=>'0.25in', :margin_bottom=>'0.25in', :margin_left=>'0.25in')
kit.stylesheets << File.join(Rails.root,'public/stylesheets/bootstrap.css')
kit.stylesheets << File.join(Rails.root,'app/assets/stylesheets/admin/admin.css')
attachments[report.filename] = {
mime_type: "application/pdf",
content: kit.to_pdf
}
mail(subject: report.name, to: to, from: '...', date: Time.now) do |format|
format.text { render text: 'Pls, see attached PDF document' }
format.html { render text: html }
end
end
该操作将 View 内容读取为 html 并将其传递给 PDF 创建引擎。
我有一个假设(也很奇怪)在添加代码之后:
av = ActionView::Base.new()
av.view_paths = ActionController::Base.view_paths
av.class.class_eval do
include Rails.application.routes.url_helpers
include ApplicationHelper
end
错误开始出现在应用程序中。
c) 我们添加了 Redis 作为缓存存储。
config.cache_store = :redis_store, 'redis://localhost:6379/0/cache', { expires_in: 90.minutes, namespace: 'production' }
d) Nginx 服务器重启后错误消失但过一段时间又出现。
非常感谢。
最佳答案
所以,我找到了导致奇怪问题的代码。
av.class.class_eval do
include Rails.application.routes.url_helpers
include ApplicationHelper
end
我不确定它为什么会导致这个问题,可能它是线程不安全的,但是当我删除它时一切都正常了。
非常接近的问题 Active Model Serializers : undefined method `url_for' for nil:NilClass
关于ruby-on-rails - 无方法错误 : undefined method `url_for' for nil:NilClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31852138/
这段代码无法编译: for(vector::iterator it = shapes.end(); it >= shapes.begin(); --it){ *it.update(1,1);
我一直在研究 Common Lisp 对象协议(protocol) (CLOS),我遇到了一个疑问。 有人知道 CLOS 中的“标准方法组合”和“简单方法组合”是什么意思吗? 在“简单方法组合”中,“
在Rust上对值调用方法之间是否有任何区别,如下所示: struct A { e: u32 } impl A { fn show(&self) { println!("{}",
我在一些 StackOverflow 答案中看到了术语抽象方法、具体方法和默认方法的“不同”定义。 Java 语言规范给出的真正定义是什么?请在您的答案中包含相关的支持 JLS 引用资料。 最佳答案
如果method = "post",如何使rest[method]扩展为rest.post(uri, body).then(. .? function proxyUrl() { return
这个问题在这里已经有了答案: Method cannot be translated into a store expression (1 个回答) 关闭 9 年前。 我有一个问题。我在 Visua
它们各自的优缺点是什么? 接口(interface)方法 虚方法 抽象方法 什么时候应该选择什么?做出这一决定时应牢记哪些要点? 最佳答案 虚拟和抽象几乎是一样的。虚方法在基类中有一个可以选择被覆盖的
我在 Meteor.js 上的那段代码出错: 客户端 : Meteor.call("logUser", function(myvar){ console.log("le c
运行代码时出现以下错误 Line: 18 illegal start of expression Line: 18 ';' expected 这意味着第 18 行中有代码写得不正确(public bo
如果可能的话,如何从另一个方法的返回中调用一个方法? 例如…… class Example { public static void main(String[] args) {
当遍历指针的 vector (或其他容器)时,使用以下优势和/或优势之间是否有任何区别: for (it = v.begin(); it != v.end(); ++it) { (*it)->
在从带有参数的 void 方法打印值或将值返回给方法调用者并在方法调用者中打印它之间,哪个被认为是更好的做法(如果有的话)?比如第一个代码摘录是前者,第二个代码摘录是后者: public static
考虑这个例子https://codesandbox.io/s/1yvp4zz5x7?module=%2Fsrc%2FApp.vue Greet1 Greet2
晚上好, 我刚开始使用 Microsoft.Contracts(最新版本)并将其插入示例界面之上,现在它看起来像这样: namespace iRMA2.Core.Interfaces { us
我是 Laravel 4 的新手,并试图弄清楚为什么我收到一个错误,说 Method [show] 不存在。 我没有名为“show”的方法,只能想象这是一个内部的 Laravel 方法,但我不知道如何
有人可以向我解释一下当我们进行下一次返回时“或”(||) 是什么意思吗? 我的意思是这行: 返回封面(值,金额 - 值 [索引],索引 + 1)||覆盖(值、金额、索引 + 1); public st
这个问题已经有答案了: Why doesn't the post increment operator work on a method that returns an int? (11 个回答) 已
我很难理解 jQuery 的 $.method() 和 $(selector).method 之间的区别。 $.method() 实际适用于 DOM 中的哪些元素?如果有人能帮助解释这两种说法之间的区
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 5 年前。 Improve t
////////////////////////////////////////////////////////////////////////////// // 3 construct
我是一名优秀的程序员,十分优秀!