【发布时间】:2009-08-11 20:10:11
【问题描述】:
我知道这违反了 ruby on rails 约定,但我的这个表的 id 不需要自动递增,我通过逻辑设置它。但是,它不会保存到数据库中。保存的所有内容都为 id 保存为 null。
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 文件之外还有其他地方我应该更改/检查吗?
【问题讨论】:
标签: ruby-on-rails