2013-03-09 2 views
0

나는 편지함 주자에 대한 알림을 만드는 두 개의 열을 마이그레이션에 추가하려고했습니다. 알림을 생성하는 마이그레이션에 둘 모두를 배치 한 다음 마이그레이션을 실행하면 문제가 해결됩니다. 그런 다음 양식에 입력하고 제출하면 오류가 없으며 로그에 오류가 표시됩니다. 어떤 이유로 표시하지 않으려 고 표시 할 때 유일한 것은 대상과 본문 인 마이그레이션의 일부인 원래의 것들입니다. 내 질문은이 마이그레이션에 열을 추가하는 방법입니다.편지함 마이그레이션에 열 추가

다음은 알림 섹션에 lat와 long 두 열을 추가 한 마이 그 레이션입니다.

# This migration comes from mailboxer_engine (originally 20110511145103) 
class CreateMailboxer < ActiveRecord::Migration 
    def self.up  
    #Tables 
    #Conversations 
     create_table :conversations do |t| 
     t.column :subject, :string, :default => "" 
     t.column :created_at, :datetime, :null => false 
     t.column :updated_at, :datetime, :null => false 
    end  
     #Receipts 
    create_table :receipts do |t| 
     t.references :receiver, :polymorphic => true 
     t.column :notification_id, :integer, :null => false 
     t.column :read, :boolean, :default => false 
     t.column :trashed, :boolean, :default => false 
     t.column :deleted, :boolean, :default => false 
     t.column :mailbox_type, :string, :limit => 25 
     t.column :created_at, :datetime, :null => false 
     t.column :updated_at, :datetime, :null => false 
    end  
     #Notifications and Messages 
    create_table :notifications do |t| 
     t.column :type, :string 
     t.column :body, :text 
     t.column :subject, :string, :default => "" 
     t.column :lat, :text 
     t.column :long, :text 
     t.references :sender, :polymorphic => true 
     t.references :object, :polymorphic => true 
     t.column :conversation_id, :integer 
     t.column :draft, :boolean, :default => false 
     t.column :updated_at, :datetime, :null => false 
     t.column :created_at, :datetime, :null => false 
    end  


    #Indexes 
    #Conversations 
    #Receipts 
    add_index "receipts","notification_id" 

    #Messages 
    add_index "notifications","conversation_id" 

    #Foreign keys  
    #Conversations 
    #Receipts 
    add_foreign_key "receipts", "notifications", :name => "receipts_on_notification_id" 
    #Messages 
    add_foreign_key "notifications", "conversations", :name => "notifications_on_conversation_id" 
    end 

    def self.down 
    #Tables  
    remove_foreign_key "receipts", :name => "receipts_on_notification_id" 
    remove_foreign_key "notifications", :name => "notifications_on_conversation_id" 

    #Indexes 
    drop_table :receipts 
    drop_table :conversations 
    drop_table :notifications 
    end 
end 

내 쇼보기

%h1= conversation.subject 
%ul 
    = content_tag_for(:li, conversation.receipts_for(current_user)) do |receipt| 
    - message = receipt.message 
    %h3= message.subject 
    %p= message.body 
    %p= message.lat 
    %p= message.long 

= render 'messages/form', conversation: conversation 

처럼이 위도를 들어, 콘솔에서 오는 것입니다 그리고 당신이이 널 (null)

Notification Load (0.1ms) SELECT "notifications".* FROM "notifications" ORDER BY "notifications"."id" DESC LIMIT 1 
--- !ruby/object:Message 
attributes: 
    id: 4 
    type: Message 
    body: game 
    subject: wiz 
    lat: !!null 
    long: !!null 
    sender_id: 1 
    sender_type: User 
    conversation_id: 2 
    draft: false 
    updated_at: 2013-03-10 04:37:54.984277000Z 
    created_at: 2013-03-10 04:37:54.984277000Z 
    notified_object_id: !!null 
    notified_object_type: !!null 
    notification_code: !!null 
    attachment: !!null 
    => nil 

답변

0

내가 이해가 확실하지 않다라고 볼 보인다 정확히 무엇을하고 있는지, 아마도 attr_accessible에 두 개의 새로운 열을 추가하지 않았을 것 같고 그것 때문에 저장되지 않을 수도 있습니다. 그게 제가 제일 먼저 확인하는 것입니다 (모델에 있습니다).

그렇지 않으면 콘솔로 이동하여 새 열이 있는지 확인하고 그 안에 데이터가 있는지 확인하십시오. 그러면 문제가있는 곳을 찾을 수 있습니다.

+0

열을 attr_accessibe에 추가했는데 아무 것도하지 않았습니다. 콘솔에서 볼 때 열이 말합니다 !! null –

+0

열을 말하는 것이 확실하지 않습니다. 레일 콘솔에 "Notification"이라고 입력하면됩니다. 너 뭐가 보이니? 또한 "Notification.first"를 할 때 무엇을 보게됩니까? 질문을 편집 내용으로 추가 할 수 있습니다. –

+0

콘솔 출력을 포함하도록 내 게시물을 편집했습니다. –

관련 문제