2011-01-18 20 views
1

레일즈 3에 플러그인을 개발했습니다. 레일즈 3에는 모델 용 문서 저장소가 있습니다. 모든 모델에서 특정 이름의 문서를 원하는 수만큼 첨부 할 수 있습니다. 처럼.TypeError (nil을 Integer로 변환 할 수 없음) :

class Person < ActiveRecord::Base 
    attach_documents_as :job_documents 
    attach_documents_as :personal_documents 
end 

매우 효과적이었습니다. 나는 그것이 어리 석다는 것을 알고 있지만, 오늘은 프로젝트를 시작하고 죽은 채 발견되었습니다. 왜 그런 일이 일어나는지 알 수 없습니다. 알아낼 수는 있지만 운이 없다. 신규 및 업데이트 양식은 잘 보여 주지만 언제든지 생성하거나 업데이트하면 오류가 발생합니다.

TypeError (can't convert nil into Integer): 

내가 그것을 디버깅을 시도하지만 컨트롤러의 작성 또는 갱신 방법에 들어가기 전에 오류가 발생

큰 오류를주고있다.

하고 완전한 오류 로그는 다음과 같습니다

Error during failsafe response: ActionView::Template::Error 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in `method_missing' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/http/parameters.rb:10:in `parameters' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb:3:in `__home_likewise_open____________nazar_hussain__rvm_gems_ruby_______p__gems_actionpack_______lib_action_dispatch_middleware_templates_rescues_diagnostics_erb__205668074_102092250__741834326' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_view/template.rb:135:in `block in render' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/notifications.rb:54:in `instrument' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_view/template.rb:127:in `render' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_view/render/rendering.rb:59:in `block in _render_template' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/notifications.rb:52:in `block in instrument' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/notifications.rb:52:in `instrument' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_view/render/rendering.rb:56:in `_render_template' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_view/render/rendering.rb:26:in `render' 
nazar.hussain/osd/development/atlantis/vendor/plugins/active_scaffold/lib/extensions/action_view_rendering.rb:86:in `render_with_active_scaffold' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/show_exceptions.rb:88:in `rescue_action_locally' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/show_exceptions.rb:68:in `render_exception' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/show_exceptions.rb:59:in `rescue in call' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/show_exceptions.rb:46:in `call' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/rack/logger.rb:13:in `call' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/runtime.rb:17:in `call' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/cache/strategy/local_cache.rb:72:in `call' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/lock.rb:11:in `block in call' 
     <internal:prelude>:10:in `synchronize' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/lock.rb:11:in `call' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/static.rb:30:in `call' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/application.rb:168:in `call' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/rack/log_tailer.rb:14:in `call' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/content_length.rb:13:in `call' 
nazar.hussain/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/handler/webrick.rb:52:in `service' 
nazar.hussain/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service' 
nazar.hussain/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run' 
nazar.hussain/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread' 

희망은 어떤 사람이 문제에서 찾게됩니다. 나는 충분히 감사 할 것이다.

컨트롤러는 단순한 발판이다 : 추가로 줄을 내가 코드를 게시하고 요청에 따라

. 여기 만들고 편집

에서 @testing.build_documents 플러그인 코드

module AttachDocumentsAs 
    module Attacher 

    def attach_documents_as(*attachment_as) 
     @as   = nil 
     @type_model = 'AttachDocumentsAs::Models::AttachedDocumentsDefaultType' 

     attachment_as = attachment_as.to_a.flatten.compact.map(&:to_sym) 
     @as   = attachment_as.first 

     if attachment_as.size > 1 
     @type_model = attachment_as.second 
     end 

     class_inheritable_reader(@as) 

     class_inheritable_reader(:atd_as) 
     write_inheritable_attribute(:atd_as, @as) 

     class_inheritable_reader(:atd_as_type) 
     write_inheritable_attribute(:atd_as_type, @type_model) 

     if @type_model.to_s.camelize.constantize.is_a?(Class) 
     class_eval do 
      has_many @as, :as => :attachable, :class_name=>"AttachDocumentsAs::Models::AttachedDocument" 
      accepts_nested_attributes_for @as 

      include AttachDocumentsAs::Attacher::Core 
     end 
     end 

    rescue NameError 
     puts "Model with name #{"#{@as}DocType".camelize.constantize} does not exits" 
    end 

    end 
end 

module AttachDocumentsAs 
    module Attacher 
    module Core 

     def self.included(base) 
     base.send :include, AttachDocumentsAs::Attacher::Core::InstanceMethods 
     base.extend AttachDocumentsAs::Attacher::Core::ClassMethods 
     end 

     module InstanceMethods 
     def build_documents(count=1) 
      1.upto count do 
      self.send(self.send(:atd_as)).build 
      end 
      docs = self.send(self.send(:atd_as)) 
      0.upto (count-1) do |i| 
      docs[i].typeable = self.send(:atd_as_type).to_s.camelize.constantize.new 
      end 
     end 
     end 

     module ClassMethods 
     end 
    end 
    end 
end 

마지막으로 폼 모델 여기서

class Testing < ActiveRecord::Base 

    attach_documents_as :xdocs, :XdocsDocType 

end 

입니다

<%= simple_form_for(@testing, :html => {:multipart => true}) do |f| %> 
    <%= f.error_notification %> 

    <div class="inputs"> 
     <%= f.input :title %> 
    </div> 

    <div class="inputs"> 
     <%= f.simple_fields_for :xdocs do |x| %> 
      <% if x.object.new_record? %> 
       <div class="inputs"> 
       <%= x.input :attachment, :as=>:file %> 
       <%= x.input :title, :as=>:string %> 
       <%= x.input :description, :as=>:text %> 
       <%= x.input :type, :as=>:attachment_type %> 
       </div> 
      <% end %> 
     <% end %> 

    </div> 

    <div class="actions"> 
     <%= f.button :submit %> 
    </div> 
<% end %> 
+1

거기에 존재하지 않는 코드를 부르지 않습니까? 우리가 컨트롤러 코드를 게시하여 우리가 그것에 대해 명확하게 알 수 있습니까? – Kunday

+0

코드로 질문을 업데이트했습니다. –

답변

2

이 플러그인을 attachment_fu 예정이었다 . 나는 플러그인을 제거하고 모든 것은 잘 작동한다. 플러그인을 다시 설치하면 같은 문제가 발생합니다. 그래서 attachment_fu가 충돌을 일으키고 있음이 분명해졌습니다.

+0

충돌을 해결할 수 있었습니까? – deb

+0

아니요, 많이 시도했지만 문제를 일으키는 정확한 문제를 찾을 수 없습니다. 나중에 클립으로 바꿨습니다. –

관련 문제