I have the following form fields..
我有以下表格字段..
<%= u.password_field 'pin[]', required: true, maxlength: 1, autofocus: true %>
<%= u.password_field 'pin[]', required: true, maxlength: 1 %>
<%= u.password_field 'pin[]', required: true, maxlength: 1 %>
<%= u.password_field 'pin[]', required: true, maxlength: 1 %>
I have a column in my database called pin (type: integer
) which I want to save the 4 digit pin to from these fields. They have to be in 4 different inputs for the design aesthetic but I'm having trouble saving it to the database.
我的数据库中有一个名为pin(type:integer)的列,我想从这些字段中保存4位数的引脚。它们必须在4种不同的输入中用于设计美学,但我无法将其保存到数据库中。
So far I'm getting the error:
到目前为止,我收到了错误:
no implicit conversion of Symbol into Integer
没有将Symbol隐式转换为Integer
When I run the following:
当我运行以下内容时:
@user.pin = params.merge([:user][:pin_1], [:user][:pin_2], [:user][:pin_3], [:user][:pin_4])
I've tried using join(',')
and split(',')
together but I can't seem to get the 4 digit, as an integer.
我尝试过使用join(',')和split(','),但我似乎无法得到4位数,作为整数。
Any help would be much appreciated :)
任何帮助将非常感激 :)
1 个解决方案
#1
0
If you do a
如果你做了
begin
"#{params[:user][:pin_1]}#{params[:user][:pin_1]}#{params[:user][:pin_1]}#{params[:user][:pin_1]}".to_i
rescue Exception => e
<error handling here>
end
That should do the trick, it's dirty but it should work. I would also do some javascript validation on the input to ensure that it is a number, not a letter.
这应该做的伎俩,它很脏但它应该工作。我还会对输入进行一些javascript验证,以确保它是一个数字,而不是一个字母。
#1
0
If you do a
如果你做了
begin
"#{params[:user][:pin_1]}#{params[:user][:pin_1]}#{params[:user][:pin_1]}#{params[:user][:pin_1]}".to_i
rescue Exception => e
<error handling here>
end
That should do the trick, it's dirty but it should work. I would also do some javascript validation on the input to ensure that it is a number, not a letter.
这应该做的伎俩,它很脏但它应该工作。我还会对输入进行一些javascript验证,以确保它是一个数字,而不是一个字母。