Rails 프로젝트 : NoMethodError : String에 대한 정의되지 않은 메서드`identifier '

디미타르 프

최근에 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보시 다시피이 단어 는 컨트롤러 작업의 이름입니다.

NewRelic을 제거해도 도움이되지 않습니다. 그런 다음 오류는 다음으로 대체됩니다.

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

BTW, 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_templateRails 메서드 (그리고 두 번째 경우에는 지정되지 않은 메서드) 라는 인상이 남습니다 . 하지 않고는 newrelic_rpm) 반환하지 않습니다 ActionView::Template하지만 String. 왜 그럴까요?

문제 2 :

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를 확장하기 위해 (아주 쓸모없는) 방법을 대체하려고 시도했지만 ActiveRecord::Concern슬프게도 아무런 차이가 없습니다. 나는 이미 프로젝트를 상당히 광범위하게 grep했다. 그것은 Rails 모듈이 실제로 그렇게 포함 된 유일한 곳이다. 그래서 지금 그 오류에 대한 유일한 후보가되어야한다.

이 두 가지 문제에 대해 저는 완전히 손실을 입었습니다. 저는 Rails (~ 15 개 프로젝트)에서 일종의 경험을했고 그런 1 학년 문제가 없었습니다.

주목 해 주셔서 감사합니다. 이미 시도 했더라도 어떤 아이디어라도 감사하겠습니다.

업데이트 # 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'
Janfoeh

편집 : 솔루션에 대한 dimitkos 주석참조하십시오 .

쉬운 대답은 없지만 두 가지 디버깅 제안 만 있습니다.

문제 1 :

  • Ruby 디버거 포함
  • 콘솔에서 app.get "/me/invoices/22/preview?oauth_token=XE03DFCGyCDYjdu8oWuU9zrN56Z6Wr7eZDuIjCbT&origin=http://localhost:9294"
  • 스택 위로 올라가서 문자열이 어디에서 왔는지 확인하십시오.

2 : 소스 제어에 git을 사용합니까?

그렇다면 지금은 사용해보기에 완벽한 순간 git bisect입니다. rake cucumber여전히 작동 하는 오래된 커밋 을 찾고 git은 몇 단계 만에 커밋을 깨뜨린 커밋을 찾는 데 도움을줍니다. 더보기 : Git으로 디버깅-이진 검색

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Rails + Paperclip-프로젝트의 NoMethodError #index-nil : NilClass에 대한 정의되지 않은 메소드`image '

분류에서Dev

Heroku + Rails : NoMethodError (nil : NilClass에 대한 정의되지 않은 메서드`/ ')

분류에서Dev

Android Volley Rails : NoMethodError ( "": String에 대해 정의되지 않은 메서드`+ @ ')

분류에서Dev

NoMethodError : "Truck"에 대한 정의되지 않은 메서드`find ': String

분류에서Dev

Rails NoMethodError (Hyperclient : Module에 대한 정의되지 않은 메소드`new ')

분류에서Dev

Ruby on Rails 배우기 : NoMethodError (nil : NilClass에 대한 정의되지 않은 메소드`[] ') :

분류에서Dev

Ruby on Rails 배우기 : NoMethodError (nil : NilClass에 대한 정의되지 않은 메소드`[] ') :

분류에서Dev

Rails NoMethodError : "# <RecipeType : 0x000055cd000b18a0>"에 대한 정의되지 않은 메서드`name ': String

분류에서Dev

Rails 오류 : NoMethodError : Capistrano :: Configuration : Class에 대한 정의되지 않은 메서드 '인스턴스' 대신에?

분류에서Dev

nil : NilClass에 대한 NoMethodError 정의되지 않은 메서드`name '

분류에서Dev

nil : NilClass <NoMethodError>에 대한 정의되지 않은 메서드 '[]'

분류에서Dev

NoMethodError : nil : NilClass에 대한 정의되지 않은 메서드 'user'

분류에서Dev

NoMethodError (true : TrueClass에 대한 정의되지 않은 메서드`persisted? ')

분류에서Dev

NoMethodError : nil : NilClass에 대한 정의되지 않은 메서드`+ '

분류에서Dev

NoMethodError : # <Class>에 대한 정의되지 않은 메서드`type '

분류에서Dev

NoMethodError : RSpec에 대한 정의되지 않은 메서드`get '

분류에서Dev

NoMethodError (nil : NilClass에 대한 정의되지 않은 메서드`[] ') : Ruby on Rails에서 dig를 사용할 때도

분류에서Dev

NoMethodError : Rails Minitest의 # <Hash : 0x007facebc78c98>에 대한 정의되지 않은 메서드 'permit'

분류에서Dev

Heroku의 Rails 4.0, NoMethodError (# <User에 대한 정의되지 않은 메서드`password_digest = '

분류에서Dev

"# <NoMethodError : \"derp \ ": String>에 대해 정의되지 않은 메서드`permit ',

분류에서Dev

`build ': rails s를 실행할 때 ExceptionNotifier : Module (NoMethodError)에 대한 정의되지 않은 메서드`new'

분류에서Dev

Ruby on Rails NoMethodError : # <User : 0x50987b8>에 대한 정의되지 않은 메서드` '

분류에서Dev

NoMethodError : "foo"에 대한 정의되지 않은 메서드`first_or_create ': String

분류에서Dev

true : TrueClass (NoMethodError)에 대한 정의되지 않은 메소드`each '

분류에서Dev

false에 대한 정의되지 않은 메소드`[] ': FalseClass (NoMethodError)

분류에서Dev

nil : NilClass에 대한 정의되지 않은 메소드`+ '(NoMethodError)-Ruby

분류에서Dev

NoMethodError : main : Object에 대한 정의되지 않은 메소드`within '

분류에서Dev

Gentoo의 Redmine : # <Rails :: Application :: Configuration : 0x00000000ea5538>에 대한 정의되지 않은 메소드`active_record '(NoMethodError)

분류에서Dev

Rails-NoMethodError : Model.find_by의 nil : NilClass에 대한 정의되지 않은 메소드`each '

Related 관련 기사

  1. 1

    Rails + Paperclip-프로젝트의 NoMethodError #index-nil : NilClass에 대한 정의되지 않은 메소드`image '

  2. 2

    Heroku + Rails : NoMethodError (nil : NilClass에 대한 정의되지 않은 메서드`/ ')

  3. 3

    Android Volley Rails : NoMethodError ( "": String에 대해 정의되지 않은 메서드`+ @ ')

  4. 4

    NoMethodError : "Truck"에 대한 정의되지 않은 메서드`find ': String

  5. 5

    Rails NoMethodError (Hyperclient : Module에 대한 정의되지 않은 메소드`new ')

  6. 6

    Ruby on Rails 배우기 : NoMethodError (nil : NilClass에 대한 정의되지 않은 메소드`[] ') :

  7. 7

    Ruby on Rails 배우기 : NoMethodError (nil : NilClass에 대한 정의되지 않은 메소드`[] ') :

  8. 8

    Rails NoMethodError : "# <RecipeType : 0x000055cd000b18a0>"에 대한 정의되지 않은 메서드`name ': String

  9. 9

    Rails 오류 : NoMethodError : Capistrano :: Configuration : Class에 대한 정의되지 않은 메서드 '인스턴스' 대신에?

  10. 10

    nil : NilClass에 대한 NoMethodError 정의되지 않은 메서드`name '

  11. 11

    nil : NilClass <NoMethodError>에 대한 정의되지 않은 메서드 '[]'

  12. 12

    NoMethodError : nil : NilClass에 대한 정의되지 않은 메서드 'user'

  13. 13

    NoMethodError (true : TrueClass에 대한 정의되지 않은 메서드`persisted? ')

  14. 14

    NoMethodError : nil : NilClass에 대한 정의되지 않은 메서드`+ '

  15. 15

    NoMethodError : # <Class>에 대한 정의되지 않은 메서드`type '

  16. 16

    NoMethodError : RSpec에 대한 정의되지 않은 메서드`get '

  17. 17

    NoMethodError (nil : NilClass에 대한 정의되지 않은 메서드`[] ') : Ruby on Rails에서 dig를 사용할 때도

  18. 18

    NoMethodError : Rails Minitest의 # <Hash : 0x007facebc78c98>에 대한 정의되지 않은 메서드 'permit'

  19. 19

    Heroku의 Rails 4.0, NoMethodError (# <User에 대한 정의되지 않은 메서드`password_digest = '

  20. 20

    "# <NoMethodError : \"derp \ ": String>에 대해 정의되지 않은 메서드`permit ',

  21. 21

    `build ': rails s를 실행할 때 ExceptionNotifier : Module (NoMethodError)에 대한 정의되지 않은 메서드`new'

  22. 22

    Ruby on Rails NoMethodError : # <User : 0x50987b8>에 대한 정의되지 않은 메서드` '

  23. 23

    NoMethodError : "foo"에 대한 정의되지 않은 메서드`first_or_create ': String

  24. 24

    true : TrueClass (NoMethodError)에 대한 정의되지 않은 메소드`each '

  25. 25

    false에 대한 정의되지 않은 메소드`[] ': FalseClass (NoMethodError)

  26. 26

    nil : NilClass에 대한 정의되지 않은 메소드`+ '(NoMethodError)-Ruby

  27. 27

    NoMethodError : main : Object에 대한 정의되지 않은 메소드`within '

  28. 28

    Gentoo의 Redmine : # <Rails :: Application :: Configuration : 0x00000000ea5538>에 대한 정의되지 않은 메소드`active_record '(NoMethodError)

  29. 29

    Rails-NoMethodError : Model.find_by의 nil : NilClass에 대한 정의되지 않은 메소드`each '

뜨겁다태그

보관