我剛剛按照文檔在配置文件中添加新字段,但似乎並不奏效。加班我得到Unpermitted parameters: firstname, lastname, password_confirmation
。無法在設計上添加新字段 - Ruby on Rails
這是我的用戶模型:
class User < ApplicationRecord
devise :database_authenticatable, :registerable, :recoverable, rememberable, :trackable, :validatable
has_many :issues
has_many :comments
has_many :likes
# Validations
validates :email, presence: true
validates :password, presence: true
# Omniauth
devise :omniauthable, omniauth_providers: [:facebook]
# Omniauth Facebook # Omniauth Facebook
def self.from_facebook(auth)
where(facebook_id: auth.uid).first_or_create do |user|
# user.image = auth.info.image
user.email = auth.info.email
user.firstname = auth.info.first_name
user.lastname = auth.info.last_name
user.country = auth.info.location
user.region = ""
user.password = Devise.friendly_token[0, 20]
# user.skip_confirmation!
end
end
## Paperclip avatar
has_attached_file :avatar, styles: {
big: "1200x1200>",
medium: "300x300>",
thumb: "100x100>"
}, default_url: "missing.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
end
這是我的應用程序控制器,它包含了新的色器件領域的配置:(first_name
,last_name
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
# Devise parameters configuration
before_action :configure_devise_parameters, if: :devise_controller?
def configure_devise_parameters
devise_parameter_sanitizer.permit(:sign_up) { |u| u.permit(:email, :avatar, :firstname, :lastname, :region, :country, :bio, :password, :password_confirmation, :current_password) }
devise_parameter_sanitizer.permit(:account_update) { |u| u.permit(:email, :avatar, :firstname, :lastname, :region, :country, :bio, :password, :password_confirmation, :current_password) }
end
end
所以
,我嘗試刪除我的應用控制方法(和地雷代替,當然你的領域),並沒有刪除它。它不工作了...... –
因此你刪除了'configure_devise_parameters'方法並且像上面那樣定義'registrations_controller.rb' ...對嗎?你能告訴我這個錯誤嗎?並添加遷移的新領域? –
當然,錯誤保持不變:'不允許的參數:名字,姓氏,password_confirmation'和添加遷移的新字段是http://chopapp.com/#3etzk654 –