gpt4 book ai didi

ruby-on-rails - Rails 项目 : NoMethodError: undefined method `identifier' for String

转载 作者:太空宇宙 更新时间:2023-11-03 16:28:20 24 4
gpt4 key购买 nike

最近继承了一个Rails + Spine.JS的项目。尽管它的主题不是非常神秘(面向营销:人们制作自己的邮件列表,在发送之前准备内容,实际发送等等),但是它的实现是具体的并且依赖于多个 Rails 覆盖(就像下面问题 #2 中指定的那样)。

我有两个问题需要帮助。

问题一:

要点:在 Spine.JS 应用程序(前端)中,我们得到了发票的预览操作,它应该(并且确实)打开一个新选项卡来执行此操作。在我真正做到之前,一切看起来都很正常。没有太多毫无意义的解释,下面是发生的事情:

Started GET "/me/invoices/22/preview?oauth_token=XE03DFCGyCDYjdu8oWuU9zrN56Z6Wr7eZDuIjCbT&origin=http://localhost:9294" for 94.26.14.131 at 2013-12-08 00:55:27 +0200
Oauth2Token Load (0.3ms) SELECT `oauth_tokens`.* FROM `oauth_tokens` WHERE `oauth_tokens`.`type` IN ('Oauth2Token') AND (invalidated_at IS NULL AND authorized_at IS NOT NULL and token = 'XE03DFCGyCDYjdu8oWuU9zrN56Z6Wr7eZDuIjCbT') LIMIT 1
Processing by InvoicesController#preview as HTML
Parameters: {"oauth_token"=>"XE03DFCGyCDYjdu8oWuU9zrN56Z6Wr7eZDuIjCbT", "origin"=>"http://localhost:9294", "id"=>"22"}
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 270932 LIMIT 1
Invoice Load (0.2ms) SELECT `receipts`.* FROM `receipts` WHERE `receipts`.`type` IN ('Invoice') AND `receipts`.`id` = 22 LIMIT 1
Completed 500 Internal Server Error in 8.3ms

NoMethodError (undefined method `identifier' for "preview":String):
newrelic_rpm (3.6.9.171) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:157:in `render_with_newrelic'
actionpack (3.2.16) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.16) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.16) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.16) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.16) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.16) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.16) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.16) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.16) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.16) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.16) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'

……等等。如您所见,preview 一词是 Controller 操作的名称。

删除 NewRelic 没有帮助。然后错误被替换为:

NoMethodError (undefined method `formats' for "preview":String):

顺便说一句,Ruby 是 2.0.0-p353,而 Rails 是 3.2.16。 Rails 项目有一些自定义设置,例如大多数操作的 OAuth 参数——因为 Rails 应用主要是 Node.JS 项目的服务器存储单元。

查看 API 文档(如此处:http://www.rubydoc.info/docs/rails/3.1.1/ActionView/Template)给我的印象是 determine_template Rails 方法(以及第二种情况下的未指定方法,没有 newrelic_rpm) 不返回 ActionView::Template 而是一个 String。知道为什么会这样吗?

问题二:

在大多数情况下,调用 rake cucumber 实际上会产生这样的结果:

stack level too deep (SystemStackError)

以前的开发人员确实将其作为 ActiveRecord::Base 的扩展:

module ActiveRecord
class Base
include Documentable
...
def self.has_url
include Rails.application.routes.url_helpers

self.default_url_options = Rails.application.default_url_options

define_method :url do
send "#{self.class.to_s.underscore}_url", self
end
end
end
end

当然,这可能是原因。我已经尝试通过 ActiveRecord::Concern 方法替换那个(相当过时的)扩展 ActiveRecord 的方法,遗憾的是这没有什么区别。我已经对这个项目进行了广泛的 grep,这是其中唯一一个真正像那样包含 Rails 模块的地方,所以现在应该是该错误的唯一候选者,对吗?

对于这两个问题,我都一头雾水。我在 Rails 方面有一些经验(~15 个项目)并且从来没有遇到过这样的一年级问题。

感谢您的关注。任何想法都会受到赞赏,即使我已经尝试过了。

更新#1:

根据要求,将 before_filter 粘贴到 ApplicationController 中。

  def remove_oauth_params
params.reject! {|k,_| %w[oauth_token bearer_token access_token].include? k}
end

def save_action
@current_action = params[:action]
end

def set_access_header
if request.path == "/users/sign_out"
headers["Access-Control-Allow-Credentials"] = "true"
headers["Access-Control-Allow-Headers"] = %w{Origin Accept Content-Type X-Requested-With X-CSRF-Token X-File-Name X-File-Size Cache-Control}.join(",")
headers["Access-Control-Allow-Methods"] = "DELETE"
headers["Access-Control-Allow-Origin"] = "http://#{Settings.app_domain}"
else
headers["Access-Control-Allow-Origin"] = "*"
headers["Access-Control-Allow-Methods"] = %w{GET POST PUT DELETE PATCH}.join(",")
headers["Access-Control-Allow-Headers"] = %w{Origin Accept Content-Type X-Requested-With X-CSRF-Token X-File-Name X-File-Size Cache-Control}.join(",")
end
head(:ok) if request.request_method == "OPTIONS"
end

def set_limit_and_offset
@limit = params.delete(:limit).to_i
@limit = default_limit unless (1..default_limit).include?(@limit)
@offset = params.delete(:offset).to_i
@offset = 0 unless @offset > 0
end

至于 InvoiceController,非常基础:

class InvoicesController < ApplicationController
oauthenticate :interactive => false

layout "invoice"

def preview
@i = Invoice.find(params[:id])
@origin = params[:origin]
end
end

更新#2:

$ rake cucumber --trace
** Invoke cucumber (first_time)
** Invoke cucumber:ok (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:test:purge
** Invoke environment
** Execute db:test:load
** Invoke db:test:load_schema (first_time)
** Invoke db:test:purge
** Execute db:test:load_schema
** Invoke db:schema:load (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:schema:load
** Invoke db:seed (first_time)
** Execute db:seed
** Invoke db:abort_if_pending_migrations
building users for ce and ce-int brands
building example CE app owner
building CE beta app
** Execute cucumber:ok
/usr/local/rvm/rubies/ruby-2.0.0-p353/bin/ruby -S bundle exec cucumber --profile default
Using the default profile...
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
Feature: Creation of robinson entries
Create a robinson entry to prevent recipients from being mailed

Background: # features/blocked_address/blocked_address_creation.feature:4
Given there is the example customer with id 200 # features/step_definitions/data_steps.rb:41
stack level too deep (SystemStackError)
features/blocked_address/blocked_address_creation.feature:5:in `Given there is the example customer with id 200'

最佳答案

编辑:参见 dimitkos comment寻求解决方案。

恐怕我没有简单的答案,只有两个调试建议:

对于问题1:

  • 包含 Ruby 调试器
  • 在控制台中,调用 app.get "/me/invoices/22/preview?oauth_token=XE03DFCGyCDYjdu8oWuU9zrN56Z6Wr7eZDuIjCbT&origin=http://localhost:9294"
  • 在堆栈中查找字符串的来源

至于2:你用git做源码控制吗?

如果是,这是尝试 git bisect 的最佳时机。你找到了一个旧的提交,其中 rake cucumber 仍在工作,而 git 帮助你在非常少的步骤中找到破坏它的提交。更多信息:Debugging with Git - Binary search

关于ruby-on-rails - Rails 项目 : NoMethodError: undefined method `identifier' for String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20452322/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com