我知道这是违反轨道约定的红宝石,但我这个表的id不需要自动增量,我通过逻辑来设置它。但是,它不会保存到数据库中。所有保存的内容都保存为空。ruby on rails id not saving
def self.up
create_table :probes, :id => false do |t|
t.string :id
t.string :name
t.integer :user_id
t.boolean :online
t.timestamps
end
end
<% form_for @probe do |f| %>
<%= f.error_messages %>
<p>
<%= f.label "Site name" %><br />
<%= f.text_field :name %>
</p>
<p style="margin-left: 10%">
<%= f.label "Probe Key" %><br />
<%= f.text_field :id, :value => @token %>
</p>
<p style="margin-left: 20%">
<%= link_to "Back to List", probes_path %>
<%= f.submit "Submit",:style => "margin-left: 75px;" %></p>
<% end %>
这甚至有可能吗?或者,除了new.html.erb文件之外,我应该更改/检查什么地方?
我 @Probe = Probe.new(PARAMS [:探测]) @Probe =参数s [:probe] [:id] 在我的控制器中,但仍然无法正常工作。这是我的整个创建方法: DEF创建 \t @user = CURRENT_USER \t @probe = Probe.new(PARAMS [:探针]) \t @ probe.id =参数[:探头] [:ID] @ probe = @ user.probes.create!(params [:probe]) if @ probe.save flash [:notice] =“成功创建探针。” redirect_to probes_path else render:action =>'new' end end – Ryan 2009-08-11 20:25:43
好吧,我被推迟了,哈哈。我忘了在create方法中传入@probe。然而,现在我得到一个关于strigify键的错误...未定义的方法'stringify_keys!' – Ryan 2009-08-11 20:57:35
而这种情况发生是因为我使用的是只接受哈希的创建。 @ Probe.save工作正常。问题已修复。 – Ryan 2009-08-12 13:08:58