- 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/
我从 Subdomain RailsCast 获取代码 module UrlHelper def with_subdomain(subdomain) subdomain = (subdom
我有一个使用 nginx 进行反向代理/ssl 终止的 flask 应用程序,但是在 flask 中使用 url_for 和重定向时遇到了麻烦。 nginx.conf 条目: location /fl
设置url_for() Jinja2 模板中的 非常简单(只要它在 HTML 中)。我一直在尝试从 JQuery 内部设置它,如下所示: function my_func(key) {
场景:HTTP 反向代理后面的 Flask + Flask-login Flask 应用程序位于 http://localhost:5000/公共(public)应用程序 http://example
我喜欢很多约定 Overholt example使用过,但遇到了特定问题。 我使用 werkzeug.wsgi 中的 DispatcherMiddleware 对象设置了两个应用程序: from we
这个问题已经有答案了: How to serve static files in Flask (24 个回答) Import javascript files with jinja from stat
我是 flask 和 html 的新手。当我尝试在我的 html 代码中使用 action 属性时出现构建错误,我不知道为什么会发生这种情况。这是我的 html 代码: 还有我的 flask
我们的服务器 (xxxx.edu.au:5000) 上运行着一个 Flask 应用程序。但是,我们设置了代理xxxx.edu.au/getseq它将请求转发到 xxxx.edu.au:5000 不幸的
这个问题已经有答案了: Pass JavaScript variable to Flask url_for (4 个回答) 已关闭 6 年前。 我有这条路线: @my_app.route('/get_
我正在为 Flask 应用程序编写一些测试,遇到一个问题,即我的 test_client 响应中的 URL 与从测试用例中调用 url_for 生成的 URL 不匹配。例如,我的模板中有以下内容: R
url_for 是否跨蓝图工作? /flaskapp /runserver.py (from server import app; app.run(debug=True))
我正在编写一个脚本来收集那些没有收到电子邮件确认电子邮件的用户的电子邮件并将其重新发送给他们。该脚本显然在 Flask 应用程序上下文之外工作。我想使用 url_for() 但无法正确使用。 def
我正在构建一个辅助方法,它允许我传递一个数组,其中包含我希望可用于管理对象(如编辑、删除等)的选项。该方法的简化版本如下所示: def management_links(instance, act
什么时候应该使用命名路由与使用带有 {:controller => "somecontroller", :action => "someaction"} 哈希的 url_for ? 一个比另一个更受欢
我正在尝试在我的管理页面中的某个 ModelView 上加载脚本: class CustomView(ModelView): # Neither approach works here:
我必须在一页(设置)上为多个表编辑/创建表单。因此我创建了 SettingsController。 路线: resources :settings, :only => :index do memb
因为 'code' 是下面 MethodView 类 C 的 get 方法的参数,当我调用 url_for('c', code='O7A') 时,我希望得到的 url 是:/c/O7A 我看到的不是预
我开发多语言网站。 页面有这样的 URI: /RU/about /EN/about /IT/about /JP/about /EN/contacts 在 jinja2 模板中,我写道: About 我
我正在 Flask 中构建模块化应用程序,如果我从当前蓝图中引用另一个蓝图中的函数,我会不断收到构建错误,例如 我有一个文件 userProfiles.py @userP.route('/myProf
我试图找到一个与 Flask 的 url_for 等效的 django 方法。 我不是在寻找 jinja 等价物(如图所示 here )——我说的是在房子的 python 方面 在我的 flask 应
我是一名优秀的程序员,十分优秀!