On saving a new record an associated id changes to 9 figure number
Posted
by
Dave
on Stack Overflow
See other posts from Stack Overflow
or by Dave
Published on 2011-03-17T23:52:42Z
Indexed on
2011/03/18
0:09 UTC
Read the original article
Hit count: 169
Hi, 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
Thanks very much for any help!
© Stack Overflow or respective owner