정의되지 않은 메소드를 가져 오는 중 '비어 있습니까?' 현재 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.rbcreate' 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
블록에 ...
버그를 찾았습니까? –