【发布时间】:2013-06-27 09:11:22
【问题描述】:
对使用 Rails 非常陌生。我已经使用 Devise 实现了一个基本的登录系统。我正在尝试将几个新字段(bio:string,name:string)添加到 sign_up 页面中。我的所有内容都正确显示,并且新字段已添加到数据库中(当我在 SQLbrowser 中查看时),但是它们没有填充,并且在用户提交注册表单后,会显示一条消息,其中一部分显示:
Unpermitted parameters: bio, name
我已将 2 个字符串添加到 _devise_create_users.rb
# added
t.string :bio
t.string :name
我让它们出现在 schema.rb 中
ActiveRecord::Schema.define(version: 20130629002343) do
create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "shortbio"
t.boolean "admin", default: false
t.string "realname"
t.string "name"
t.string "bio"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
我的用户.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
#:token_authenticatable, :confirmable,
#:lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
这个问题与强参数有关吗?我很难理解它们以及在哪里/如何实施。
【问题讨论】:
-
@mohamad 这并没有真正帮助他解决问题。
-
@simonmorley 确实如此。但这是评论,而不是答案。
-
有时解决问题的最佳方法就是采用不同的方法,我感谢您的评论。
-
Devise 非常棒,如果您想使用的不仅仅是其中的一两个功能。基本身份验证非常容易从头开始构建,并且通常是您所需要的。但是,一旦您进入“记住我”令牌、确认电子邮件、忘记密码、登录/注销日志以及由于密码尝试次数过多而锁定帐户,设计开始显示其优势!
-
我将大部分附加字段放入另一个模型
Profile并规避了人们在这里抱怨的大部分问题。无论如何,一个额外的模型可以说是更好的数据库/模型设计,尽管我不会在这里争论。
标签: ruby-on-rails ruby