gpt4 book ai didi

mysql - Devise 和country_select gem 不会将选择保存到数据库 Rails4 中

转载 作者:行者123 更新时间:2023-11-29 22:33:04 25 4
gpt4 key购买 nike

我正在尝试在 Devise 注册中添加国家/地区选择,并且我使用 https://github.com/stefanpenner/country_select#example 中的country_select gem

这里解释了使用country_select("user", "country")使用模型和属性作为参数的简单用法:

问题:当我按下提交按钮时,用户已创建,一切都很好,除了国家/地区列没有我选择的数据

目的:提交注册后,我想将从注册表单中选择的国家/地区插入数据库(表:用户,列:国家/地区)

sign_up.html.erb

<h2><center>Sign up</center></h2>

<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= f.error_notification %>

<div class="form-inputs" style="float; margin:0 auto;width:35%">
<%= f.input :email, required: true, autofocus: true %>
<%= f.input :password, required: true %>
<%= f.input :password_confirmation, required: true %>
<%= f.label :country %>

<%= country_select("user", "country") %> <<-- My model's name is user.rb and in my users table has a country column

</div>

<div class="form-actions" style="float; margin:0 auto;width:10%">
<%= f.button :submit, "Sign up" %>
</div>
<% end %>

**我的模型名称是 user.rb,在我的用户表中有一个国家/地区列

感谢您的提前

最佳答案

试试这个

<%= f.input :country, as: :country %>

关于mysql - Devise 和country_select gem 不会将选择保存到数据库 Rails4 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29669675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com