2

I have the following code:

<%= f.label nil, "*Status" %><br \>
<%= f.select :full_time, [["Full Time", true], ["Daily Call", false]], :prompt => "-Select a Status-" %>

:full_time is a boolean (tinyint(1) in mysql).

The issue I'm having is that when I select "Full Time" or true, it will update the mysql db, but when I select "Daily Call" or false, it will not update the database at all.

Why is this happening and how should I fix this?? I'll provide more code on request.

Additional info:

As far as the controller, there is no code that involves :full_time .

It looks like this in the schema.rb: t.boolean "full_time"

Also, every other field is working fine in the form.

4

1 回答 1

0

啊哈!我在控制器中找到了这段代码:

new_fields = Hash.new
@position.attributes = params[:position]
changed_fields = @position.changed
changed_fields.each do |f|
  if !@position[f].blank?
   new_fields[f] = @position[f]
  end
end

我意识到调用@position[f].blank?一个错误的布尔值将返回true..因此为什么没有添加它。

对于那些好奇它是如何不工作的人......它稍后会检查 new_fields 以查看它是否为空,以决定是否要保存修改后的位置。

感谢你的帮助。

于 2013-08-16T21:37:53.503 回答