2013-03-09 71 views
0

我想添加兩列到爲郵箱gem進行通知的遷移。當我將兩者都放入創建通知的遷移中,然後運行遷移時,它就會通過。然後我將它們輸入到表單中,當我提交它們時,沒有錯誤,並且日誌顯示它帶有它們。出於某種原因,當我試圖展示它們時,它們並沒有顯示出來,唯一顯示的是作爲主體和主體的遷移的一部分的原始事物。我的問題是如何將列添加到此遷移?將列添加到郵箱遷移

這裏是我的兩列經緯度添加到通知部分的遷移。

# 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 

這是在控制檯出現,爲緯度和長,你看它說,空

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 – 2013-03-10 04:47:27

+0

不知道你說的那些專欄是什麼意思。如果您只是在導軌控制檯中鍵入「通知」。你看到了什麼?還有,當你做「Notification.first」時你會看到什麼。也許作爲編輯添加到您的問題。 – 2013-03-10 08:10:41

+0

編輯我的帖子,包括控制檯輸出 – 2013-03-10 08:32:24