- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试记录我的 REST API 应用程序的请求。我为此使用 Rails 通知,例如这里 http://railscasts.com/episodes/249-notifications-in-rails-3
我不明白如何用 rails 通知解决一个问题。
我的初始化代码
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, start, finish, id, payload|
p name
p start
p finish
p id
p payload
end
Controller respond section
class PostsController < ApplicationController
# GET /posts
# GET /posts.json
respond_to :json, :html
....
end
def create
@post = Post.new(params[:post])
@post.save!
respond_with(@post, :location => nil)
end
"process_action.action_controller"
2013-02-02 20:13:11 +0200
2013-02-02 20:13:11 +0200
"951b8999e9b71d4a8949"
{:controller=>"PostsController", :action=>"create", :params=>{"utf8"=>"✓", "authenticity_token"=>"1WugY9gh6ZCRXjfBTuckye3c9XDvtCqMQ2JdBpCo88s=", "post"=>{"name"=>"post3", "title"=>"post3", "content"=>"post3"}, "commit"=>"Create Post", "action"=>"create", "controller"=>"posts"}, :format=>:html, :method=>"POST", :path=>"/posts", :status=>302, :view_runtime=>nil, :db_runtime=>0}
def create
@post = Post.new(params[:post])
#@post.save!
#respond_with(@post)
respond_to do |format|
if @post.save
format.html { redirect_to @post, notice: 'Post was successfully created.' }
format.json { render json: @post, status: :created, location: @post }
else
format.html { render action: "new" }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
"process_action.action_controller"
2013-02-02 20:22:51 +0200
2013-02-02 20:22:51 +0200
"bf2a3173c08a0fd9008e"
{:controller=>"PostsController", :action=>"create", :params=>{"utf8"=>"✓", "authenticity_token"=>"1WugY9gh6ZCRXjfBTuckye3c9XDvtCqMQ2JdBpCo88s=", "post"=>{"name"=>"post3", "title"=>"post3", "content"=>"post3"}, "commit"=>"Create Post", "action"=>"create", "controller"=>"posts"}, :format=>:html, :method=>"POST", :path=>"/posts", :status=>302, :view_runtime=>nil, :db_runtime=>4.727}
bundle show rails
/Users/admin/.rvm/gems/ruby-1.9.3-p125/gems/rails-3.2.11
rvm current
ruby-1.9.3-p125
最佳答案
好吧,这似乎是一个错误。让我们看看,发生了什么:
首先,我们有用于 Controller 操作的 AR railtie 及其使用 cleanup_view_runtime 钩子(Hook)设置 db_runtime 的实现
def cleanup_view_runtime
if ActiveRecord::Base.connected?
db_rt_before_render = ActiveRecord::LogSubscriber.reset_runtime
runtime = super
db_rt_after_render = ActiveRecord::LogSubscriber.reset_runtime
self.db_runtime = db_rt_before_render + db_rt_after_render
runtime - db_rt_after_render
else
super
end
end
def respond_with(*resources, &block)
raise "In order to use respond_with, first you need to declare the formats your " <<
"controller responds to in the class level" if self.class.mimes_for_respond_to.empty?
if collector = retrieve_collector_from_mimes(&block)
options = resources.size == 1 ? {} : resources.extract_options!
options[:default_response] = collector.response
(options.delete(:responder) || self.class.responder).call(self, resources, options)
end
end
def self.call(*args)
new(*args).respond
end
def to_format
if get? || !has_errors? || response_overridden?
default_render
else
display_errors
end
rescue ActionView::MissingTemplate => e
api_behavior(e)
end
db_rt_before_render = ActiveRecord::LogSubscriber.reset_runtime
runtime = super # <-- here
db_rt_after_render = ActiveRecord::LogSubscriber.reset_runtime
关于ruby-on-rails - rails activesupport 通知 - 错误的数据库运行时值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14665016/
当我尝试执行 rails server 和 thin start 时,两者都说:“在任何来源中都找不到 activesupport-3.0.6。” 我安装了 activesupport-3.0.7。我
在迁移到 rails 5 之前,它运行良好,但是当我迁移到 rails 5.1.1 时,它给我这样的错误 ActiveSupport::MessageVerifier::InvalidSignatur
在尝试启动某个开源 Rails 项目的旧版本时,遇到了一条多云的错误消息: “无法激活 activesupport (>= 2.3.2, runtime),已经激活 activesupport-2.1
我在将我的 React on Rails 应用程序部署到 Heroku 时遇到了一些麻烦。我已经阅读并尝试了无数关于如何解决 secret_key_base 和 rails_master_key 问题
我已将 Ruby on Rails 应用程序从 Rails 5.1.2 迁移到 Rails 5.2.0 以使用加密的 secret 。应用程序已成功部署到 Digital Ocean Ubuntu 服
我已将 Ruby on Rails 应用程序从 Rails 5.1.2 迁移到 Rails 5.2.0 以使用加密的 secret 。应用程序已成功部署到 Digital Ocean Ubuntu 服
我找到了 ActiveSupport 变形器类。在哪里可以找到初始化英文变形器的代码? 最佳答案 ActiveSupport inflector.rb文件包含所有词形变化库和模块。 如果您想自定义它,
我正在使用带有 rails 3 的 mongoid 并且最近遇到了一个非常艰难的问题 问题,我需要一个建议。 我正在开发 CMS,其中一个想法是 CMS 将提供 一些基本模型定义和最终用户将在需要时扩
我在纽约有我的 Linux 服务器,配置为 GMT。 我所有的日期都以 UTC 格式保存。 要将这些日期返回给客户,我唯一需要做的是 ? date = my_date.utc_to_local 不管我
我有一个令人尴尬的基本问题: 我正在研究一个处理金钱的普通老式 ruby 模型,一些类方法返回需要格式化才能显示的价格。 过去我曾使用 include ActionView::Helpers::N
我遇到了一个小问题...我正要在 Exercism.io 上开始一些卡塔练习当我运行测试时,我有一个 Gem:ConflictError /Users/john/.rbenv/versions/2.4
我有一个这样的日期对象: >> the_date => Tue, 12 Jun 2012 >> the_date.class => Date 和一个存储为字符串的时区: >> tz = "Pacifi
我已经从 Rails 应用程序中提取了一个类到 a gem 中.它非常非常简单,但我当然想对其进行全面测试(我使用的是 rspec)。 该类进行一些简单的日期计算。它不依赖于 Rails,但由于它是在
我很高兴也很惊讶地发现 ActiveSupport 以我想要的方式计算月数。无论所讨论的月份有多少天,添加 1.month到特定的 Time将使您与 Time 在同一天. > Time.utc(201
我有一个非常简单的设置来测试 rails3 ActiveSupport::Notifications。通过阅读文档,ActiveSupport::Notifications.subscribe 位应该
是否可以在类方法上使用 ActiveSupport::Callbacks?更具体地说,在下面的模块中,您会将 include ActiveSupport::Callbacks 放在哪里,以使 defi
我想在我的一个模型上使用 ActiveSupport 选项 encode_big_decimal_as_string。我应该把它放在模型中吗?我是否在模型实例上调用此方法?我要把它放在配置中的某个地方
我正在研究 CodeSchool 的 RubyBits,我做了一个我只是不理解的练习:“确保 AtariLibrary 类只包含 LibraryUtils 模块,并让 ActiveSupport::C
我在 Rails 3 应用程序中收到 SystemStackError。 我拥有的所有信息都是无用的一行堆栈跟踪(从日志中获取): SystemStackError (stack level too
我知道 include 用于将模块方法作为实例方法访问,而 extend 用于将模块方法作为类方法访问。 对于 ActiveSupport::Concern 某处我看到写成, module Test
我是一名优秀的程序员,十分优秀!