gpt4 book ai didi

ruby-on-rails - Rails Country_select 无法保存到数据库

转载 作者:搜寻专家 更新时间:2023-10-30 23:43:40 25 4
gpt4 key购买 nike

我无法将此选择国家/地区插件 ( https://github.com/scudco/country_select_test) 集成到我的测试应用程序中。我安装了它并将其放入我的数据库中。当我在 rails 控制台中输入我的 id 时它会出现,但它总是显示为 nil。这是我的 view.haml:

.form-group
= f.input :country_code, autofocus: true, :class => "form-control"
.form-group
= f.input :address, autofocus: false, :class => "form-control"

这是我最近进行的迁移:

class AddCountryCodeToUsers < ActiveRecord::Migration
def change
add_column :users, :country_code, :string
end
end

我的控制台输出:

updated_at: "2015-08-07 15:29:26", address: " ", country_code: nil>

我的 users.rb 文件中没有关于 :country_code 的信息。我曾经在他们的 assert country_code 中有过,但是当我把它拿出来时它并没有改变任何东西。感谢所有帮助我的人。我仍然是 ruby​​ on rails 的菜鸟。

最佳答案

由于 strong_parameters,您可能错过了在 UsersController 中允许使用 :country_code 参数

在你的 Controller 中你应该有类似的东西

def users_params
params.require(:user).permit(...)
end

您需要确保在 permit 方法中,也调用了 :country_code。例如:

params.require(:user).permit(:country_code, :email, :password, :password_confirmation)

关于ruby-on-rails - Rails Country_select 无法保存到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31882815/

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