简单的整型字段保存为无 [英] Simple integer field saves as nil

查看:96
本文介绍了简单的整型字段保存为无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近增加了一个新的mapicon_id场给我的这对新的和编辑下拉显示所有availiable图标场地纪录。每个记录也有上边和左边的整数字段这让我给COORDS为使用JavaScript的图标绝对定位。

I recently added a new mapicon_id field to my venue records which displays all availiable icons in a dropdown on new and edit. Each record also has top and left integer fields which allow me to give coords for absolute positioning of the icons using javascript.

在我添加了新的mapicon_id领域的顶部和左侧领域工作得很好,但现在的左外野不会保存。您可以编辑字段或创建一个新的记录与左值,然后单击保存,然后它将给全成显信息和正确的重定向,但该领域将是空白。

Before I added the new mapicon_id field the top and left fields worked fine but now the left field wont save. You can edit the field or create a new record with a left value and click save, it will then give the successfull flash message and redirect correctly but the field will be blank.

场地部分:

<%= link_to venue do %>
  <div class="venue_partial">

    <div class="venue_icon">
      <%= image_tag venue.venuetype.photo.url(:thumb), :class => 'image' %>
    </div>
  </div>
<% end %>

<%= link_to venue do %>
  <div id="venue_map_icon_<%= venue.id %>" style="position:absolute;"><%= image_tag venue.mapicon.photo.url(:thumb), :class => 'venue_map_icon' %></div>
<% end %>

<script>
  document.getElementById("venue_map_icon_<%= venue.id %>").style.left= "<%= venue.left %>px";
  document.getElementById("venue_map_icon_<%= venue.id %>").style.top= "<%= venue.top %>px";
</script>

编辑和新的:

edit and new:

<%= form_for @venue do |f| %>
  <p>name: <br>
  <%= f.text_field :name %></p>

  <p>mapicon: <br>
  <%= f.collection_select(:mapicon_id, Mapicon.all, :id, :name) %>

  <p>top: <br>
  <%= f.text_field :top %></p>

  <p>left: <br>
  <%= f.text_field :left %></p>

  <%= submit_tag %>
<% end %>

在编辑的100顶部的记录,并留下价值开发日志:

development log on editing a record with top and left values of 100:

Started GET "/venues/45-test-place/edit" for 127.0.0.1 at 2011-02-26 11:07:10 +0000
  Processing by VenuesController#edit as HTML
  Parameters: {"id"=>"45-test-place"}
  [1m[35mVenue Load (1.0ms)[0m  SELECT `venues`.* FROM `venues` WHERE `venues`.`id` = 45 LIMIT 1
  [1m[36mArea Load (0.0ms)[0m  [1mSELECT `areas`.* FROM `areas`[0m
  [1m[35mVenuetype Load (0.0ms)[0m  SELECT `venuetypes`.* FROM `venuetypes`
  [1m[36mMapicon Load (1.0ms)[0m  [1mSELECT `mapicons`.* FROM `mapicons`[0m
Rendered venues/edit.html.erb within layouts/application (108.0ms)
Completed 200 OK in 150ms (Views: 127.0ms | ActiveRecord: 2.0ms)


Started POST "/venues/45-test-place" for 127.0.0.1 at 2011-02-26 11:07:16 +0000
  Processing by VenuesController#update as HTML
  Parameters: {"utf8"=>"âœ"", "authenticity_token"=>"By8blc3esfE6A8tnfOmRPn9f4KZb/ctwpjg86La4d1Y=", "venue"=>{"name"=>"test place", "addressline1"=>"", "addressline2"=>"", "addressline3"=>"", "phonenumber"=>"", "area_id"=>"8", "venuetype_id"=>"15", "mapicon_id"=>"1", "top"=>"100", "left"=>"100"}, "commit"=>"Save changes", "id"=>"45-test-place"}
  [1m[35mVenue Load (1.0ms)[0m  SELECT `venues`.* FROM `venues` WHERE `venues`.`id` = 45 LIMIT 1
  [1m[36mSQL (0.0ms)[0m  [1mBEGIN[0m
  [1m[35mAREL (0.0ms)[0m  UPDATE `venues` SET `top` = 100, `left` = 100, `updated_at` = '2011-02-26 11:07:16' WHERE `venues`.`id` = 45
  [1m[36mSQL (30.0ms)[0m  [1mCOMMIT[0m
Redirected to http://localhost:3000/venues.45-test-place
Completed 302 Found in 65ms

编辑这个纪录后,前场显示100,但左边的字段为空。

After editing this record the top field shows 100 but the left field is blank.

场地模型:

class Venue < ActiveRecord::Base
  belongs_to :user
  has_many :reviews
  belongs_to :area
  belongs_to :venuetype
  belongs_to :mapicon

  scope :with_type, lambda { |types|
    types.present? ? where(:venuetype_id => types) : scoped }

  scope :with_area, lambda { |areas|
    areas.present? ? where(:area_id => areas) : scoped }

  def to_param
    "#{id}-#{name.gsub(/\W/, '-').downcase}"
  end

  def self.search(search)
    if search
      where('name LIKE ?', "%#{search}%")
    else
      scoped
    end
  end
end

mapicon模式:

mapicon model:

class Mapicon < ActiveRecord::Base
  has_many :venues
  has_attached_file :photo,
    :styles => {
      :thumb=> "100x100>",
      :small  => "150x150>",
      :medium => "300x300>",
      :large =>   "400x400>" },
    :default_url => '/images/noimage.png'
end

更新

我放弃了顶部和左侧的字段,并添加toppx和leftpx所以字段名称不那么通用的,但问题依然存在,只是现在它的toppx字段不会保存。另外,如果我改变的JavaScript采取venuetype_id,而不是它会显示正确的toppx值的价值。所述venuetype_id是15和图标从页面顶部显示15px的

I dropped the top and left fields and added toppx and leftpx so the field names aren't so generic, however the problem still exists only now its the toppx field that wont save. Also, If I change the javascript to take the value of the venuetype_id instead of the toppx value it displays correctly. the venuetype_id is 15 and the icon is displayed 15px from the top of the page.

新移民:

class AddToppxAndLeftpxToVenues < ActiveRecord::Migration

  def self.up
    add_column :venues, :toppx, :integer
    add_column :venues, :leftpx, :integer
  end

  def self.down
    remove_column :venues, :toppx
    remove_column :venues, :leftpx
  end
end

另一个更新

irb(main):002:0> v=Venue.new
=> #<Venue id: nil, name: nil, addressline1: nil, addressline2: nil, addressline
3: nil, created_at: nil, updated_at: nil, area_id: nil, user_id: nil, venuetype_
id: nil, phonenumber: nil, toppx: nil, leftpx: nil>
irb(main):003:0> v.name='test23'
=> "test23"
irb(main):004:0> v.leftpx='24'
=> "24"
irb(main):005:0> v.toppx='42'
=> "42"
irb(main):006:0> v.venuetype_id='13'
=> "13"
irb(main):007:0> v.area_id='2'
=> "2"
irb(main):008:0> v.user_id='6'
=> "6"
irb(main):009:0> v.save
=> true
irb(main):010:0> Venue.find(:last)
=> #<Venue id: 55, name: "test23", addressline1: nil, addressline2: nil, address
line3: nil, created_at: "2011-02-28 18:07:42", updated_at: "2011-02-28 18:07:42"
, area_id: 2, user_id: 946706424, venuetype_id: 13, phonenumber: nil, toppx: nil
, leftpx: 24>
irb(main):011:0>

在一个侧面说明我不知道发生了什么与USER_ID有变化,但它正常工作和同事给正确的用户。

On a side note I dont know whats happening with the change of user_id there but it works correctly and associates to the correct user.

感谢您的帮助!

推荐答案

在坚持的libmysql.dll的新副本到红宝石bin文件夹固定。

Fixed by sticking a new copy of libmySQL.dll into the ruby bin folder.

这篇关于简单的整型字段保存为无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆