保存新记录时,关联的 ID 更改为 9 位数字
我有一张场地表,每个场地都属于一个区域和一种类型。我最近删除了该表并向其中添加了一些地址行字段。我已经重新迁移了它,但现在area_id字段保存为随机的? 9位数。 area_id 和venuetype_id 整数都是在创建新表单时以相同的方式创建的,并且venuetype_id 正常保存,但area_id 不保存。有人可以提供任何帮助吗?
控制台中显示的内容
=> [#<Venue id: 4, name: "sdf", addressline1: "", addressline2: "", addressline3
: "", addressline4: "", icontoppx: 234, iconleftpx: 234, area_id: 946717224, ven
uetype_id: 8, created_at: "2011-03-17", updated_at: "2011-03-17 23:33:53">]
irb(main):030:0>
在上面的示例中,area_id 应为 8。
区域和场地类型 ID 是从新场地表单上的下拉框中选择的。
新表单
<%= form_for @venue do |f| %>
<p>name: <br>
<%= f.text_field :name %></p>
<p>top: <br>
<%= f.text_field :icontoppx %></p>
<p>left: <br>
<%= f.text_field :iconleftpx %></p>
<p>addressline1: <br>
<%= f.text_field :addressline1 %></p>
<p>addressline2: <br>
<%= f.text_field :addressline2 %></p>
<p>addressline3: <br>
<%= f.text_field :addressline3 %></p>
<p>addressline4: <br>
<%= f.text_field :addressline4 %></p>
<p>area: <br>
<%= f.collection_select(:area_id, Area.all, :id, :name) %></p>
<p>venuetype: <br>
<%= f.collection_select(:venuetype_id, Venuetype.all, :id, :name) %></p>
<br><br>
<div class="button"><%= submit_tag %></div>
<% end %>
区域表
class CreateAreas < ActiveRecord::Migration
def self.up
create_table :areas do |t|
t.string :name
t.timestamps
end
end
def self.down
drop_table :areas
end
end
从控制台显示的区域记录
irb(main):001:0> Area.all
=> [#<Area id: 8, name: "Area1", created_at: "2011-03-17 23:28:40", u
pdated_at: "2011-03-17 23:28:40">, #<Area id: 9, name: "Area2", created_at:
"2011-03-17 23:29:50", updated_at: "2011-03-17 23:29:50">]
irb(main):002:0> Area.all.map(&:id)
非常感谢您的帮助!
I have a table of venues, with each venue belonging to an area and a type. I recently dropped the table and added to it some addressline fields. I have re-migrated it but now the area_id field saves as a random? 9 figure number. Both the area_id and venuetype_id integers are created in the same way from the create new form and the venuetype_id saves as normal but not the area_id. Can anyone offer any help?
whats shown in the console
=> [#<Venue id: 4, name: "sdf", addressline1: "", addressline2: "", addressline3
: "", addressline4: "", icontoppx: 234, iconleftpx: 234, area_id: 946717224, ven
uetype_id: 8, created_at: "2011-03-17", updated_at: "2011-03-17 23:33:53">]
irb(main):030:0>
the area_id should be 8 in the above example.
The area and venuetype id's are slected from dropdown boxes on the new venue form.
new form
<%= form_for @venue do |f| %>
<p>name: <br>
<%= f.text_field :name %></p>
<p>top: <br>
<%= f.text_field :icontoppx %></p>
<p>left: <br>
<%= f.text_field :iconleftpx %></p>
<p>addressline1: <br>
<%= f.text_field :addressline1 %></p>
<p>addressline2: <br>
<%= f.text_field :addressline2 %></p>
<p>addressline3: <br>
<%= f.text_field :addressline3 %></p>
<p>addressline4: <br>
<%= f.text_field :addressline4 %></p>
<p>area: <br>
<%= f.collection_select(:area_id, Area.all, :id, :name) %></p>
<p>venuetype: <br>
<%= f.collection_select(:venuetype_id, Venuetype.all, :id, :name) %></p>
<br><br>
<div class="button"><%= submit_tag %></div>
<% end %>
Areas table
class CreateAreas < ActiveRecord::Migration
def self.up
create_table :areas do |t|
t.string :name
t.timestamps
end
end
def self.down
drop_table :areas
end
end
Area records shown from console
irb(main):001:0> Area.all
=> [#<Area id: 8, name: "Area1", created_at: "2011-03-17 23:28:40", u
pdated_at: "2011-03-17 23:28:40">, #<Area id: 9, name: "Area2", created_at:
"2011-03-17 23:29:50", updated_at: "2011-03-17 23:29:50">]
irb(main):002:0> Area.all.map(&:id)
Thanks very much for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
长整数是内部 ruby 对象 id。我猜测 Area.all 返回的东西不是 ActiveRecord 对象。可能是这样吗?
区域选择列表选项在浏览器和源代码中看起来是否正确?我希望您能在源代码中看到 9 位数字的值。
The long integer is the internal ruby object id. I'm guessing the things Area.all is returning are not ActiveRecord objects. Could this be the case?
Does the area select list options look correct in the browser and in the source? I expect you're seeing the 9 digit values in the source.
这个问题以多种方式呈现,包括将更新字段更改为大十进制。不管怎样,我不是专家,但我认为这是 Windows 和 mysql2 的一个问题,它通过将 libmySQL.dll 的新副本从 mysql bin 目录复制粘贴到 ruby bin 目录来纠正。
This problem presented in a few ways, including changing the updated at field to a bigdecimal. Anyway, I'm no expert but I think its a blip with windows and mysql2 it corrected by copy pasting a new copy of the libmySQL.dll from the mysql bin directory to the ruby bin directory.