2014-02-20 3 views
0

정의되지 않은 메소드를 가져 오는 중 '비어 있습니까?' 현재 logged_in 사용자를 모델에 저장하려고 할 때 컨트롤러에서 # 오류가 발생했습니다.has_one 및 mongoid : 정의되지 않은 메소드`empty? ' # <User>

고안 사용하고 레일 4

모델 :

class Event 

    include Mongoid::Document 

    field :name, type: String 
    field :description, type: String 
    field :date, type: Date 

    embeds_many :invitees, cascade_callbacks: true 
    embeds_many :participants, cascade_callbacks: true 
    embeds_many :comments, cascade_callbacks: true 
    embeds_many :options, cascade_callbacks: true 

    has_one :owner, :class_name => "User" 

    accepts_nested_attributes_for :options, autosave: true, allow_destroy: true 
    accepts_nested_attributes_for :participants, autosave: true, allow_destroy: true 
    accepts_nested_attributes_for :comments, autosave: true, allow_destroy: true 
    accepts_nested_attributes_for :invitees, autosave: true, allow_destroy: true 
    accepts_nested_attributes_for :owner, autosave: true, allow_destroy: true 

    end 

컨트롤러 : ... 데프 내가 잘못 뭐하는 거지

@event = Event.create(event_params) 

    if user_signed_in? 
     @event.create_owner(current_user) 
    end 

    respond_to do |format| 
     if @event.save 
     #TODO: Save users attached to event in user collection 
     format.html { redirect_to @event, notice: 'Event was successfully created.' } 
     format.json { render action: 'show', status: :created, location: @event } 
     else 
     format.html { render action: 'new' } 
     format.json { render json: @event.errors, status: :unprocessable_entity } 
     end 
    end 
    end 
    .... 

만들? 편집

:

C : /Rails/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/attributes 여기 는 스택 트레이스입니다 /processing.rb:21:in process_attributes' C:/Rails/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/document.rb:110:in 초기화 블록 ' C : /Rails/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/threaded/lifecycle. rb : 84 : _building' C:/Rails/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/document.rb:104:in 'devise (3.0.4) lib/devise/models/confirmable.rb : 46 : initialize' C:/Rails/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/factory.rb:23:in 새' C : /Rails/Ruby1.9.3/lib/ruby/gems/1.9에서 초기화하십시오. 1/bundler/gems/mongoid-5b0f031992cb/lib 디렉토리/mongoid/factory.rb : 23 : ': 31 : 응용 프로그램/컨트롤러/events_controller.rb create' actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in send_action에서'창조자의 build' C:/Rails/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/relations/builders.rb:93:in 블록에 ...

+0

버그를 찾았습니까? –

답변

0

문제는 당신이 전화하는거야하는 기능 "빈?" 사용자 레코드에 정의되어 있지 않은 경우 '당신에게 위치를 알아 내기 위해

def empty? 
end 

그러나 더 나은 것 :

1.9.3-p194 :001 > User.first.empty? 
    User Load (9.3ms) SELECT `users`.* FROM `users` ORDER BY `users`.`id` ASC LIMIT 1 
    NoMethodError: undefined method `empty?' for #<User:0x007fe0375d8c10> 

당신은 당신의 사용자 모델의 기능을 스텁이 문제를 해결할 수있다 : 가장 간단한 경우이 레일 콘솔에서 실패 다시 전화하고 고칠 수 있습니다. 오류 추적은 파일과 행의 출처를 알려야합니다.

+0

안녕하세요, stacktrace를 추가했습니다. 문제가 어디에서 발생했는지 이해하지 마십시오 ... – Mike

+0

어떤 버전의 레일, 루비 및 몽고 이도를 사용하고 있습니까? 아마도 약간의 비호 환성이있을 수 있습니다. –

관련 문제