2013-03-09 80 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