2013-05-03 6 views
2

Windows입니다. Ruby v.1.9.3p392/Rails v. 3.2.13 - Michael Hart의 Ruby on Rails 튜토리얼의 2 장에서 나온 demo_app 프로젝트입니다.dynamic_matchers.rb : 55 :`method_missing ': ActiveRecord :: Base : Class (NoMethodError)에 대해 정의되지 않은 메소드`migration_error ='

이 오류는 'rails generate scaffold'를 발행 할 때 발생합니다. 사용자 이름 : 문자열 전자 메일 : 문자열 '이 문제를 해결하는 방법은 무엇입니까?

C:\ruby\rails_projects\demo_app>rails generate scaffold User name:string email:s 
tring 
     invoke active_record 
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/act 
ive_record/dynamic_matchers.rb:55:in `method_missing': undefined method `migrati 
on_error=' for ActiveRecord::Base:Class (NoMethodError) 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3 
.2.13/lib/active_record/railtie.rb:66:in `block (3 levels) in <class:Railtie>' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3 
.2.13/lib/active_record/railtie.rb:65:in `each' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3 
.2.13/lib/active_record/railtie.rb:65:in `block (2 levels) in <class:Railtie>' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 
3.2.13/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 
3.2.13/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 
3.2.13/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 
3.2.13/lib/active_support/lazy_load_hooks.rb:42:in `each' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 
3.2.13/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3 
.2.13/lib/active_record/base.rb:720:in `<top (required)>' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 
3/lib/rails/generators/named_base.rb:166:in `pluralize_table_names?' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 
3/lib/rails/generators/named_base.rb:114:in `table_name' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3 
.2.13/lib/rails/generators/active_record/model/model_generator.rb:17:in `create_ 
migration_file' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/command.rb:27:in `run' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/invocation.rb:120:in `invoke_command' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/invocation.rb:127:in `block in invoke_all' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/invocation.rb:127:in `each' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/invocation.rb:127:in `map' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/invocation.rb:127:in `invoke_all' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/group.rb:233:in `dispatch' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/invocation.rb:109:in `invoke' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/group.rb:278:in `block in _invoke_for_class_method' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/shell.rb:74:in `with_padding' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/group.rb:267:in `_invoke_for_class_method' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/group.rb:150:in `_invoke_from_option_orm' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/command.rb:27:in `run' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/invocation.rb:120:in `invoke_command' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/invocation.rb:127:in `block in invoke_all' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/invocation.rb:127:in `each' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/invocation.rb:127:in `map' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/invocation.rb:127:in `invoke_all' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/group.rb:233:in `dispatch' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.18.1/li 
b/thor/base.rb:439:in `start' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 
3/lib/rails/generators.rb:171:in `invoke' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 
3/lib/rails/commands/generate.rb:12:in `<top (required)>' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 
3.2.13/lib/active_support/dependencies.rb:251:in `require' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 
3.2.13/lib/active_support/dependencies.rb:251:in `block in require' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 
3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 
3.2.13/lib/active_support/dependencies.rb:251:in `require' 
     from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 
3/lib/rails/commands.rb:29:in `<top (required)>' 
     from bin/rails:4:in `require' 
     from bin/rails:4:in `<main>' 

dynamic_matchers.rb

module ActiveRecord 
    module DynamicMatchers 
    def respond_to?(method_id, include_private = false) 
     if match = DynamicFinderMatch.match(method_id) 
     return true if all_attributes_exists?(match.attribute_names) 
     elsif match = DynamicScopeMatch.match(method_id) 
     return true if all_attributes_exists?(match.attribute_names) 
     end 

     super 
    end 

    private 

    # Enables dynamic finders like <tt>User.find_by_user_name(user_name)</tt> and 
    # <tt>User.scoped_by_user_name(user_name). Refer to Dynamic attribute-based finders 
    # section at the top of this file for more detailed information. 
    # 
    # It's even possible to use all the additional parameters to +find+. For example, the 
    # full interface for +find_all_by_amount+ is actually <tt>find_all_by_amount(amount, options)</tt>. 
    # 
    # Each dynamic finder using <tt>scoped_by_*</tt> is also defined in the class after it 
    # is first invoked, so that future attempts to use it do not run through method_missing. 
    def method_missing(method_id, *arguments, &block) 
     if match = (DynamicFinderMatch.match(method_id) || DynamicScopeMatch.match(method_id)) 
     attribute_names = match.attribute_names 
     super unless all_attributes_exists?(attribute_names) 
     if !(match.is_a?(DynamicFinderMatch) && match.instantiator? && arguments.first.is_a?(Hash)) && arguments.size < attribute_names.size 
      method_trace = "#{__FILE__}:#{__LINE__}:in `#{method_id}'" 
      backtrace = [method_trace] + caller 
      raise ArgumentError, "wrong number of arguments (#{arguments.size} for #{attribute_names.size})", backtrace 
     end 
     if match.respond_to?(:scope?) && match.scope? 
      self.class_eval <<-METHOD, __FILE__, __LINE__ + 1 
      def self.#{method_id}(*args)         # def self.scoped_by_user_name_and_password(*args) 
       attributes = Hash[[:#{attribute_names.join(',:')}].zip(args)] # attributes = Hash[[:user_name, :password].zip(args)] 
                      # 
       scoped(:conditions => attributes)        # scoped(:conditions => attributes) 
      end                # end 
      METHOD 
      send(method_id, *arguments) 
     elsif match.finder? 
      options = if arguments.length > attribute_names.size 
         arguments.extract_options! 
        else 
         {} 
        end 

      relation = options.any? ? scoped(options) : scoped 
      relation.send :find_by_attributes, match, attribute_names, *arguments, &block 
     elsif match.instantiator? 
      scoped.send :find_or_instantiator_by_attributes, match, attribute_names, *arguments, &block 
     end 
     else 
     super 
     end 
    end 

    # Similar in purpose to +expand_hash_conditions_for_aggregates+. 
    def expand_attribute_names_for_aggregates(attribute_names) 
     attribute_names.map { |attribute_name| 
     unless (aggregation = reflect_on_aggregation(attribute_name.to_sym)).nil? 
      aggregate_mapping(aggregation).map do |field_attr, _| 
      field_attr.to_sym 
      end 
     else 
      attribute_name.to_sym 
     end 
     }.flatten 
    end 

    def all_attributes_exists?(attribute_names) 
     (expand_attribute_names_for_aggregates(attribute_names) - 
     column_methods_hash.keys).empty? 
    end 

    def aggregate_mapping(reflection) 
     mapping = reflection.options[:mapping] || [reflection.name, reflection.name] 
     mapping.first.is_a?(Array) ? mapping : [mapping] 
    end 


    end 
end 

답변

7

좋아, 그래서 다른 사람이이 문제에 대한 해결책을 찾을 수 있었고, 내가 그것을 다른 사람을 위해 온다 여기 경우에 그것을 공유 할 수 있습니다.

내 레일 버전이 최근 버전으로 설정되었지만 필자가 만든 앱에서 오래된 레일 버전을 생성하는 것으로 나타났습니다. 3.2.13

따라서 내 config/application.rb 파일은 레일스 3.2.13 버전과 완전히 다릅니다. application.rb 파일이 대체 된 후. 오류가 수정되었습니다.

Windows 사용자가 현재 버전을 제어 할 경우이 오류를 방지하려면 rvm 또는 pik을 사용할 수 있습니다. 새 응용 프로그램을 만들 때 레일 버전을 지정 '3.2.13 your_app 레일', 또는 모든 버전을 레일 제거하고 당신이 필요로하는 하나 설치할 수 있습니다

보석 제거 레일 모든 버전 -choose

는 보석 조언 (+1)에 대한 레일 --version '= 3.2.13'

+0

는, 그것이 있어야는 레일을 지정하는 '새로운 demo_app 3.2.13 레일' 필요한 경우 앱의 버전입니다. – LilithX

+0

죄송합니다. 올바른 명령입니다. 'rails _3.2.13_ new newappname' – LilithX

+0

음, 버전 사양이 여전히 잘못되었습니다. 권자하지만 그것은 필요하지 않습니다. 레일은 기본적으로 최신 버전을 설치합니다; – RGB

1

감사를 설치, 저도 같은 문제를 겪고 ...

앱 초기화를 만든 ially 레일의 이전 버전과 ... 내 유증 물건을 돌파 (3.2.13)를 최신으로 충돌

모든 것을이 필요했다

config/application.rb

0

의 상단에 require "rails/all"을 추가했다 나는 비슷한 있었다 정의되지 않은 메소드 인 'has_many'에 대해 불평하는 문제. 나는 문제를 깨닫기 전에 루비와 레일 버전과 보석을 만지며 보냈다 ... has_many 이전의 여분의 공간!

필자는 다른 장소 (모든 종류의 이상한 서식을 사용하는 Evernote)에서 이전 코드를 복사했으며 공백 세부 정보가 이런 식으로 엉망이 될 수 있음을 인식하지 못했습니다. 공백을 삭제하고 수동으로 다시 넣으면 문제가 해결됩니다.

(이건 정말 원래의 질문에 대한 답변이 아니라 내 검색 여기에 저를지도하고 여기에 다른 사람을 이끌 수 있습니다.)

실제로