2012-05-06 43 views
1

这里是我的架构文件..Entrys没有正确保存到我的数据库?

ActiveRecord::Schema.define(:version => 20120505115340) do 

    create_table "clients", :force => true do |t| 
    t.string "name" 
    t.string "detail" 
    t.string "more_detail" 
    t.string "more_details" 
    t.datetime "created_at", :null => false 
    t.datetime "updated_at", :null => false 
    end 

    create_table "jobs", :force => true do |t| 
    t.string "name" 
    t.integer "number" 
    t.string "responsible" 
    t.string "monthly" 
    t.string "quarterly" 
    t.string "other" 
    t.datetime "created_at", :null => false 
    t.datetime "updated_at", :null => false 
    end 

end 

,这里是我的移民文件的..

class CreateClients < ActiveRecord::Migration 
    def change 
    create_table :clients do |t| 
     t.string :name 
     t.string :detail 
     t.string :more_detail 
     t.string :more_details 
     t.timestamps 
    end 
    end 
end 

class CreateJobs < ActiveRecord::Migration 
    def change 
    create_table :jobs do |t| 
     t.string :name 
     t.integer :number 
     t.string :responsible 
     t.string :monthly 
     t.string :quarterly 
     t.string :other 
     t.timestamps 
    end 
    end 
end 

我认为文件中,我有它设置,使是翻出client.name,它显示的用户<%= link_to client.name, client_path(client) %>

但是,当我创建新条目时,所有即时回复为/clients/1而不是我在表单中指定的名称。

当我尝试迁移数据库时,什么也没有发生,然后当我尝试删除他的DB重新开始时,它告诉我它甚至存在。

回答

1

如果我正确理解你,你担心你的视图显示你的新创建对象的链接/clients/1

这是使用Ruby on Rails时的默认路径,它是由您正在使用的路径帮助程序object_path(object)生成的。这可以定制(参见routes.rb指南)。如果这不是问题,那么你的应用程序按照预期工作。

BtW,默认路径中使用的数字是指给予对象的id。所有使用ActiveRecord存储的对象都会自动获得唯一的可用于识别对象的id。就像架构中的created_atupdated_at列一样,将创建id列,无论您是否在模式中明确定义它。

要重置您的数据库(下降,重建并迁移到当前的模式),请使用以下命令:

rake db:reset 

编辑:

<%= link_to client.name, client_path(client) %> 

应该导致下面的HTML(其中,客户是客户端的名称属性)

<a href="/clients/1">CLIENT_NAME</a> 
+0

但我在视图中调用的属性不是id。 在我尝试将数据库迁移到aadd作业表之前,此工作正在进行。 – Keva161

+0

所以..在我的表单中保存:name属性。为什么只显示客户端ID?正如我刚才所说的那样,它正在显示客户名称。除了尝试使用新模型迁移数据库外,我没有触及我的代码。 我把我的代码放在GitHub上,如果帮助=> https://github.com/keva161/document_manager 我相信这是一个数据库相关的问题,因为当我导航到/ clients /目录并添加一个新的客户端并保存。表单将进入,但不会保存任何信息。 – Keva161

相关问题