0
를 작동하지 않는 것 같습니다 것은 message.rb 내 모델 :레일 Mongoid 타임 스탬프가 여기에
class Message
include Mongoid::Document
include Mongoid::Timestamps::Created
embedded_in :room
field :content
field :user_id # That's the guest_id; room_id if it's a room's owner message.
end
타임 스탬프 *의 created_at * 자동 Mongoid에 의해 생성 될 생각하지만, 그러한 속성 Message.created_at은 거기에 없다 데이터베이스 이유를 이해할 수 없습니다.
embeds_many 모델 : 이것은 메시지 작성하는 방법입니다
def create
@room = Room.new(room_params)
@room.password_confirmation = @room.password # Easy way to bypass the has_secure_password confirmation.
@room.url = generate_url
respond_to do |format|
if @room.save
session[@room.id.to_s.to_sym] = true
format.html { redirect_to "/chat/" + @room.url, notice: 'Room was successfully created.' }
format.json { render action: 'show', status: :created, location: @room }
else
format.html { render action: 'new' }
format.json { render json: @room.errors, status: :unprocessable_entity }
end
end
end
:
class Room
include Mongoid::Document
include ActiveModel::SecurePassword
embeds_one :guest
embeds_many :messages
has_secure_password
field :password_digest
field :owner_name
field :url
end
이 내가 방을 생성하는 방법이다
def write_message
@room = Room.find(params[:id])
@room.messages.build(content: params[:message], user_id: params[:user_id])
if @room.save
render json: true
else
render json: @room.errors, status: :unprocessable_entity
end
end
을 나는 레일을 사용하고 있습니다 4.0.0 및 몽고 이드 4.0.0.beta1.
@muistooshort로 변경하려고합니다. – fschuindt
개체는 어떻게 만듭니 까? –
@artmees 개체 생성 방법으로 편집되었습니다. – fschuindt